<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '详情',
              auth: 'api:yt:alarm:get',
              icon: 'ant-design:eye-outlined',
              onClick: handleDetail.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <AlarmDetailDrawer @register="registerDetailDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { alarmColumns, alarmSearchSchemas } from './config/detail.config';
  import { getDeviceAlarm } from '/@/api/device/deviceManager';
  import { useDrawer } from '/@/components/Drawer';
  import AlarmDetailDrawer from './cpns/AlarmDetailDrawer.vue';

  export default defineComponent({
    name: 'AlarmCenter',
    components: {
      BasicTable,
      TableAction,
      AlarmDetailDrawer,
    },

    setup() {
      const [registerTable, { reload }] = useTable({
        title: '告警记录列表',
        api: getDeviceAlarm,
        columns: alarmColumns,
        useSearchForm: true,
        formConfig: {
          labelWidth: 120,
          schemas: alarmSearchSchemas,
          fieldMapToTime: [['alarmTime', ['startTime', 'endTime'], 'x']],
        },
        bordered: true,
        showIndexColumn: false,
        showTableSetting: true,
        actionColumn: {
          width: 200,
          title: '操作',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      const [registerDetailDrawer, { openDrawer }] = useDrawer();
      const handleDetail = (record: Recordable) => {
        openDrawer(true, record);
      };
      const handleSuccess = () => {
        reload();
      };
      return {
        registerTable,
        registerDetailDrawer,
        handleDetail,
        handleSuccess,
      };
    },
  });
</script>
