<template>
  <BasicTable @register="registerTable">
    <template #form-userLevle="{ model, field }">
      <a-select
        v-model:value="model[field]"
        placeholder="请选择"
        @change="change(model)"
        :fieldNames="{ label: 'text', value: 'value' }"
        :options="Options"
      ></a-select>
    </template>
    <template #tableTitle>
      <a-button type="primary" preIcon="ant-design:export-outlined" v-auth="'dqcb-dc'" @click="onExportXls"> 导出</a-button>
    </template>
  </BasicTable>
</template>
<script setup lang="ts">
  import { BasicTable } from '@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { excedColumns, searchExcedFormSchema, getUserLevel } from './data';
  import { excedList, dqcbfxExcel } from './api';

  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '',
      api: excedList,
      columns: excedColumns,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      showActionColumn: false,
      beforeFetch(params: any) {
        let res = [...excedColumns];
        if (params.level == 2) {
          res.splice(1, 0, {
            title: '县',
            dataIndex: 'countryName',
            resizable: true,
          });
          setColumns(res);
        } else {
          setColumns(res);
        }
      },
      formConfig: {
        labelWidth: 120,
        schemas: searchExcedFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
    },
    exportConfig: {
      name: '地区超标分析',
      url: dqcbfxExcel,
    },
  });
  const [registerTable, { setColumns }, {}] = tableContext;

  const Options = getUserLevel().data;
  function change(model) {
    model.cityCode = '';
  }
</script>
