<template lang='pug'>
    el-container(style="padding:0px;height:77.6vh;")
        el-header(style='height:42px;line-height:42px;border: 1px solid rgba(196, 196, 196, 1);background: #f4f4f4;')
            span.title-bold.title-left-color() 告警信息
            el-popover( placement="bottom" width="150")
                el-button( slot="reference" size='mini' type="primary" icon="el-icon-s-tools" style='float:right;transform:translateY(6px)')  筛选
                el-checkbox-group( v-model="checkList")
                    el-col( :span="24")
                        el-checkbox( v-for="(item,index) in tableHeader" :label="item" :key="index" )
                            span {{item.label}}
        el-main.box_main
            el-card()
                div.tableCard()
                    el-form( :inline="true" :model="dataForm" size="mini" @keyup.enter.native="getDataList()")
                        el-form-item( label="设备名称:")
                            el-select(style='width:100%;' class="inputWidth" v-model="dataForm.eqId" placeholder="请选择" clearable)
                                el-option(v-for="(item, index) in eqList" :key="index" :label="item.name" :value="item.id")
                        el-form-item( label="告警时间:")
                            el-date-picker(type="datetime" value-format="yyyy-MM-dd HH:mm:ss" class="inputWidth" style="width:175px;" v-model="dataForm.startTime" placeholder="选择开始时间"  clearable)
                        el-form-item( label="至")
                            el-date-picker( type="datetime" value-format="yyyy-MM-dd HH:mm:ss" class="inputWidth" style="width:175px;" v-model="dataForm.endTime" placeholder="选择结束时间" clearable)
                        el-button( type="primary" size='mini' icon="el-icon-search" @click="getDataList()") 查询
                        el-button(@click="reSet()" size='mini' type="primary" icon="el-icon-refresh-right") 重置
                    //- card body
                    //el-table(:data="dataList" @sort-change='sortChange' style="width: 100%;" v-loading="dataListLoading" :stripe="true"  :header-cell-style="{background:'#EEF8FF',color:'#333333'}")
                        el-table-column( type="index" header-align="center" align="center" label="序号")
                          template(scope="scope")
                            span {{scope.$index+(pageIndex - 1) * pageSize + 1}}
                        el-table-column( prop="type" header-align="center" align="center" label="告警类型" sortable='custom')
                            template(slot-scope='scope')
                                font(v-for="(item, index) in alarmTypeList" :key="index" )
                                    span(v-if='scope.row.type===parseInt(item.value)') {{item.name}}
                        el-table-column( prop="level" header-align="center" align="center" label="告警级别" sortable='custom')
                            template(slot-scope='scope')
                                font(v-if='scope.row.level===1') 特别重大
                                font(v-if='scope.row.level===2') 重大
                                font(v-if='scope.row.level===3') 一般
                        el-table-column( prop="code" header-align="center" align="center" label="告警码" sortable='custom')
                        el-table-column( prop="eqName" column-key='eq_name' header-align="center" align="center" label="设备名称" sortable='custom')
                        el-table-column( prop="stationName" column-key='station_name' header-align="center" align="center" label="站点名称" sortable='custom')
                        el-table-column( prop="reportTime" column-key='report_time' header-align="center" align="center" label="告警发生时间" sortable='custom')
                        el-table-column( prop="remark" header-align="center" align="center" label="备注" sortable='custom')
                drag-table( :data="dataList" :header="checkList"  :option="tableOption"  @getDataList="getDataList" v-loading="dataListLoading"  :operationNum="4"  :isShowOperate="false")
                    //- -- 插槽
                    el-table-column(slot="fixed"  fixed  prop=""  label="序号"   header-align="center" align="center" width=80)
                        template( slot-scope="scope")
                            span   {{scope.$index+(pageIndex - 1) * pageSize + 1}}
                    template(slot='type' slot-scope='scope')
                        font {{scope.row.typeName}}
                        //font(v-for="(item, index) in alarmTypeList" :key="index" )
                            span(v-if='scope.row.type===parseInt(item.value)') {{item.name}}
                    template( slot='code' slot-scope="scope")
                        font(:title="scope.row.code") {{scope.row.code}}
                    template(slot='level' slot-scope="scope")
                        font(v-if='scope.row.level===1') 特别重大
                        font(v-if='scope.row.level===2') 重大
                        font(v-if='scope.row.level===3') 一般
                    template( slot='remark' slot-scope="scope")
                        font(:title="scope.row.remark") {{scope.row.remark}}

        el-footer.box_footer
            el-pagination(background  @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize"  :total="totalPage" layout="total, sizes, prev, pager, next, jumper")
</template>

<script>
import dragTable from '../../components/tab'
export default {
  data () {
    return {
      data: [],
      dataForm: {
        eqId: '',
        startTime: '',
        endTime: ''
      },
      dataList: [],
      eqList: [],
      alarmTypeList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      sort: '',
      order: '',
      dataListLoading: false,
      dataListSelections: [],
        checkList: [],
        tableHeader: [
            { label: '告警类型', prop: 'type', slot: true },
            { label: '告警级别', prop: 'level', slot: true, width: 120 },
            { label: '告警码', prop: 'code', slot: true },
            { label: '参考值', prop: 'byx1' },
            { label: '告警值', prop: 'byx2' },
            { label: '设备名称', prop: 'eqName' },
            { label: '站点名称', prop: 'sname' },
            { label: '告警发生时间', prop: 'reportTime' },
            { label: '备注', prop: 'remark', width: 220, slot: true }
        ],
        tableOption: {
            border: false, //是否边框
            maxHeight: 500 //高度
        }
    }
  },
  components: {
     dragTable
  },
  watch: {
      totalPage() { //注意这个函数的名字必须和你监听data中的属性的名字一样，这样才能当你data中的属性发生变化时，触发这个函数
          let pages = Math.ceil(this.totalPage / this.pageSize)//新数据总页数
          //总页数小于当前页数则重新加载列表数据
          if (pages < this.pageIndex) {
              this.pageIndex = pages || 1
              this.getDataList()//获取表格数据的方法
          }
      }
  },
  created () {
    this.checkList = [...this.tableHeader]
    this.getDataList()
    this.getEquipmentList()
  },
  methods: {
    //重置
    reSet() {
          this.dataForm = {}
          this.pageIndex = 1
          this.getDataList()
    },
    //获取设备信息
    getEquipmentList () {
      this.$http({
        url: this.$http.adornUrl('/eqEquipment/queryList'),
        method: 'get',
        params: {
            'stationId': localStorage.getItem('stationId')
        }
      }).then(data => {
        if (data && data.code === 0) {
          this.eqList = data.list
        }
      })
    },
    sortChange (column) {
      if (column.order === 'descending') {
        this.order = 'desc'
      } else {
        this.order = 'asc'
      }
      if (column.column.columnKey) {
        this.sort = column.column.columnKey
      } else {
        this.sort = column.prop
      }
      this.getDataList()
    },
    // 获取数据列表
    getDataList (sort, order) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/eqAlarm/list'),
        method: 'post',
        data: {
          eqId: this.dataForm.eqId,
          stationId: localStorage.getItem('stationId'),
          startTime: this.dataForm.startTime,
          endTime: this.dataForm.endTime,
          page: this.pageIndex,
          rows: this.pageSize,
          sort: sort,
          order: order
        }
      }).then(data => {
        if (data && data.code === 0) {
          this.dataList = data.page.rows
          this.totalPage = data.page.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    indexMethod(index) {
       return (this.pageIndex - 1) * this.pageSize + index + 1
    }
  }
}
</script>
<style lang='scss'>
</style>
