<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="退改历史" @ok="handleSubmit" width="50%">
    <a-table :dataSource="dataSource" :columns="columns">
      <template #clyjfj="{ column, record }">
        <div>
          <!-- 用插件好像不显示 -->
          <img :src="record.clyjfj" style="width: 80px; height: 80px" />
          <a-button type="primary" @click="down(record)">下载</a-button>
        </div>
      </template>
      <template #tbjdbm="{ column, record }">
        <div>
          <span v-if="record.tbjdbm == 'T1'">填报中</span>
          <span v-if="record.tbjdbm == 'T2'">待评审</span>
          <span v-if="record.tbjdbm == 'SH'">评审通过</span>
          <span v-if="record.tbjdbm == 'SHBTG'">评审不通过</span>
          <span v-if="record.tbjdbm == 'SHHDWS'">评审后待完善</span>
          <span v-if="record.tbjdbm == 'BPS'">不评审</span>
          <span v-if="record.tbjdbm == 'DKDTC'">地块待退出</span>
          <span v-if="record.tbjdbm == 'DKYTC'">地块已退出</span>
        </div>
      </template>
    </a-table>
  </BasicModal>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { backHis } from '/@/api/common/api';
  import { downloadFile } from '/@/utils/common/renderUtils';

  const dataSource = ref([]);
  const emit = defineEmits(['register']);

  const columns = [
    {
      title: '意见下发人',
      dataIndex: 'realname',
    },
    {
      title: '意见',
      dataIndex: 'clyj',
    },
    {
      title: '附件',
      dataIndex: 'clyjfj',
    },
    {
      title: '退改阶段',
      dataIndex: 'tbjdbm',
    },
    {
      title: '退回时间',
      dataIndex: 'clsj',
    },
  ];

  const [registerModal, { closeModal }] = useModalInner((data) => {
    init(data.record);
  });
  async function init(v) {
    const res = await backHis(v);
    dataSource.value = res.records;
  }

  function handleSubmit() {
    closeModal();
  }
  function down(record) {
    downloadFile(record?.clyjfj, '处理意见');
  }
</script>
