<template>
  <div class="ele-body">
    <el-card shadow="never" v-loading="loading">
      <setting-search @search="reload"> </setting-search>
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        cache-key="systemRoleTable"
      >
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-plus"
            class="ele-btn-icon"
            @click="openEdit()"
          >
            新建
          </el-button>
        </template>
        <template v-slot:enable="{ row }">
          <el-switch
            v-model="row.enable"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="0"
            disabled
          >
          </el-switch>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link
            type="primary"
            :underline="false"
            icon="el-icon-edit"
            @click="openEdit(row)"
          >
            修改
          </el-link>
          <el-popconfirm
            class="ele-action"
            title="确定要删除此告警设置吗？"
            @confirm="remove(row)"
          >
            <template v-slot:reference>
              <el-link type="danger" :underline="false" icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
	
	<AddWarningDialog
	  ref="addWarningDialogRef"
	  :dialogTitle="dialogTitle"
	  @refreshList="reload"
	/>

  </div>
</template>

<script>
  import SettingSearch from './components/setting-search.vue';
  import AddWarningDialog from './components/addWarningDialog.vue'
  import dictMixins from '@/mixins/dictMixins';
  import { planConfigPage, removeRule } from '@/api/ruleManagement/plan';
  export default {
    mixins: [dictMixins],
    components: {
      SettingSearch, AddWarningDialog
    },
    data () {
      return {
        // 表格列配置
        columns: [
          {
            columnKey: 'index',
            label: '序号',
            type: 'index',
            width: 55,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'status',
            label: '告警级别',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110,
            formatter: (_row, _column, cellValue) => {
              return this.getDictValue('告警级别', _row.status);
            }
          },		  
          {
            prop: 'enable',
            label: '状态',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
          {
            prop: 'fl',
            label: '告警设备分类',
            align: 'center',
            showOverflowTooltip: true,
            minWidth: 110
          },
		  {
		    prop: 'groupName',
		    label: '告警名称',
		    align: 'center',
		    showOverflowTooltip: true,
		    minWidth: 110
		  },
		  {
		    prop: 'categoryName',
		    label: '告警描述',
		    align: 'center',
		    showOverflowTooltip: true,
		    minWidth: 110
		  },
          {
            columnKey: 'action',
            label: '操作',
            width: 150,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 加载状态
        loading: false,
        pageType: 'add',
        dialogTitle: '',
        isBindPlan: false
      };
    },
    computed: {},
    created () {
      this.requestDict('告警级别');
    },
    methods: {
      /* 表格数据源 */
      datasource ({ page, limit, where, order }) {
        return planConfigPage({
          pageNum: page,
          size: limit,
          ...where,
          ruleType: 2
        });
      },

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

      openEdit (row) {
		  if(row){
			  this.dialogTitle = '编辑告警'
		  }else{
			  this.dialogTitle = '新增告警'
		  }
		  this.$refs.addWarningDialogRef.addWarningDialog = true
      },

      remove (row) {
        removeRule([row.id]).then((res) => {
          this.$message.success('删除成功！');
          this.reload();
        });
      }
    }
  };
</script>

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