<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
        <a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined" v-auth="'zjgl-cq-add'"> 添加</a-button>

        <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls" v-auth="'zjgl-cq-dc'">导出</a-button>
      </template>
      <!-- 专业方向 -->
      <template #form-zyfx="{ model, field }">
        <a-checkbox-group v-model:value="model[field]" name="checkboxgroup" :options="plainOptions" />
      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
    </BasicTable>

    <!-- 表单区域 -->
    <addCqModal @register="registerModal" @success="handleSuccess"></addCqModal>
    <cqListModal @register="registerCCModal" @success="handleSuccess" />
  </div>
</template>

<script lang="ts" name="zjgl-gZjcyb" setup>
  import { BasicTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage';
  import addCqModal from './modules/addCqModal.vue';
  import cqListModal from './modules/cqListModal.vue';
  import { Cqcolumns, searchcqFormSchema, useSpeciality } from './GZjcyb.data';
  import { cqlist, deleteCq, importExcelCc } from './GZjcyb.api';

  //注册model
  const [registerModal, { openModal }] = useModal();
  const [registerCCModal, { openModal: openCcModal }] = useModal();
  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '专家抽取',
      api: cqlist,
      columns: Cqcolumns,
      canResize: false,
      clickToRowSelect: true,
      rowKey: 'cqdkId',
      ellipsis: false,
      // rowSelection: { type: 'radio' },
      formConfig: {
        labelWidth: 120,
        schemas: searchcqFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        autoAdvancedCol: 10, //超过几行显示折叠默认是3
      },
      actionColumn: {
        width: 120,
      },
    },
    exportConfig: {
      name: '专家抽取',
      url: importExcelCc,
    },
  });
  const plainOptions = useSpeciality().data;
  const [registerTable, { reload }, {}] = tableContext;

  /**
   * 新增事件
   */
  function handleAdd() {
    openModal(true, {
      isUpdate: false,
      showFooter: true,
    });
  }
  /**
   * 抽取
   */
  function handleAddcc(record: Recordable) {
    openCcModal(true, {
      record,
      isUpdate: true,
      showFooter: true,
    });
  }
  /**
   * 详情
   */
  function handleDetail(record: Recordable) {
    openModal(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
  }
  /**
   * 删除事件
   */
  async function handleDelete(record) {
    await deleteCq({ cqdkId: record.cqdkId }, reload);
  }

  /**
   * 成功回调
   */
  function handleSuccess() {
    reload();
  }
  /**
   * 操作栏
   */
  function getTableAction(record) {
    return [
      {
        label: '抽取',
        ifShow: record.status == '1' ? true : false,
        onClick: handleAddcc.bind(null, record),
      },
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      },
      {
        label: '删除',
        ifShow: record.status == '1' ? true : false,
        popConfirm: {
          title: '是否确认删除',
          confirm: handleDelete.bind(null, record),
        },
      },
    ];
  }
</script>
<style scoped></style>
