<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="fanName">
        <el-select v-model="queryParams.fanName" placeholder="风机名称" clearable>
          <el-option
            v-for="dict in fanName"
            :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="infoList" >
      <el-table-column label="风机名称" align="center" prop="fanName"/>
      <el-table-column label="风机编号" align="center" prop="deviceId"/>
      <el-table-column label="操作类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fan_run_status" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status"></el-table-column>
      <el-table-column label="操作时间" align="center" prop="time"/>
    </el-table>

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

    
  </div>
</template>

<script>
  import { listFanSwitchHis } from "@/api/tyler/fan";
  import { fanDeviceName } from "@/api/tyler/common";

  export default {
  name: "Info",
  dicts: ['fan_run_status'],
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 风机基本信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fanName: null,
        deviceId: null,
    
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
        fanName: [
          { required: true, message: "风机名称不能为空", trigger: "blur" }
        ],
        deviceId: [
          { required: true, message: "风机编号不能为空", trigger: "blur" }
        ],
      },
      fanName:[],
      dateRange:[],
    };
  },
  created() {
    fanDeviceName().then(res=>{
      this.fanName = res.data;
    })
    this.getList();
  },
  methods: {
    /** 查询风机基本信息列表 */
    getList() {
      this.loading = true;
      listFanSwitchHis(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fanName: null,
        deviceId: null,
        installationLocation: null,
        powerSupplyVoltage: null,
        motorCurrent: null,
        operatingFrequency: null,
        setFrequency: null,
        windPressure: null,
        windSpeed: null,
        airVolume: null,
        frontAxisTemperature: null,
        rearAxisTemperature: null,
        motorTemperature: null,
        frontVibration: null,
        rearVibration: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
 
    
  
  }
};
</script>
