<template>
    <div>
      <!--引用表格-->
      <BasicTable @register="registerTable" >
        <!-- 行业分类 -->
        <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" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
        </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)"/>
      </template>
      </BasicTable>
    </div>
  </template>
  
  <script lang="ts" name="xcjd-Supervise" setup>
  import { BasicTable,TableAction,TableActionType } from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useRouter } from 'vue-router';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { columns, searchFormSchema, useSuspectsData, useCategoryData } from './components/data';
  import { getDkhjdList,getExportUrl } from './components/api';
  import { useModal } from '/@/components/Modal';
  let router = useRouter();
  
    //注册model
    // const [registerModal, { openModal }] = useModal();
  //注册table数据
  const { tableContext,onExportXls } = useListPage({
    tableProps: {
      title: '现场监督-现场监督',
      api: getDkhjdList,
      columns,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      // rowSelection: { type: 'radio' },
      showIndexColumn:true,
      clickToRowSelect: false,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        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, { }, {  selectedRowKeys }] = tableContext;
  const { createMessage } = useMessage();
  //编辑事件
   function handleEdit(record) {
    router.push({path: `/xcjd/Supervise/LookData`,query:{wrdkid:record.wrdkid,type:'edit'}})
  }
  // 查看事件
  function handleLook(record){
    router.push({path: `/xcjd/Supervise/LookData`,query:{wrdkid:record.wrdkid,type:'look'}})
  }
    /**
   * 操作栏
   */
   function getTableAction(record) {
    return [
      {
        label: '编辑',
        onClick: handleEdit.bind(null, record),
      },
      {
        label: '查看',
        onClick: handleLook.bind(null, record),
      },
    ];
  }
  </script>
  <style scoped>
  </style>
  