<template>
  <BasicTable @register="registerTable">
    <template #bodyCell="{ column, text }">
      <template v-if="column.dataIndex === 'yqsc'">
        <div v-if="text == '用户尚未登录'" class="text-red">{{ text }}</div>
        <div v-if="text.includes('未逾期')" class="text-[#84CDFF]">{{ text }}</div>
        <div v-if="text.includes('逾期')" class="text-[#FFA584]">{{ text }}</div>
      </template>
    </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>
    <template #tableTitle>
      <a-button type="primary" preIcon="ant-design:export-outlined" v-auth="'yqqkjc-dc'" @click="onExportXls"> 导出</a-button>
    </template>
  </BasicTable>
</template>
<script setup lang="ts">
  import { BasicTable } from '@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { YqColumns, YqseachFormSchema, useCategoryData } from './data';
  import { yqqkjc, yqqkjcExcel } from './api';

  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '',
      api: yqqkjc,
      columns: YqColumns,
      canResize: false,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      clickToRowSelect: true,
      showActionColumn: false,
      beforeFetch(params: any) {
        if (params.hylb) {
          if (params.hylb.length == 1) {
            params.hyml = params.hylb;
          } else if (params.hylb.length == 2) {
            params.hydl = params.hylb;
          } else if (params.hylb.length == 3) {
            params.hyzl = params.hylb;
          } else if (params.hylb.length == 4) {
            params.hyxl = params.hylb;
          }
        }
      },
      formConfig: {
        labelWidth: 120,
        schemas: YqseachFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 120,
        fixed: 'right',
      },
    },
    exportConfig: {
      name: '逾期情况监测',
      url: yqqkjcExcel,
    },
  });
  const [registerTable, {}, {}] = tableContext;
  const useCategory = useCategoryData();
  const treeData = useCategory.data; // 行业类别-数据
</script>
