<template>
  <div>
    <BasicTable @register="registerTable" :searchInfo="searchInfo">
      <template #toolbar>
        <PermissionBtn @btn-event="onBtnClicked" />
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              {
                // icon: 'ant-design:ellipsis-outlined',
                label: '详情',
                onClick: transaction.bind(null, record),
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
    <AuditModel @register="registerAuditModel" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup>
  import { reactive } from 'vue';

  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { queryMyUnfinished } from '@/api/demo/handlingmanagement';

  import { useMessage } from '@/hooks/web/useMessage';
  import { useModal } from '@/components/Modal';
  import { AuditModel } from '@/views/demo/handlingmanagement/intend/page';
  import { PermissionBtn } from '@/components/PermissionBtn/index';
  import { columns, searchFormSchema  } from '@/views/demo/handlingmanagement/intend/data';


  defineOptions({ name: 'RoleManagement' });

  const { createConfirm, createMessage } = useMessage();
  const [registerAuditModel, { openModal: openAuditModel }] = useModal();

  const searchInfo = reactive<Recordable>({});

  const [registerTable, { reload, getSelectRows, clearSelectedRowKeys }] = useTable({
    // 表格名称
    title: '未办结列表',
    // 获取数据的接口
    api: queryMyUnfinished,
    // 表单列信息 BasicColumn[]
    columns,
    rowKey: 'id',
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    // 使用搜索表单
    useSearchForm: true,
    // 显示表格设置工具
    showTableSetting: true,
    // 是否显示表格边框
    bordered: true,
    // 序号列
    showIndexColumn: true,
    // 搜索
    handleSearchInfoFn(info) {
      return info;
    },
    actionColumn: {
      width: 80,
      title: '操作',
      dataIndex: 'action',
      // slots: { customRender: 'action' },
      fixed: undefined,
    },
  });

  async function transaction(record) {
    console.log('transaction', record);
    openAuditModel(true, {
      record,
      type: 'detail',
    });
  }

  function handleSuccess() {
    clearSelectedRowKeys();
    reload();
  }
  function onBtnClicked(domId) {
    switch (domId) {
      case 'btnAdd':
        break;
      default:
        break;
    }
  }
</script>
