<template>
  <div>
    <BasicTable :clickToRowSelect="false" @register="registerTable">
      <template #toolbar> </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '详情',
              auth: 'api:yt:log:get',
              icon: 'clarity:note-edit-line',
              onClick: handleViewDetail.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <OperateDrawer @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>

<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useDrawer } from '/@/components/Drawer';
  import OperateDrawer from './OperateDrawer.vue';
  import { getOperatePage } from '/@/api/log/logManager';
  import { searchFormSchema, columns } from './config.data';
  import { useModal } from '/@/components/Modal';

  export default defineComponent({
    components: {
      BasicTable,
      TableAction,
      OperateDrawer,
    },
    setup() {
      const [registerModal] = useModal();
      const [registerTable, { reload }] = useTable({
        // 表格头部
        title: '操作日志列表',
        api: getOperatePage,
        columns,
        showIndexColumn: false,
        clickToRowSelect: false,
        beforeFetch: (T) => {
          if (T.actionType == 'ALL') {
            delete T.actionType;
          }
        },
        // 搜索表格
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
          fieldMapToTime: [['queryTime', ['startTime', 'endTime'], 'x']],
        },
        // 是否需要搜索框
        useSearchForm: true,
        // 是否需要表格设置框
        showTableSetting: true,
        // 是否需要边框
        bordered: false,
        rowKey: 'id',
        actionColumn: {
          width: 200,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      // 弹框
      const [registerDrawer, { openDrawer }] = useDrawer();

      // 刷新
      const handleSuccess = () => {
        reload();
      };

      const handleViewDetail = (record) => {
        openDrawer(true, {
          isUpdate: true,
          record,
        });
      };
      return {
        handleSuccess,
        registerTable,
        registerDrawer,
        handleViewDetail,
        registerModal,
      };
    },
  });
</script>
