<template>
  <div>
    <el-card style="height: 958px">
      <el-col :span="8">
        <span style="color: #ff0000;font-weight: bolder">设备实时报警</span>
        <el-button :disabled="loading" type="text" icon="el-icon-refresh" style="margin-left: 10px;font-size: 14px" @click="searchTable()"></el-button>
        <div style="margin-top: 10px">
          <el-table
              :data="tableData"
              :header-cell-style="{background:'#F5F5F5'}"
              element-loading-text="数据加载中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(0, 0, 0, 0.2)"
              tooltip-effect="dark"
              style="width: 100%"
              height="850"
              border
              highlight-current-row
              stripe>
            <el-table-column
                type="index"
                width="50">
            </el-table-column>
            <el-table-column align="center" label="报警内容" min-width="100">
              <template slot-scope="scope">
                {{ scope.row.报警内容 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="开始时间" width="180">
              <template slot-scope="scope">
                {{ scope.row.开始时间 }}
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
      <el-col :span="15" style="margin-left: 10px">
        <span>报警名称</span>
        <el-input v-model="alarmName" style="width:250px;margin-left: 10px" clearable placeholder="报警名称"></el-input>
        <span style="margin-left: 5px">日期：</span>
        <el-date-picker v-model="deliveryDate" type="daterange" range-separator="至" start-placeholder="开始日期" value-format="yyyy-MM-dd" end-placeholder="结束日期" style="width:250px"/>
        <el-button :disabled="loading" type="success" plain icon="el-icon-search" style="margin-left: 10px" @click="searchTable1()">查询</el-button>
        <div style="margin-top: 10px">
          <el-table
              v-loading="loading"
              :data="tableData1"
              :header-cell-style="{background:'#F5F5F5'}"
              element-loading-text="数据加载中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(0, 0, 0, 0.2)"
              tooltip-effect="dark"
              style="width: 100%"
              height="780"
              border
              highlight-current-row
              stripe>
            <el-table-column
                type="index"
                width="50">
            </el-table-column>
            <el-table-column align="center" label="报警内容" min-width="100">
              <template slot-scope="scope">
                {{ scope.row.报警内容 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="开始时间" width="180">
              <template slot-scope="scope">
                {{ scope.row.开始时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="解除时间" width="180">
              <template slot-scope="scope">
                {{ scope.row.结束时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" label="持续时长(s)" width="180">
              <template slot-scope="scope">
                {{ scope.row.持续时间 }}
              </template>
            </el-table-column>
          </el-table>
          <div class="block" style="margin-top: 10px;">
            <el-pagination
                :current-page="PageCurrent"
                :page-sizes="[50, 70, 100, 150]"
                :page-size="pageSize"
                :total="total"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"/>
          </div>
        </div>
      </el-col>
    </el-card>
  </div>
</template>
<script>
import { getNowTime2 } from '@/utils/tool'
export default {
  data() {
    return {
      deliveryDate: [],
      textarea: '',
      alarmName: '',
      programName: '',
      upValue: 0,
      downValue: 0,
      loading: false,
      tableData: [],
      tableData1: [],
      timer: null,
      total: 0, // 总条数
      pageSize: 50, // 每页显示条数
      PageCurrent: 1 // 后台获取页
    }
  },
  computed: {},
  mounted() {
    this.searchTable()
    this.searchTable1()
  },
  created() {
    const scope = this
    const start = new Date()
    const end = new Date(start.getTime() - 3600 * 1000 * 24 * 15)
    this.deliveryDate[1] = getNowTime2(start)
    this.deliveryDate[0] = getNowTime2(end)
    this.timer = setInterval(() => {
      scope.searchTable()
    }, 5000)
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    searchTable() {
      var param = []
      var Data = this.CreateData('11', '报警管理_设备当前报警_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.tableData = response.data
        }
      })
    },
    searchTable1() {
      this.loading = true
      var param = []
      param[0] = ['开始时间', this.deliveryDate[0]]
      param[1] = ['结束时间', this.deliveryDate[1]]
      param[2] = ['PageCurrent', this.PageCurrent]
      param[3] = ['PageSize', this.pageSize]
      param[4] = ['PageCount', '1111', 'int', '1']
      param[5] = ['ItemCount', '1111', 'int', '1']
      param[6] = ['报警名称', this.alarmName]
      var Data = this.CreateData('11', '报警管理_设备历史报警_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length !== 0) {
          this.tableData1 = response.data.result
          this.total = parseInt(response.data.output[0].ItemCount)
        }
        this.loading = false
      })
    },
    handleSizeChange(val) {
      this.PageCurrent = 1
      this.pageSize = val
      this.searchTable1()
    },
    handleCurrentChange(val) {
      this.PageCurrent = val
      this.searchTable1()
    }
  }
}
</script>
<style scoped>
.div1{
  width: 140px;
  height: 105px;
  margin-left:15px;
  margin-top:15px;
  background: green;
  color: white;
  font-size: 25px;
}
.div2{
  width: 140px;
  height: 105px;
  margin-left:15px;
  margin-top:15px;
  background: #60839e;
  color: white;
  font-size: 25px;
}
.Checkbox {
  position: absolute;
  visibility: hidden;
}
</style>
