<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <a-button type="primary" v-auth="'xchsqk:export'" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出</a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" />
      </template>
      <template #wrdkbm="{ text, record }">
        <a-button type="link" @click="handleLook(record)">{{ text }}</a-button>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="xcjd-xchsqk-index" 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 } from './components/data';
  import { getDkhcsList, getExportUrl } from './components/api';
  import { useModal } from '/@/components/Modal';
  //注册model
  const [registerModal, { openModal }] = useModal();
  //注册table数据
  const { tableContext, onExportXls } = useListPage({
    tableProps: {
      title: '现场监督-安全利用现场检查核实情况',
      api: getDkhcsList,
      columns,
      canResize: false,
      showIndexColumn: true,
      //定义rowSelection的类型，默认是checkbox多选，可以设置成radio单选
      rowKey: 'wrdkid',
      // rowSelection: { type: 'radio' },
      clickToRowSelect: true,
      formConfig: {
        labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: false,
      },
      actionColumn: {
        width: 60,
        fixed: 'right',
      },
    },
    exportConfig: {
      name: '现场监督-安全利用现场检查核实情况',
      url: getExportUrl,
    },
    // importConfig: {
    //   url: getImportUrl,
    // },
  });
  const [registerTable, {}, { selectedRowKeys }] = tableContext;
  let router = useRouter();
  const { createMessage } = useMessage();
  //编辑事件
  function handleEdit(record: Recordable) {
    router.push(`/xcjd/xchsqk/detail?wrdkid=${record.wrdkid}&type=edit`);
  }
  function handleLook(record: Recordable) {
    router.push(`/xcjd/xchsqk/detail?wrdkid=${record.wrdkid}&type=look`);
  }
  //操作栏
  function getTableAction(record) {
    return [
      {
        label: '核实',
        onClick: handleEdit.bind(null, record),
        auth: 'xcjd:xchsqk:hs',
      },
    ];
  }
</script>
<style scoped></style>
