<template>
  <a-divider orientation="left">历次评审信息</a-divider>
  <a-table :columns="columns" :data-source="localData" :pagination="false" bordered size="middle">
    <!--操作栏-->
    <template #action="{ record }">
      <a-button type="link" @click="toDetail(record)">查看</a-button>
    </template>
    <template #bodyCell="{ column, record }">
      <template v-if="column?.dataIndex === 'tgjg'">
        <template v-if="record.tgjg === 0">未通过</template>
        <template v-else>通过</template>
      </template>
    </template>
  </a-table>
  <HistoryInfoModal @register="registerModal" />
</template>
<script lang="ts" setup>
  import { ref, watch } from 'vue';
  import { useModal } from '/@/components/Modal';
  import { getZjyjHis, getCcHis } from '@/api/dkgl.api';
  import HistoryInfoModal from './HistoryInfoModal.vue';
  const [registerModal, { openModal }] = useModal();
  const props = defineProps({
    wrdkid: {
      type: String,
      default: '',
    },
    pgtype: {
      type: String,
      default: '',
    },
    scjdbm: {
      type: String,
      default: '',
    },
    type: {
      type: String,
      default: '', // 不同的模块
    },
    dksdzt: {
      type: String,
      default: '',
    },
    faid: {
      type: String,
      default: '',
    },
    columns: {
      type: Array,
      default: () => [
        {
          title: '第几次评审',
          dataIndex: 'pscs',
          align: 'center',
        },
        {
          title: '会议时间',
          dataIndex: 'hysj',
          align: 'center',
        },
        {
          title: '处理时间',
          dataIndex: 'tsamp',
          align: 'center',
        },
        {
          title: '会议地点',
          dataIndex: 'hydd',
          align: 'center',
        },
        {
          title: '会议组织方',
          dataIndex: 'hyzzf',
          align: 'center',
        },
        {
          title: '报告是否通过',
          dataIndex: 'tgjg',
          align: 'center',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 100,
          slots: { customRender: 'action' },
        },
      ],
    },
  });
  const localData = ref([]);
  getHistory();
  async function getHistory() {
    if (!props.wrdkid) return;
    if (props.dksdzt != '1') {
      localData.value = await getZjyjHis({
        wrdkid: props.wrdkid,
        pgtype: props.pgtype,
        scjdbm: props.scjdbm,
      });
    } else {
      localData.value = await getCcHis({
        wrdkid: props.wrdkid,
        // pgtype: props.pgtype,
        scjdbm: props.scjdbm,
        faid: props.faid,
      });
    }
  }
  function toDetail(record) {
    record.dksdzt = props.dksdzt;
    console.log('toDetail', record);
    openModal(true, {
      type: props.type,
      record: record,
      showFooter: false,
    });
  }
  // 监听污染地块id
  watch(
    () => props?.wrdkid,
    async (val: any) => {
      getHistory();
    },
    { deep: true }
  );
</script>
