<template>
  <div
    class="ele-body"
    :style="
      $route.query.isDrawer
        ? {
            position: 'fixed',
            height: '100vh',
            top: '0',
            bottom: '0',
            left: '0',
            right: '0',
            zIndex: 1000,
            background: '#fff'
          }
        : {}
    "
  >
    <el-card shadow="never" v-loading="loading">
      <message-search @search="reload"> </message-search>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :pageSizes="tablePageSizes"
        :columns="columns"
        :datasource="datasource"
        cache-key="systemRoleTable"
      >
      </ele-pro-table>
    </el-card>
  </div>
</template>

<script>
  import MessageSearch from './components/message-search.vue';
  import { alarmlogsheetPage } from '@/api/warning/index.js';

  import dictMixins from '@/mixins/dictMixins';
  export default {
    mixins: [dictMixins],
    components: {
      MessageSearch
    },
    data() {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'alarmLevel',
            label: '告警级别',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row, _column, cellValue) => {
              const map = {
                1: '提示',
                2: '一般',
                3: '严重',
                4: '紧急',
                5: '致命'
              };
              return map[cellValue] || '-';
            }
          },
          {
            prop: 'deviceCode',
            label: '设备编号',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'deviceName',
            label: '设备名称',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'description',
            label: '告警描述',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 180
          },
          {
            prop: 'generateDocumentType',
            label: '生成单据类型',
            formatter: (_row, _column, cellValue) => {
              return cellValue == 1
                ? '巡点检'
                : cellValue == 2
                ? '保养'
                : cellValue == 3
                ? '维修'
                : cellValue == 5
                ? '量具送检'
                : '';
            },
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'generateDocumentCode',
            label: '生成单据编码',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'remark',
            label: '备注',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'alarmTime',
            label: '告警时间',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 160,
            formatter: (_row, _column, cellValue) => {
              return this.$util.toDateString(cellValue);
            }
          }
        ],
        // 加载状态
        loading: false
      };
    },
    computed: {},
    created() {
      this.requestDict('规则状态');
    },
    methods: {
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return alarmlogsheetPage({
          pageNum: page,
          size: limit,
          ...where
        });
      },

      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where, ruleType: 2 });
      }
    }
  };
</script>

<style lang="scss" scoped></style>
