<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" v-auth="'repair-tbz-fa'" @click="handleAdd">查看方案列表</a-button>
        <a-button type="primary" @click="onExportXls" v-auth="'repair-tbz-dc'">导出</a-button>
        <a-button type="primary" @click="handleLsqk" v-auth="'xf-tbz-lsqk'">风险管控措施落实情况（暂不开发利用地块）</a-button>
      </template>
    </BasicTable>

    <!-- 落实情况填报 -->
    <LsqkModal @register="registerModal" />
  </div>
</template>

<script lang="ts" name="dkgl-investigate-Filling" setup>
  import { BasicTable } from '/@/components/Table';

  import { useListPage } from '/@/hooks/system/useListPage';
  import { columns, searchFormSchema, useSuspectsData, useCategoryData } from './data';
  import { fillingList, getImportUrl, getExportUrl } from './api';
  import { useRouter } from 'vue-router';
  import { useMessage } from '/@/hooks/web/useMessage';
  import LsqkModal from '@/components/customComponent/LsqkModal.vue'
  import { useModal } from '/@/components/Modal';

  const { createMessage } = useMessage();
  let router = useRouter();

  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '修复-填报中',
      api: fillingList,
      columns,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      showActionColumn: false,
      rowSelection: { type: 'radio' },
      formConfig: {
        labelWidth: 120,
        schemas: [
          ...searchFormSchema,
          {
            label: '阶段内状态',
            field: 'jdnzt',
            component: 'Input',
            defaultValue: 'T1',
            show: false,
          },
        ],
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 120,
      },
    },
    exportConfig: {
      name: '修复-填报中',
      url: getExportUrl,
    },
    importConfig: {
      url: getImportUrl,
    },
  });
  const isSuspectOptions = useSuspectsData().data; // 行业分类
  const useCategory = useCategoryData();
  const treeData = useCategory.data; // 行业类别-数据
  const changeSuspect = useCategory.changeIsSuspect; // 行业类别-方法
  const [registerTable, {}, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;
  /**
   * 新增事件
   */
  function handleAdd() {
    if (selectedRowKeys.value.length === 1) {
      router.push(`/dkgl/repair/DetailList?wrdkid=${selectedRowKeys.value[0]}&type=填报&jdnzt=T1`);
    } else {
      createMessage.info('请选择需要查看的内容，每次只能选中一条');
    }
  }

  //注册model
  const [registerModal, { openModal }] = useModal();

  function handleLsqk() {
    if (selectedRowKeys.value.length == 0) {
      createMessage.info('请选择需要处理的内容，每次只能选中一条');
      return;
    }
    openModal(true, {
      isUpdate: true,
      showFooter: true,
      record: selectedRows.value[0]
    });
  }
</script>
<style scoped></style>
