<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="WaterQualityMonitoringList" @selection-change="handleSelectionChange" width="1200px">
      <!--<el-table-column type="selection" width="30" align="center"/>-->
      <el-table-column label="水质悬浮物(mg/L)" align="center" prop="waterQualitySuspension"/>
      <el-table-column label="化学需氧量(mg/L)" align="center" prop="cod"/>
      <el-table-column label="氨氮(mg/L)" align="center" prop="ammoniaNitrogen"/>
      <el-table-column label="水中PH(pH)" align="center" prop="waterPh"/>
      <el-table-column label="水温(℃)" align="center" prop="waterTemperature"/>
      <el-table-column label="信号强度(RSSI)" align="center" prop="signalStrength"/>
      <el-table-column label="数据创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" width="120px" 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="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="水质悬浮物(mg/L)" prop="waterQualitySuspension" label-width="150px">
              <el-input v-model="form.waterQualitySuspension" readonly/>
            </el-form-item>
            <el-form-item label="化学需氧量(mg/L)" prop="cod" label-width="150px">
              <el-input v-model="form.cod" readonly/>
            </el-form-item>
            <el-form-item label="氨氮(mg/L)" prop="ammoniaNitrogen" label-width="150px">
              <el-input v-model="form.ammoniaNitrogen" readonly/>
            </el-form-item>
            <el-form-item label="水中PH(pH)" prop="waterPh" label-width="150px">
              <el-input v-model="form.waterPh" readonly/>
            </el-form-item>
          </el-col>
            <el-col :span="12">
            <el-form-item label="生化需氧量(mg/L)" prop="bod" label-width="150px">
              <el-input v-model="form.bod" readonly/>
            </el-form-item>
            <el-form-item label="水温(℃)" prop="waterTemperature" label-width="150px">
              <el-input v-model="form.waterTemperature" readonly/>
            </el-form-item>
            <el-form-item label="信号强度(RSSI)" prop="signalStrength" label-width="150px">
              <el-input v-model="form.signalStrength" 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 { selectWaterQualityMonitoringData, getWaterQuality } from '@/api/centerMonitor/device/device'

export default {
  name: 'WaterQualityMonitor',
  data() {
    return {
      showLongitude: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监测设备表格数据
      WaterQualityMonitoringList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openSee: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        waterQualitySuspension: null,
        cod: null,
        ammoniaNitrogen: null,
        waterPh: null,
        bod: null,
        waterTemperature: null,
        signalStrength: null,
        id: null,
        deviceType: null,
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList();
  },
  props: {
    deviceCode: '',
    deviceType: "",
  },
  methods: {
    /** 查询监测设备列表 */
    getList() {
      this.loading = true
      this.queryParams.deviceCode=this.deviceCode
      selectWaterQualityMonitoringData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.WaterQualityMonitoringList = 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;
      getWaterQuality(id).then(response => {
        this.form = response.data;
        this.openSee = true;
        this.title = "详情";
      });
    },
    // 表单重置
    reset() {
      this.form = {
        waterQualitySuspension: null,
        cod: null,
        ammoniaNitrogen: null,
        waterPh: null,
        bod: null,
        waterTemperature: null,
        signalStrength: null,
        errorCode: null,
        version: 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>
