<script setup>

import request from "@/utils/request.js";
import {useRoute} from "vue-router";
import {ElMessage} from "element-plus";
import {fieldMap, tableMap} from "@/views/qyxypj/xypjdj/detailListMap.js";
const route = useRoute();
const activeNames = ref([])
const showList = ref([])
const detailContainer = ref(null);

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);
}



const getData = async ()=>{
  const res = await request.get('/basicData/xcrEBaseinfo/all-in',{
    params:{
      uniCode: route.query.uniCode
    }
  })
  if (res.code === 200) {
    for (let i = 0; i < res.data.length; i++) {
      activeNames.value.push(i)
    }
    showList.value = res.data;
  }else {
    ElMessage.error(res.msg);
  }
}

const specialHanle = (rowProp, index, label) => {
  if (!rowProp) return;
  if (typeof rowProp == 'string') {
    if (rowProp.includes('script') || rowProp.includes("img")) {
      return "违禁词"
    }
  }
  return rowProp;
}

const init = ()=>{
  getData();
}

init()

</script>

<template>
  <div ref="detailContainer">
    <div style="font-size: 18px;font-weight: bold;">企业名称:{{ route.query.companyName }}</div>
    <div style="font-size: 18px;font-weight: bold;">当前查询的统一信用代码是：{{ route.query.uniCode }}
    </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" max-height="250">
            <template v-for="(t,i) in getTableLength(item.data[0])" :key="i">
              <el-table-column :prop="t" :label="fieldMap[t]" width="300">
                <template #default="scope">
                  <div v-html="specialHanle(scope.row[t],i,fieldMap[t])"/>
                </template>
              </el-table-column>
            </template>
          </el-table>
        </el-collapse-item>
      </el-collapse>
    </div>
  </div>
</template>

<style lang="scss">
.demo-collapse .el-collapse-item__header {
  font-size: 18px;
  font-weight: bold;
}
</style>