<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="" prop="deviceName">
        <el-select
          v-model="queryParams.deviceName"
          placeholder="空压机名称"
          clearable
        >
          <el-option
            v-for="dict in deviceName"
            :key="dict.id"
            :label="dict.deviceName"
            :value="dict.id"
          />
        </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-button icon="el-icon-download" size="mini" type="primary" plain @click="exportData">导出</el-button> -->
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="infoList">
      <el-table-column
        label="空压机名称"
        align="center"
        prop="deviceName"
        width="120"
      />
      <el-table-column
        label="空压机编号"
        align="center"
        prop="deviceId"
        width="120"
      />
      <el-table-column
        label="监测时间"
        align="center"
        prop="time"
        width="160"
      />
      <el-table-column
        label="管道压力(Kpa)"
        align="center"
        prop="pipelinePressure"
        width="140"
      />
      <el-table-column
        label="瞬时流量(m³)"
        align="center"
        prop="flowRate"
        width="140"
      />
      <el-table-column
        label="瞬时流速(m³/s)"
        align="center"
        prop="velocity"
        width="140"
      />
      <el-table-column
        label="气体温度(℃)"
        align="center"
        prop="gasTemperature"
        width="120"
      />
      <el-table-column
        label="管道压力(Kpa)"
        align="center"
        prop="pipelinePressureFalse"
      />
      <el-table-column
        label="瞬时流量(m³)"
        align="center"
        prop="flowRateFalse"
      />
      <el-table-column
        label="瞬时流速(m³/s)"
        align="center"
        prop="velocityFalse"
      />
      <el-table-column
        label="气体温度(℃)"
        align="center"
        prop="gasTemperatureFalse"
      />
      <el-table-column
        label="状态"
        align="center"
        prop="fanRunStatus"
        width="140"
      >
        <template slot-scope="{ row }">
          <el-tag v-if="row.fanRunStatus == 1" type="success" size="mini"
            >启动</el-tag
          >
          <el-tag v-else-if="row.fanRunStatus == 2" type="danger" size="mini"
            >停止</el-tag
          >
          <el-tag v-else-if="fanRunStatus == 3" size="mini">复位</el-tag>
        </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 { listKongHis } from "@/api/tyler/kong";
import { kongDeviceName } from "@/api/tyler/common";

export default {
  name: "Info",
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 空压机基本信息表格数据
      infoList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceName: null,
        deviceId: null,
      },
      deviceName: [],
      dateRange: [],
    };
  },
  created() {
    kongDeviceName().then((res) => {
      this.deviceName = res.rows;
    });
    this.getList();
  },
  methods: {
    /** 导出按钮操作 */
    exportData() {
      this.download(
        "/business/pump/history/export ",
        {},
        `空压机运行历史数据_${new Date().getTime()}.xlsx`
      );
    },
    /** 查询空压机基本信息列表 */
    getList() {
      this.loading = true;
      listKongHis(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.infoList = 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>
