<script setup lang="ts">
import { type LocationQueryValue, useRoute } from 'vue-router'
import { get1, get2, get3, get4 } from '@/api/home'
import {ref} from 'vue'
const route = useRoute()
const k:any = route.query.n
const currentShowList = ref<any>([]);
function removeDuplicatesById(arr:any, key:any) {
  return arr.reduce((accumulator:any, current:any) => {
    if (!accumulator.some((item:any) => item[key] === current[key])) {
      accumulator.push(current);
    }
    return accumulator;
  }, []);
}
const getData =async ()=>{
  if(k == 1){
    console.log(1)
    const res1 = await get1({pageNum:1,pageSize:1000});
    const bo = removeDuplicatesById(res1.records, 'administrativePartyName')
    const result = bo.map((item:any)=>{
      return ({
        name: item.administrativePartyName,
        time: item.licenseDecisionDate,
      })
    })
    currentShowList.value = result;
  }else if(k == 2){
    const res2 = await get2({pageNum:1,pageSize:1000});
    const bo = removeDuplicatesById(res2.records, 'administrativePartyName')
    const result = bo.map((item:any)=>{
      return ({
        name: item.administrativePartyName,
        time: item.penaltyDecisionDate.split('T')[0],
      })
    })
    currentShowList.value = result;
  }else if(k == 3){
    const res3 = await get3({pageNum:1,pageSize:1000});
    const bo = removeDuplicatesById(res3.records, 'subjectName')
    const result = bo.map((item:any)=>{
      return ({
        name: item.subjectName,
        time: item.statisticsTime.split('T')[0],
      })
    })
    currentShowList.value = result;
  }else if(k == 4){
    const res4:any = await get4({pageNum:1,pageSize:1000});
    const bo = removeDuplicatesById(res4.data.result, 'enterpriseName')
    console.log(bo)
    const result = bo.map((item:any)=>{
      return ({
        name: item.enterpriseName
      })
    })
    currentShowList.value = result;
  }
}
const init = () => {
  getData();
}
init();
</script>

<template>
  <div class="conpanyListContainer pt-20px">
    <div class="w-912px bg-white mr-a ml-a pt-20px border-solid border-1px border-color-#e6e6e6 rounded-10px">
      <div v-for="(item,index) in currentShowList" :key="index">
        <div class="text-20px p-20px flex justify-between">
          <div>{{item.name}}</div>
          <div class="text-gray text-20px">{{item.time}}</div>
        </div>
        <div class="h-1px bg-gray"></div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.conpanyListContainer{
  background-color: #ecf0f9;
}
</style>