<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-09-05 10:03:30
 * @LastEditors: 无尘
 * @LastEditTime: 2019-10-23 17:47:37
 -->
<template>
  <el-dialog
    title="日志"
    :visible.sync="dialogVisible"
    width="600px"
    @close="close">
    <div class="dialog-body">
      <el-table
        :data="tableData"
        style="width: 100%"
        class="dialog-table">
        <el-table-column
          prop="alarmType"
          label="告警类型">
          <template slot-scope="scope">
            <div v-if="scope.row.alarmType === 1">
              流控告警
            </div>
            <div v-if="scope.row.alarmType === 2">
              熔断告警
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="alarmContent"
          label="告警内容"
          width="300px"
          show-overflow-tooltip />
        <el-table-column
          prop="updateTime"
          label="发生时间">
          <template slot-scope="scope">
            <div class="color-606266 line-18">
              {{ scope.row.updateTime | timeStampToYmd }}
            </div>
            <div class="color-606266 line-18">
              {{ scope.row.updateTime | timeStampToHms }}
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div
        v-if="total > 0"
        class="page-content">
        <dm-pagination
          small
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="prev, pager, next"
          :total="total"
          @current-change="handleCurrentChange" />
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getRequest } from '@/api/api';
export default {
  props: {
    alarmType: {
      type: Number,
      default() {
        return 0;
      }
    },
    sceneCode: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      dialogVisible: true,
      tableData: [],
      total: 0,
      currentPage: 1,
      pageSize: 5
    };
  },
  created() {
    this.dialogVisible = true;
    this.getList();
  },
  methods: {
    handleCurrentChange(page) {
      this.currentPage = page;
      this.getList();
    },
    getList() {
      let params = {
        sceneCode: this.sceneCode,
        alarmType: this.alarmType,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      };
      let that = this;
      getRequest('/gateway-manage/rule/alarm/log', params)
        .then(res => {
          if (res.data.code == '0000') {
            if (res.data.result.result.length) {
              this.tableData = res.data.result.result;
              this.total = res.data.result.totalCount;
            } else {
              this.tableData = [];
              this.total = 0;
            }
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    close() {
      this.dialogVisible = false;
      this.$emit('cancelLog');
    }
  }
};
</script>
<style lang="less" scoped>
.dialog-table {
  margin-bottom: 30px;
}
.page-content {
  text-align: right;
  margin-top: -15px;
}
</style>
