<script setup>
import {fieldMap, tableMap} from './map';
import {getCompanyDetail} from '@/api/companyDetail';
import {ref} from 'vue'
import {useRoute} from "vue-router";

const activeNames = ref([])
    const showList = ref([])
  const route = useRoute();

    const handleChange = (val) => {
      console.log(val)
    }
    const getTableLength = (tableObj)=>{
      if(!tableObj)return null;
      let excludeList = ['id', 'update_time','create_time'];
      let newObj = {};
      for (let key in tableObj) {
        if (!excludeList.includes(key)) {
          newObj[key] = tableObj[key];
        }
      }
      return Object.keys(newObj);
    }
    getCompanyDetail(route.query.unifiedSocialCreditCode).then(res=>{
      if(res.code == 200){
        for(let i=0;i<res.data.length;i++){
          activeNames.value.push(i)
        }
        showList.value = res.data;
        // console.log(showList.value);
      }
    })
    // const test = (a)=>{
    //   // console.log(a);
    //   const r = a.map(item=>{
    //     let entries = Object.entries(item);
    //     const r = entries.filter(item=>{
    //       return item[0] == 'unified_social_credit_code'
    //     })
    //     const index = entries.findIndex(item=>{
    //       return item[0] == 'unified_social_credit_code'
    //     })
    //     const r1 = entries.filter(item=>{
    //       return item[0] == 'id'
    //     })
    //     const index1 = entries.findIndex(item=>{
    //       return item[0] == 'id'
    //     })
    //     entries.splice(index,1)
    //     entries.splice(index1,1)
    //     return [...r,...r1,...entries];
    //   })
    //   console.log(r);
    // }
</script>

<template>
  <div>
    <div>企业名称:{{route.query.enterpriseName}}</div>
    <div>当前查询的统一信用代码是：{{route.query.unifiedSocialCreditCode}}</div>
    <div class="demo-collapse">
      <el-collapse v-model="activeNames" @change="handleChange">
        <el-collapse-item v-for="(item,index) in showList" :title="tableMap[item.tableName]" :name="index">
          <el-table :data="item.data">
            <template v-for="(t,i) in getTableLength(item.data[0])" :key="i">
              <el-table-column :prop="t" :label="fieldMap[t]" width="300"></el-table-column>
            </template>
          </el-table>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
</template>

<style lang="scss">
</style>