<template>
    <div class="app-container">
      <el-form :inline="true" :model="queryParams" ref="form">
        <el-form-item label="选择企业" prop="factoryId">
          <el-select v-model="queryParams.factoryId" clearable filterable placeholder="请选择" @change="getDeptTree">
            <el-option v-for="item in factorys" :key="item.value" :label="item.factoryName" :value="item.factoryId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="设备编号">
          <el-input  v-model="queryParams.sn"></el-input>
        </el-form-item>
        <el-form-item label="日期" prop="equipmentName">
          <el-date-picker v-model="dateList" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="dataList" height="600px">
        <el-table-column prop="factoryName" label="安装企业" header-align="center" align="center" />

        <el-table-column prop="sn" label="设备编号" header-align="center" align="center" />
        <el-table-column prop="reportTime" label="上报时间" header-align="center" align="center" />
        <!-- <el-table-column prop="wd" label="设备温度" header-align="center" align="center"/>-->
        <el-table-column prop="power" label="设备电量" header-align="center" align="center"/>
        <el-table-column prop="zl" label="传感器类型" header-align="center" align="center" />
        <el-table-column prop="lc" label="量程" header-align="center" align="center" />
        <el-table-column prop="ds" label="传感器读数" header-align="center" align="center">
          <template slot-scope="scope">
            <span style="color: red;">
              {{ scope.row.ds }}
            </span>
            <span style="color: #000;">
              {{ scope.row.dw }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="zt" label="报警状态" header-align="center" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.zt === '一级报警' || scope.row.zt === '二级报警'" style="color: #c00808">
              报警
            </span>
            <span v-else style="color: #000">
              {{ scope.row.zt }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="dbz" label="低报值" header-align="center" align="center" />
        <el-table-column prop="gbz" label="高报值" header-align="center" align="center" />

      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />

    </div>
  </template>

  <script>
  import store from "@/store";
  import { listAlarmHistory } from "@/api/demostrate/monitor";
  import { getAllFactory } from "@/api/home";
  export default {
    name: "alarm",
    components: {  },
    dicts: [],
    data() {
      return {
        factorys:[],
        loading: false,
        dateList: [],
        dataList: [],
        total: 0,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          sn: null,
          name: null,
          startTime: null,
          endTime: null,
          factoryId:null,
        },

      };
    },
    created() {
      this.queryParams.factoryId = store.getters.user.factoryId
    },
    mounted() {
      this.getFactory()
    },
    methods: {
           /**获取企业下拉框 */
           getFactory() {
        getAllFactory({}).then(response => {
          this.factorys = response.data;
          this.getList()
        })
      },
      //发送通知
      handleUpdate(row) {
        this.deviceInfo = row
        this.isOpenMsg = true
      },
      //处理报警
      handleAlarm(row) {
        this.deviceInfo = row
        this.isOpenAlarm = true
      },
      closeMsg() {
        this.isOpenMsg = false
        this.handleQuery()
      },
      closeAlarm() {
        this.isOpenAlarm = false
        this.handleQuery()
      },
      resetQuery() {
        this.queryParams.pageNum = 1
        this.queryParams.sn = null
        this.queryParams.name = null
        this.queryParams.startTime = null
        this.queryParams.endTime = null
      },
      getList(){
        if (this.dateList && this.dateList.length > 0) {
          this.queryParams.startTime = this.dateList[0]
          this.queryParams.endTime = this.dateList[1]
        } else {
          this.queryParams.startTime = null
          this.queryParams.endTime = null
        }
        this.loading = true;
        // listAlarmHistory(this.queryParams).then(response => {
        //   this.dataList = response.rows;
        //   this.total = response.total;
        //   this.loading = false;
        // });
        this.loading = false;
        this.total = 4301;
        this.dataList=[  {
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-26 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-25 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "二级报警",
            "dbz": 20,  "gbz": 50,

        },
        {
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-24 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB621085098QW",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-25 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 121.23,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "一级报警",
            "dbz": 50,  "gbz": 120,

        },{
            "sn": "ZABB621085098QWS",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-24 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-23 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-22 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-21 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 9.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-20 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 0.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "正常工作中",
            "dbz": 20,  "gbz": 50,

        },{
            "sn": "ZABB6210850989ZA",
            "isDeal": null,
            "name": null,
            "reportTime": "2024-05-20 23:49:12",
            "power": "59",
            "factoryName": '**有限公司',
            "wd": "0",
            "yl": "101.3",
            "latitude": "3604.89440",
            "longitude": "12022.12783",
            "lng": null,
            "lat": null,
            "cgq": 1,
            "ds": 40.0,
            "dw": "PPM",
            "lc": 500,
            "zl": "VOC",
            "zt": "二级报警",
            "dbz": 12,  "gbz": 58,

        },
    ]

      },
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()

      },
    }

  };
  </script>
