<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <!-- <el-form-item label="安装位置：" prop="name">
        <el-input
          v-model.trim="queryParams.name"
          placeholder="请输入安装位置"
          clearable
          size="small"
          style="width: 160px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称：" prop="name">
        <el-input
          v-model.trim="queryParams.name"
          placeholder="请输入设备名称"
          clearable
          size="small"
          style="width: 160px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
       <el-form-item label="采集时间:" class="time">
         <el-date-picker
          style="margin-top:5px;;width:340px"
          v-model="dateRange"
          size="small"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item class="right">
        <el-button plain size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="adminList" border style="margin-top:20px">
      <el-table-column label="序号" align="left" prop="id"  show-overflow-tooltip />
      <el-table-column label="设备名称" align="left" prop="deviceName"  show-overflow-tooltip />
      <el-table-column label="采集时间" align="left" prop="createTime"  show-overflow-tooltip />
      <el-table-column label="泵1运行状态" align="left" prop=""  show-overflow-tooltip  >
        <template slot-scope="scope">
          <span :class="scope.row.b1rs == 0 ? 'color3' : 'color4'">{{scope.row.b1rs == 0 ? "停止" : "运行"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="泵1故障状态 " align="left" prop=""  show-overflow-tooltip  >
        <template slot-scope="scope">
          <span :class="scope.row.b1al == 0 ? 'color4' : 'color3'">{{scope.row.b1al == 0 ? "正常" : "故障"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="泵2运行状态" align="left" prop=""  show-overflow-tooltip  >
        <template slot-scope="scope">
          <span :class="scope.row.b2rs == 0 ? 'color3' : 'color4'">{{scope.row.b2rs == 0 ? "停止" : "运行"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="泵2故障状态" align="left" prop=""  show-overflow-tooltip  >
        <template slot-scope="scope">
          <span :class="scope.row.b2al == 0 ? 'color4' : 'color3'">{{scope.row.b2al == 0 ? "正常" : "故障"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="液位开关" align="left" prop=""  show-overflow-tooltip  >
        <template slot-scope="scope">
          <span :class="scope.row.yw == 0 ? 'color4' : 'color3'">{{scope.row.yw == 0 ? "低液位" : "高液位"}}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />
    <!-- 导出-->
    <a href="" download="" id="xz" style="position: absolute;z-index: -1;opacity: 0;"></a>
  </div>
</template>
<script>
import { getWell, exportWell } from "@/api/business/ba/well";
import { BASEPATH } from "@/assets/js/common.js";
export default {
  name: "Device",
  data() {
    return {
      fileList:[],
      loading:true,
      exportLoading:false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      adminList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        name: undefined,
        dwtype:undefined,
      },
      dateRange:[],
    };
  },
  created() {
    this.getList();//初始化table
  },
  methods: {
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        name: undefined,
        channelTypeName:undefined,
        current:1,
        size:10
      }
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 查询参数列表 */
    getList() {
      let data = this.addDateRange(this.queryParams,this.dateRange)
      data.endTime = data.params.endTime
      data.startTime = data.params.beginTime
      delete data.params
      getWell(this.queryParams).then(response => {
        this.adminList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      let queryParams = {...this.queryParams};
      delete queryParams.current
      delete queryParams.size
      queryParams.dwType = queryParams.dwtype
      this.exportLoading = true;
      exportWell(queryParams).then(response =>{
        this.exportLoading = false;
        document.getElementById("xz").href = BASEPATH()  + response.data
        document.getElementById("xz").download = response.data
        document.getElementById("xz").click()
      })
    },
  }
};
</script>
