<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="14">
        <el-divider content-position="left">运行实时数据</el-divider>
        <el-table :data="dataListLeft" style="width: 100%" border size="mini">
          <el-table-column
            label="序号"
            type="index"
            width="55"
            align="center"
          />
          <el-table-column label="运行数据项" align="center" prop="comment" />
          <el-table-column label="值" align="center" prop="value">
            <template slot-scope="scope">
              <span v-if="scope.row.comment == '当前动作'">
                <span v-if="scope.row.value">{{
                  ["去井口", "去一中", "去二中", "去三中", "去四中", "去五中"][
                    scope.row.value
                  ]
                }}</span
                ><span v-else>待命</span>
              </span>
              <span v-else>
                {{ scope.row.value }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="单位" align="center" prop="unit" />
          <el-table-column label="时间" align="center" prop="recordedAt" />
        </el-table>
      </el-col>
      <el-col :span="10">
        <el-divider content-position="left">运行实时状态</el-divider>
        <el-table :data="dataListRight" style="width: 100%" border size="mini">
          <el-table-column
            label="序号"
            type="index"
            width="55"
            align="center"
          />
          <el-table-column label="状态名称" align="center" prop="comment" />
          <el-table-column label="状态" align="center" prop="value">
            <template slot-scope="scope">
              <el-tag :type="scope.row.value == '1' ? 'success' : 'danger'">
                {{ scope.row.value == "1" ? "开" : "关" }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column label="时间" align="center" prop="recordedAt" />
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getDraData, getRunStatusData } from "@/api/tyler/realtimeDataodHoist";

export default {
  name: "Data",
  data() {
    return {
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提升机实时数据
      dataListLeft: [],
      // 提升机状态表格数据
      dataListRight: [],
      // 弹出层标题
      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;
      getDraData(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.dataListLeft = response.rows;
        }
      );
      getRunStatusData(
        this.addDateRange(this.queryParams, this.dateRange)
      ).then((response) => {
        this.dataListRight = response.rows;
      });
    },
  },
  mounted() {
    this.getList();
  },
};
</script>
