<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-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="dataList">
      <el-table-column label="主控速度m/s" align="center" prop="mainSpeed" />
      <el-table-column label="编码器速度m/s" align="center" prop="coderSpeed" />
      <el-table-column label="给定速度m/s" align="center" prop="givenSpeed" />
      <el-table-column
        label="从编码器速度m/s"
        align="center"
        prop="slaveSpeed"
      />
      <el-table-column label="主罐位置m" align="center" prop="position" />
      <el-table-column
        label="位置偏差m"
        align="center"
        prop="locationDeviation"
      />
      <el-table-column label="电枢电流A" align="center" prop="motorCurrent" />
      <el-table-column
        label="磁场电流A"
        align="center"
        prop="runningPressure"
      />
      <el-table-column
        label="运行油压MPa"
        align="center"
        prop="controlPosition"
      />
      <!-- <el-table-column label="当前动作" align="center" prop="currentAction">
        <template slot-scope="scope">
          <span>{{
            ["去井口", "去一中", "去二中", "去三中", "去四中", "去五中"][
              scope.row.currentAction
            ]
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="运行准备" align="center" prop="runPrepare">
        <template slot-scope="scope">
          <span v-if="scope.row.runPrepare != null">{{
            scope.row.runPrepare == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="主风机启动" align="center" prop="mainFan">
        <template slot-scope="scope">
          <span v-if="scope.row.mainFan != null">{{
            scope.row.mainFan == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="交流器启动" align="center" prop="transformer">
        <template slot-scope="scope">
          <span v-if="scope.row.transformer != null">{{
            scope.row.transformer == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column
        label="液压站启动"
        align="center"
        prop="hydraulicStation"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.hydraulicStation == null">--</span>
          <span v-else>{{
            scope.row.hydraulicStation == "0" ? "否" : "是"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="硬件安全" align="center" prop="hardwareSecurity">
        <template slot-scope="scope">
          <span v-if="scope.row.hardwareSecurity != null">{{
            scope.row.hardwareSecurity == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="软件安全" align="center" prop="softwareSecurity">
        <template slot-scope="scope">
          <span v-if="scope.row.softwareSecurity != null">{{
            scope.row.softwareSecurity == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="操作台安全" align="center" prop="consoleSafety">
        <template slot-scope="scope">
          <span v-if="scope.row.consoleSafety != null">{{
            scope.row.consoleSafety == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="轻故障" align="center" prop="minorMalfunction">
        <template slot-scope="scope">
          <span v-if="scope.row.minorMalfunction != null">{{
            scope.row.minorMalfunction == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="井口信号" align="center" prop="wellheadSignal">
        <template slot-scope="scope">
          <span v-if="scope.row.wellheadSignal != null">{{
            scope.row.wellheadSignal == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="信号继电器" align="center" prop="signalRelay">
        <template slot-scope="scope">
          <span v-if="scope.row.signalRelay != null">{{
            scope.row.signalRelay == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="选择正向" align="center" prop="chooseForward">
        <template slot-scope="scope">
          <span v-if="scope.row.chooseForward != null">{{
            scope.row.chooseForward == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="选择反向" align="center" prop="chooseReverse">
        <template slot-scope="scope">
          <span v-if="scope.row.chooseReverse != null">{{
            scope.row.chooseReverse == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="手动闸" align="center" prop="manualGate">
        <template slot-scope="scope">
          <span v-if="scope.row.manualGate != null">{{
            scope.row.manualGate == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="工作闸" align="center" prop="workGate">
        <template slot-scope="scope">
          <span v-if="scope.row.workGate != null">{{
            scope.row.workGate == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="全敞闸" align="center" prop="openGate">
        <template slot-scope="scope">
          <span v-if="scope.row.openGate != null">{{
            scope.row.openGate == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="一级制动" align="center" prop="firstBraking">
        <template slot-scope="scope">
          <span v-if="scope.row.firstBraking != null">{{
            scope.row.firstBraking == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="选低速" align="center" prop="lowSpeed">
        <template slot-scope="scope">
          <span v-if="scope.row.lowSpeed != null">{{
            scope.row.lowSpeed == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="使能输出" align="center" prop="enableOutput">
        <template slot-scope="scope">
          <span v-if="scope.row.enableOutput != null">{{
            scope.row.enableOutput == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="装置解封" align="center" prop="deviceUnsealed">
        <template slot-scope="scope">
          <span v-if="scope.row.deviceUnsealed != null">{{
            scope.row.deviceUnsealed == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="系统减速" align="center" prop="systemSlowdown">
        <template slot-scope="scope">
          <span v-if="scope.row.systemSlowdown != null">{{
            scope.row.systemSlowdown == "0" ? "否" : "是"
          }}</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
       -->
      <el-table-column
        fixed="right"
        label="记录时间"
        align="center"
        prop="recordedAt"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordedAt) }}</span>
        </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 { 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 = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    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>
