<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="状态名称">
        <el-select
          v-model="queryParams.cageSection"
          style="width: 240px"
          placeholder="请选择状态名称"
          clearable
        >
          <el-option
            v-for="item in deviceName"
            :key="item.id"
            :label="item.cageSection"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <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-divider content-position="left">运行实时状态</el-divider>
    <el-table
      :data="dataList"
      style="width: 100%"
      border
      size="mini"
      :row-key="getRowKey"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="序号" type="index" width="55" align="center" />
      <el-table-column label="状态名称" align="center" prop="mainSpeed" />
      <el-table-column label="状态" align="center" prop="coderSpeed" />
      <el-table-column label="时间" align="center" prop="slaveSpeed" />
    </el-table>
  </div>
</template>

<script>
import { queryHoistHisData, listHoistSelectData } from "@/api/tyler/hoistSys";

export default {
  name: "Data",
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提升机历史数据表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cageSection: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [{ required: true, message: "$comment不能为空", trigger: "blur" }],
        cageSection: [
          { required: true, message: "罐笼所在中段不能为空", trigger: "blur" },
        ],
      },
      deviceName: [],
      dateRange: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询提升机历史数据列表 */
    getList() {
      this.loading = true;
      queryHoistHisData(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        this.dataList = [];
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        cageSection: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
