<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <!-- 行业分类 -->
      <template #form-suspect="{ model, field }">
        <a-select
          v-model:value="model[field]"
          placeholder="请选择行业分类"
          :fieldNames="{ label: 'text', value: 'value' }"
          :options="isSuspectOptions"
          @change="changeSuspect"
        ></a-select>
      </template>
      <template #form-category="{ model, field }">
        <a-tree-select
          v-model:value="model[field]"
          show-search
          placeholder="请选择二级"
          allow-clear
          tree-default-expand-all
          :field-names="{ label: 'name', value: 'id', children: 'children' }"
          :tree-data="treeData"
          tree-node-filter-prop="label"
        >
          <template #suffixIcon>
            <SmileOutlined />
          </template>
        </a-tree-select>
      </template>
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="skip" v-auth="'gkxfpg-psytg-fa'">查看报告列表</a-button>
        <a-button type="primary" @click="exit('sttc')" v-auth="'gkxfpg-psytg-sqtc'">申请退出</a-button>
        <!-- <a-button type="primary" @click="exit('tc')" v-auth="'gkxfpg-psytg-dktc'">地块退出</a-button> -->
        <a-button type="primary" @click="onExportXls" v-auth="'gkxfpg-psytg-dc'">导出</a-button>
      </template>
    </BasicTable>
    <!-- 申请退出 -->
    <ApplyexitModal @register="registerModal" @success="handleSuccess" />
    <!-- 地块退出 -->
    <DkexitModal @register="registerdktcModal" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="dkgl-gkxfpg-Approved" setup>
  import { BasicTable } from '/@/components/Table';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useRouter } from 'vue-router';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, searchFormSchema, useSuspectsData, useCategoryData } from './data';
  import { checkXgpgTc } from '/@/api/common/api';
  import ApplyexitModal from '@/components/customComponent/ApplyexitModal.vue';
  import DkexitModal from '@/components/customComponent/DkExitModal.vue';
  import { approvedList, getImportUrl, getExportUrl } from './api';
  import { tip, chTip } from '@/utils/checkTip';

  const router = useRouter();
  const { createMessage } = useMessage();
  const [registerModal, { openModal }] = useModal();
  const [registerdktcModal, { openModal: opendktcModal }] = useModal();
  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '风险管控与修复效果评估-评审通过',
      api: approvedList,
      columns,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      showActionColumn: false,
      rowSelection: { type: 'radio' },
      beforeFetch() {
        let res = [...columns];

        res.splice(7, 0, {
          title: '地块是否超标',
          dataIndex: 'sfcb',
          resizable: true,
          customRender: ({ record }: any) => {
            return record?.sfcb==='1'?'是':record?.sfcb==='0'?'否':'未调查';
          },
        });
        res.splice(8, 0, {
          title: '地块锁定状态',
          dataIndex: 'dksdztText',
          resizable: true,
        });
        setColumns(res);
      },
      formConfig: {
        labelWidth: 120,
        schemas: [
          ...searchFormSchema,
          {
            label: '阶段内状态',
            field: 'jdnzt',
            component: 'Input',
            defaultValue: 'SH',
            show: false,
          },
          {
            label: 'pgtype',
            field: 'pgtype',
            component: 'Input',
            defaultValue: '3',
            show: false,
          },
        ],
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
    },
    exportConfig: {
      name: '风险管控与修复效果评估-评审通过',
      url: getExportUrl,
    },
    importConfig: {
      url: getImportUrl,
    },
  });
  const isSuspectOptions = useSuspectsData().data; // 行业分类
  const useCategory = useCategoryData();
  const treeData = useCategory.data; // 行业类别-数据
  const changeSuspect = useCategory.changeIsSuspect; // 行业类别-方法
  const [registerTable, { reload, setColumns }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;
  // 查看报告列表
  function skip() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    router.push(
      `/dkgl/gkxfpg/DetailList?wrdkid=${selectedRowKeys.value[0]}&type=评审已通过&jdnzt=SH&isnyd2yzlg=${selectedRows.value[0]?.isnyd2yzlg}`
    );
  }
  async function exit(v) {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    if (!chTip(selectedRows.value)) return;
    if (tip(selectedRows.value[0])) return;
    let obj: any = {};
    obj.pgtype = selectedRows.value[0].pgtype;
    obj.wrdkid = selectedRowKeys.value[0];
    if (v == 'sttc') {
      // 效果判断方案是否在外运模块里面如果在不可以提交不可以填报
      await checkXgpgTc({ wrdkid: obj.wrdkid });

      openModal(true, {
        record: obj,
        isUpdate: true,
        showFooter: true,
      });
      // await tcsq({ wrdkid: selectedRowKeys.value[0] });
      // handleSuccess();
    } else if (v == 'tc') {
      opendktcModal(true, {
        record: obj,
        isUpdate: true,
        showFooter: true,
      });
    }
  }
  function handleSuccess() {
    reload();
  }
</script>
<style scoped></style>
