<template>
  <BasicTable @register="registerTable">
    <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>
    <template #tableTitle>
      <a-button type="primary" preIcon="ant-design:export-outlined" v-auth="'tbgj-dc'" @click="onExportXls"> 导出</a-button>
    </template>
  </BasicTable>
</template>
<script setup lang="ts">
  import { BasicTable } from '@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';

  import { Columns, searchFormSchema, useCategoryData } from './data';
  import { sbxcjd, sbxcjdExcel } from './api';

  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '',
      api: sbxcjd,
      columns: Columns,
      canResize: false,
      rowSelection: { type: 'radio' },
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      showActionColumn: false,
      beforeFetch(params: any) {
        if (params.data) {
          const arry = params.data.split(',');
          params.startTime = arry[0];
          params.endTime = arry[1];
        }
        let res = [...Columns];
        res.splice(7, 0, {
          title: '监督管理标题',
          dataIndex: 'jdglbt',
          resizable: true,
        });
        res.splice(8, 0, {
          title: '最新监督管理时间',
          dataIndex: 'jdglsj',
          resizable: true,
        });
        res.splice(9, 0, {
          title: '监督管理状态',
          dataIndex: 'jdglzt',
          resizable: true,
        });

        setColumns(res);
      },
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
    },
    exportConfig: {
      name: '上报现场监督',
      url: sbxcjdExcel,
    },
  });
  const [registerTable, { setColumns }, {}] = tableContext;
  const useCategory = useCategoryData();
  const treeData = useCategory.data; // 行业类别-数据
</script>
