<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="WaterVelocityMonitoringList" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="瞬时流量(m3/s)" align="center" prop="q"/>
      <el-table-column label="瞬时流速(m/s)" align="center" prop="v1"/>
      <el-table-column label="设备温度" align="center" prop="dtemp"/>
      <el-table-column label="水位" align="center" prop="z"/>
      <el-table-column label="水深" align="center" prop="z1"/>
      <el-table-column label="电池电量(%)" align="center" prop="bat"/>
      <el-table-column label="数据创建时间" align="center" prop="tt"/>
      <el-table-column label="操作" align="center" width="150px" 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="瞬时流量(m3/s)" prop="q" label-width="120px">
              <el-input v-model="form.q" readonly/>
            </el-form-item>
            <el-form-item label="瞬时流速(m/s)" prop="v1" label-width="120px">
              <el-input v-model="form.v1" readonly/>
            </el-form-item>
            <el-form-item label="设备温度" prop="dtemp" label-width="120px">
              <el-input v-model="form.dtemp" readonly/>
            </el-form-item>
          </el-col>
            <el-col :span="12">
            <el-form-item label="水位" prop="z" label-width="120px">
              <el-input v-model="form.z" readonly/>
            </el-form-item>
            <el-form-item label="电池电量(%)" prop="bat" label-width="120px">
              <el-input v-model="form.bat" 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 { getWaterVelocity, selectWaterVelocityMonitoringData } from '@/api/centerMonitor/device/device'

export default {
  name: 'WaterVelocityMonitor',
  data() {
    return {
      showLongitude: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监测设备表格数据
      WaterVelocityMonitoringList: [],
      // 弹出层标题
      title: '',
      // 是否显示详情弹出层
      openSee: false,
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ST: null,
        FUN: null,
        TT: null,
        TYPE: null,
        BAT: null,
        Q: null,
        Q1: null,
        CQ1: null,
        id: null,
        deviceType: null,
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList();
  },
  props: {
    ST: '',
    deviceType: "",
  },
  methods: {
    /** 查询监测设备列表 */
    getList() {
      this.loading = true
      this.queryParams.ST = this.ST;
      selectWaterVelocityMonitoringData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.WaterVelocityMonitoringList = 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;
      getWaterVelocity(id).then(response => {
        this.form = response.data;
        this.openSee = true;
        this.title = "详情";
      });
    },
    // 表单重置
    reset() {
      this.form = {
        ST: null,
        FUN: null,
        TT: null,
        TM: null,
        VER: null,
        MARK: null,
        SERIAL: null,
        TYPE: null,
        DTEMP: null,
        BAT: null,
        SIGNAL: null,
        VT: null,
        Q: null,
        Q1: null,
        Q2: null,
        V1: null,
        CQ1: null,
        Z: null,
        Z1: 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>
