<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></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="WaterPressureMonitoringList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="设备编码" align="center" prop="imei"/>
      <el-table-column label="水压值" align="center" prop="hydraulicValue"/>
      <el-table-column label="水压下限阈值" align="center" prop="hydraulicThresholdMin"/>
      <el-table-column label="水压上限阈值" align="center" prop="hydraulicThresholdMax"/>
      <el-table-column label="信号强度" align="center" prop="signalPower"/>
      <el-table-column label="电池电量" align="center" prop="batteryValue"/>
      <el-table-column label="数据创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" width="100px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleSee(scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 详情 -->
    <el-dialog :title="title" :visible.sync="openSee" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="水压值" prop="hydraulicValue" label-width="120px">
              <el-input v-model="form.hydraulicValue" readonly/>
            </el-form-item>
            <el-form-item label="水压下限阈值" prop="hydraulicThresholdMin" label-width="120px">
              <el-input v-model="form.hydraulicThresholdMin" readonly/>
            </el-form-item>
            <el-form-item label="水压上限阈值" prop="hydraulicThresholdMax" label-width="120px">
              <el-input v-model="form.hydraulicThresholdMax" readonly/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="信号强度" prop="signalPower" label-width="120px">
              <el-input v-model="form.signalPower" readonly/>
            </el-form-item>
            <el-form-item label="电池电量" prop="batteryValue" label-width="120px">
            <el-input v-model="form.batteryValue" readonly/>
          </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getWaterPressure, selectWaterPressureMonitoringData } from '@/api/centerMonitor/device/device'

export default {
  name: 'WaterPressureMonitoring',
  data() {
    return {
      showLongitude: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监测设备表格数据
      WaterPressureMonitoringList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openSee: false,
      // 是否显示弹出层
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        IMEI: null,
        thresholdLowEnable: null,
        thresholdHighEnable: null,
        signalPower: null,
        hydraulicValue: null,
        hydraulicThresholdMin: null,
        heartbeatTime: null,
        deviceType: null,
        hydraulicThresholdMax:null,
        batteryValue:null
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList();
    // this.beforeGetList();

  },
  props: {
    IMEI: '',
    deviceType: "",
  },
  methods: {
    /** 查询监测设备列表 */
    // beforeGetList() {
    //   setTimeout("this.getList", 1000);
    // },
    getList() {
      // alert(this.IMEI)
      this.loading = true
      this.queryParams.IMEI=this.IMEI
      selectWaterPressureMonitoringData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.WaterPressureMonitoringList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false,
        this.openSee = false;
      this.reset()
    },
    /** 查询水压详情 */
    handleSee(row) {
      this.reset();
      const id = row.id || this.ids;
      getWaterPressure(id).then(response => {
        this.form = response.data;
        this.openSee = true;
        this.title = "详情";
      });
    },
    // 表单重置
    reset() {
      this.form = {
        IMEI: null,
        thresholdLowEnable: null,
        thresholdHighEnable: null,
        signalPower: null,
        hydraulicValue: null,
        hydraulicThresholdMin: null,
        heartbeatTime: null,
        deviceType: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  },
};
</script>
