<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="view" v-auth="'dkdc-dsl-jbxx'">查看基本信息</a-button>
        <!-- <a-button type="primary" @click="handleAdd('ysl')" v-auth="'dkdc-dsl-ysl'">预受理</a-button> -->
        <a-button type="primary" @click="handleAdd('')" v-auth="'dkdc-dsl-sl'">受理</a-button>
        <a-button type="primary" @click="onExportXls" v-auth="'dkdc-dsl-dc'">导出</a-button>
        <a-button type="primary" @click="handelStep" v-auth="'dkdc-dsl-lct'">流程图</a-button>
      </template>
    </BasicTable>
    <AcceptanceModal @register="registerModal" @success="handleSuccess" />
    <!-- 预受理 -->
    <Paccept @register="registerlyslModal" @success="handleSuccess" />
    <!-- 流程图 -->
    <Step @register="registerlcModal" />
  </div>
</template>
<script lang="ts" name="dkgl-investigate-Acceptance" setup>
  import { BasicTable } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useRouter } from 'vue-router';
  import AcceptanceModal from '@/components/customComponent/AcceptanceModal.vue';
  import Paccept from '@/components/customComponent/Pacceptance.vue';
  import { columns, searchFormSchema, useSuspectsData, useCategoryData } from './data';
  import { acceptanceList, getImportUrl, getExportUrl } from './api';
  import Step from '/@/components/customComponent/steps/step.vue';
  import { chTip } from '@/utils/checkTip';

  let router = useRouter();
  //注册model
  const [registerModal, { openModal }] = useModal();
  const [registerlcModal, { openModal: openlcModal }] = useModal();
  const [registerlyslModal, { openModal: openlyslModal }] = useModal();
  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '地块管理-待受理',
      api: acceptanceList,
      columns,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      rowSelection: { type: 'radio' },
      showActionColumn: false,

      formConfig: {
        labelWidth: 120,
        schemas: [
          ...searchFormSchema,
          {
            label: '阶段内状态',
            field: 'jdnzt',
            component: 'Input',
            defaultValue: 'DSL',
            show: false,
          },
        ],
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
    },
    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;
  const { createMessage } = useMessage();

  function handleAdd(v) {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    if (!chTip(selectedRows.value)) return;
    if (v == 'ysl') {
      openlyslModal(true, {
        record: selectedRows.value[0],
        isUpdate: true,
        showFooter: true,
      });
    } else {
      openModal(true, {
        record: selectedRows.value[0],
        isUpdate: true,
        showFooter: true,
      });
    }
  }
  // 点击查看详情
  function view() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    router.push(`/dkgl/investigate/modal/ViewData?wrdkid=${selectedRowKeys.value[0]}`);
  }
  // 点击查看流程图
  function handelStep() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    openlcModal(true, {
      record: selectedRows.value[0],
      isUpdate: true,
      showFooter: true,
    });
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    selectedRows.value = [];
    selectedRowKeys.value = [];
    reload();
  }
</script>
<style scoped></style>
