<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('zltb')" v-auth="'gkpg-tbz-zltb'">查看报告列表</a-button>
        <a-button type="primary" @click="skip('qrtc')" v-auth="'gkpg-dkdtc-qrtc'">确认退出</a-button>
        <a-button type="primary" @click="skip('thyps')" v-auth="'gkpg-dkdtc-thyps'">退回已评审</a-button>
      </template>
    </BasicTable>
    <ExitModal @register="registerModal" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="dkgl-gkpg-Filling" setup>
  import { BasicTable } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useRouter } from 'vue-router';
  import { columns, searchFormSchema, useSuspectsData, useCategoryData } from './data';
  import { exitApi, getImportUrl, getExportUrl } from './api';
  import ExitModal from '@/components/customComponent/ExitModal.vue';
  import { qrtc } from '/@/api/common/api';

  let router = useRouter();
  const { createMessage } = useMessage();
  //注册model
  const [registerModal, { openModal }] = useModal();
  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: '风险管控效果评估-待退出',
      api: exitApi,
      columns,
      canResize: false,
      clickToRowSelect: true,
      showActionColumn: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      rowSelection: { type: 'radio' },
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        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 }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;
  // 查看方案列表
  async function skip(v) {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    if (v == 'zltb') {
      router.push(`/dkgl/fxgk/DetailList?wrdkid=${selectedRowKeys.value[0]}&type=地块待退出&jdnzt=DKDTC`);
    } else if (v == 'qrtc') {
      let obj: any = {};

      obj.pgtype = selectedRows.value[0].pgtype;

      obj.wrdkid = selectedRowKeys.value[0];

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