<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="sumpName">
        <el-select v-model="queryParams.sumpName" placeholder="设备名称" clearable>
          <el-option
            v-for="dict in devList"
            :key="dict.value"
            :label="dict.name"
            :value="dict.name"
          />
        </el-select>
      </el-form-item>
      <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="historyList">
      <el-table-column label="设备名称" align="center" prop="sumpName" />
      <el-table-column label="设备编号" align="center" prop="sumpId" />
      <el-table-column label="设备安装描述" align="center" prop="installationLocation" />
      <el-table-column label="液位高度（m）" align="center" prop="heghtThreshold" />
      <el-table-column label="监测时间" align="center" prop="time" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.time) }}</span>
        </template>
      </el-table-column>
    </el-table>

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

<script>
  import {getHistory, listSumpHistory} from "@/api/tyler/waterLevelHis";
  import {draDeviceName} from "@/api/tyler/common";

  export default {
  name: "History",
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备历史信息表格数据
      historyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sumpName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      // 日期范围
      dateRange: [],
      devList: [],
    };
  },
  created() {
    draDeviceName({typeId:2}).then(res => {
      this.devList = res.data;
    })
    this.getList();
  },
  methods: {
    /** 查询设备历史信息列表 */
    getList() {
      this.loading = true;
      listSumpHistory(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.historyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    
   
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
