<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="handleView" v-auth="'fxpg-pshdws-jbxx'">查看基本信息</a-button>
        <a-button type="primary" @click="handleComint" v-auth="'fxpg-dqr-dqr'">待确认</a-button>
        <a-button type="primary" @click="handelStep" v-auth="'fxpg-dqr-lct'">流程图</a-button>
      </template>
    </BasicTable>
  </div>
  <ConfirmedModal @register="registerModal" @success="handleSuccess" />
  <!-- 流程图 -->
  <Step @register="registerlcModal" />
</template>

<script lang="ts" name="dkgl-fxpg-Improved" setup>
  import { BasicTable } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useRouter } from 'vue-router';
  import { useModal } from '/@/components/Modal';
  import { useMessage } from '/@/hooks/web/useMessage';
  import ConfirmedModal from '@/components/customComponent/ConfirmedModal.vue';
  import { columns, searchFormSchema, useSuspectsData, useCategoryData } from './data';
  import Step from '/@/components/customComponent/steps/step.vue';
  import { improvedList, getImportUrl, getExportUrl } from './api';
  import { chTip } from '@/utils/checkTip';

  const router = useRouter();
  const { createMessage } = useMessage();
  const [registerModal, { openModal }] = useModal();
  const [registerlcModal, { openModal: openlcModal }] = useModal();
  //注册table数据
  const { tableContext } = useListPage({
    tableProps: {
      title: '风险评估-评审后待完善',
      api: improvedList,
      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: 'tx',
          resizable: true,
        });

        setColumns(res);
      },
      formConfig: {
        labelWidth: 120,
        schemas: [
          ...searchFormSchema,
          {
            label: '阶段内状态',
            field: 'jdnzt',
            component: 'Input',
            defaultValue: 'SHHDWS',
            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 handleView() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    router.push(`/dkgl/fxpg/ViewDetail?wrdkid=${selectedRowKeys.value[0]}`);
  }
  function handleComint() {
    if (selectedRows.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    if (!chTip(selectedRows.value)) return;
    if (selectedRows.value[0].jdnzt == '待受理' && selectedRows.value[0].sfthxg == 1) {
      openModal(true, {
        record: selectedRows.value[0],
        isUpdate: true,
        showFooter: true,
      });
    } else {
      createMessage.info('数据还未提交，请提交后再进行操作');
    }
  }
  function handleSuccess() {
    selectedRows.value = [];
    selectedRowKeys.value = [];
    reload();
  }
  // 点击查看流程图
  function handelStep() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    openlcModal(true, {
      record: selectedRows.value[0],
      isUpdate: true,
      showFooter: true,
    });
  }
</script>
<style scoped></style>
