<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="退改历史" @ok="handleSubmit" width="50%">
    <a-table :dataSource="dataSource" :columns="columns">
      <template #bodyCell="{ column, record }">
        <template v-if="column.dataIndex == 'clyjfj'">
          <div>
            <!-- 用插件好像不显示 -->
            <!-- <img v-if="record.clyjfj" :src="record.clyjfj" style="width: 80px; height: 80px" /> -->
            <a-button type="primary" v-if="record.clyjfj" @click="down(record?.clyjfj, '处理意见')">下载</a-button>
          </div>
        </template>
        <template v-if="column.dataIndex == 'tbjdbm'">
          <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>
      </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 '/@/api/common/api';

  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(url, name) {
    let fileExtension = url.split('.').pop();
    downloadFile('/sys/common/static' + url, `${name}.${fileExtension}`);
  }
</script>
