<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="AtmosphereMonitoringList" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column label="二氧化硫(ug/m3)" align="center" prop="sulfurDioxide"/>
      <el-table-column label="二氧化氮(ug/m3)" align="center" prop="nitrogenDioxide"/>
      <el-table-column label="细颗粒(ug/m3)" align="center" prop="fineParticle"/>
      <el-table-column label="温度(℃)" align="center" prop="temperature"/>
      <el-table-column label="湿度(%RH)" align="center" prop="humidity"/>
      <el-table-column label="一氧化碳(mg/m3)" align="center" prop="carbonMonoxide"/>
      <el-table-column label="数据创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" width="130px" 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="二氧化硫(ug/m3)" prop="sulfurDioxide" label-width="150px">
              <el-input v-model="form.sulfurDioxide" readonly/>
            </el-form-item>
            <el-form-item label="二氧化氮(ug/m3)" prop="nitrogenDioxide" label-width="150px">
              <el-input v-model="form.nitrogenDioxide" readonly/>
            </el-form-item>
            <el-form-item label="细颗粒(ug/m3)" prop="suctionParticle" label-width="150px">
              <el-input v-model="form.suctionParticle" readonly/>
            </el-form-item>
            <el-form-item label="大气压(Kpa)" prop="atmos" label-width="150px">
              <el-input v-model="form.atmos" readonly/>
            </el-form-item>
            <el-form-item label="光照度(Lux)" prop="illuminance" label-width="150px">
              <el-input v-model="form.illuminance" readonly/>
            </el-form-item>
          </el-col>
            <el-col :span="12">
            <el-form-item label="温度(℃)" prop="temperature" label-width="150px">
              <el-input v-model="form.temperature" readonly/>
            </el-form-item>
            <el-form-item label="湿度(%RH)" prop="humidity" label-width="150px">
              <el-input v-model="form.humidity" readonly/>
            </el-form-item>
              <el-form-item label="微粒(ug/m3)" prop="fineParticle" label-width="150px">
                <el-input v-model="form.fineParticle" readonly/>
              </el-form-item>
            <el-form-item label="一氧化碳(mg/m3)" prop="carbonMonoxide" label-width="150px">
              <el-input v-model="form.carbonMonoxide" readonly/>
            </el-form-item>
              <el-form-item label="臭氧(ug/m3)" prop="ozone" label-width="150px">
                <el-input v-model="form.ozone" 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 { selectAtmosphereMonitoringData, getAtmosphere } from '@/api/centerMonitor/device/device'

export default {
  name: 'AtmosphereMonitoring',
  data() {
    return {
      showLongitude: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监测设备表格数据
      AtmosphereMonitoringList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openSee: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fineParticle: null,
        suctionParticle: null,
        sulfurDioxide: null,
        nitrogenDioxide: null,
        ozone: null,
        carbonMonoxide: null,
        tvoc: null,
        tsp: null,
        temperature: null,
        humidity: null,
        windSpeed: null,
        windDirection: null,
        id: null,
        deviceType: null,
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList();
  },
  props: {
    deviceCode: '',
    deviceType: "",
  },
  methods: {
    /** 查询监测设备列表 */
    getList() {
      this.loading = true
      this.queryParams.deviceCode=this.deviceCode
      selectAtmosphereMonitoringData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.AtmosphereMonitoringList = 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;
      getAtmosphere(id).then(response => {
        this.form = response.data;
        this.openSee = true;
        this.title = "详情";
      });
    },
    // 表单重置
    reset() {
      this.form = {
        fineParticle: null,
        suctionParticle: null,
        sulfurDioxide: null,
        nitrogenDioxide: null,
        ozone: null,
        carbonMonoxide: null,
        tvoc: null,
        tsp: null,
        temperature: null,
        humidity: null,
        windSpeed: null,
        windDirection: null,
        id: null,
        deviceType: 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>
