<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="设备编号" prop="deviceCode">
        <el-input
          v-model="queryParams.deviceCode"
          placeholder="请输入设备编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备类型" prop="deviceType">
        <el-select v-model="queryParams.deviceType" placeholder="请选择设备类型" clearable size="small">
          <el-option label="流量计" value="3" />
          <el-option label="压力表" value="4" />
        </el-select>
      </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="dataList.slice((pageNum-1)*pageSize,pageNum*pageSize)" @selection-change="handleSelectionChange">
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备编号" align="center" prop="deviceCode" />
      <el-table-column label="设备类型" align="center" prop="deviceType" >
        <template slot-scope="scope">
          <span v-if="scope.row.deviceType == '3'">流量计</span>
          <span v-if="scope.row.deviceType == '4'">压力表</span>
        </template>
      </el-table-column>
      <el-table-column label="标况累计量(m³)" align="center" prop="standardConditionAccumulation" />
      <el-table-column label="工况累计量(m³)" align="center" prop="workingConditionAccumulation" />
      <el-table-column label="剩余量(m³)" align="center" prop="residualQuantity" />
      <el-table-column label="标况流量(m³/h)" align="center" prop="standardConditionFlow" />
      <el-table-column label="工况流量(m³/h)" align="center" prop="workingConditionFlow" />
      <el-table-column label="温度(℃)" align="center" prop="temperature" />
      <el-table-column label="压力(KPa)" align="center" prop="pressure" />
      <el-table-column label="上报时间" align="center" prop="reportTime" width="180px"/>
      <el-table-column label="设备状态" align="center" prop="deviceStatus" >
      </el-table-column>
    </el-table>

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

  </div>
</template>

<script>
import { listData } from "@/api/dataMonitoring/reportData";

export default {
  name: "ReportData",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      pageNum: 1,
      pageSize: 10,
      // 设备监控表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        deviceNum: null,
        standardConditionAccumulation: null,
        workingConditionAccumulation: null,
        residualQuantity: null,
        standardConditionFlow: null,
        workingConditionFlow: null,
        temperature: null,
        pressure: null,
        reportTime: null,
        communicationStatus: null,
        deviceStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询设备监控列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deviceReportDataId: null,
        deviceNum: null,
        standardConditionAccumulation: null,
        workingConditionAccumulation: null,
        residualQuantity: null,
        standardConditionFlow: null,
        workingConditionFlow: null,
        temperature: null,
        pressure: null,
        reportTime: null,
        communicationStatus: "0",
        deviceStatus: "0",
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.deviceReportDataId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
