<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <BasicTable class="w-4/4 xl:w-5/5" @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="downloadSHP" v-if="false">SHP导出</a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                label: '详情',
                onClick: () => {
                  handleAudit(record);
                },
              }
            ]"
          />
        </template>
      </template>
    </BasicTable>
    <a-modal width="75%" style="top: 30px;" v-model:open="openModal" title="线索审核" :destroyOnClose="true" :footer="null">
      <InfoModal :infoData="infoData.info" @handleOk="handleOk" @closeModal="closeModal" :control="false" :type="type"/>
    </a-modal>
  </PageWrapper>
</template>
<script lang="ts" setup>
import { nextTick, onMounted, ref } from 'vue';
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { PageWrapper } from '@/components/Page';
import InfoModal from '@/components/Audit/InfoModal/index.vue'
import { columns, searchFormSchemaFunction } from '@/views/demo/audit/util';
import { LoadCaseInfoLists, GetCaseInfo, ExportapprovalCaseInfoShapefile } from '@/api/audit/index';
import { useRouter } from 'vue-router';

const router = useRouter()
let type = router.currentRoute.value.params.id
const searchFormSchema = searchFormSchemaFunction(type,false)
const infoData = ref({})
const openModal = ref(false)

const [registerTable, { reload, expandAll}] = useTable({
  title: '已审核',
  api: (params) => LoadCaseInfoLists(type, params),
  columns,
  rowKey: 'id',
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
  },
  striped: false,
  // 序号列
  showIndexColumn: false,
  // 使用搜索表单
  useSearchForm: true,
  // 显示表格设置工具
  showTableSetting: true,
  bordered: true,
  beforeFetch(data) {
    let params = {...data,nowStatus: '已审核'}
    return params
  },
  afterFetch(data) {
    console.log('afterFetch', data);
  },
  actionColumn: {
    width: 100,
    title: '操作',
    dataIndex: 'action',
  },
  handleSearchInfoFn(info) {
    return info;
  },
});
function handleAudit(record) {
  GetCaseInfo(type, {id: record.Id}).then(res => {
    console.log(res)
    infoData.value = res
    openModal.value = true
  })
}
const handleOk = () => {
  console.log('infoData',infoData.value)
}
const closeModal = () => {
  openModal.value = false
}
const downloadSHP = () => {
  let params = {
    nowStatus: '已审核'
  }
  ExportapprovalCaseInfoShapefile(type,params).then(res => {
    const elink = document.createElement('a');
    elink.download = '已审核矢量数据' + new Date().getTime() + '.zip';
    elink.style.display = 'none';
    elink.href = URL.createObjectURL(res);
    document.body.appendChild(elink);
    elink.click();
    URL.revokeObjectURL(elink.href);
    document.body.removeChild(elink);
  })
}
</script>
