<template>
  <div class="elevator-status">
    <InfoHeader name="电梯现行状态" eName="Current status of elevator"></InfoHeader>
    <InfoContent height="auto">
      <div class="status-content">
        <div class="elevator-visual">
          <div class="elevator-box">
            <img src="../../../assets/images/elevator_run_close.png" alt="" />
          </div>
          <div class="control-btns">
            <div class="btn" :class="{active: runInfo.runState == 17}">
              <img src="../../../assets/images/elevator_btn_up.png" alt="" />
            </div>
            <div class="floor-num">{{runInfo.floor || ""}}</div>
            <div class="btn" :class="{active: runInfo.runState == 18}">
              <img src="../../../assets/images/elevator_btn_down.png" alt="" />
            </div>
          </div>
        </div>
        <div class="status-info">
          <div class="info-grid">
            <div class="info-item" v-for="(item, index) in statusList" :key="index">
              <div class="item-label">{{item.label}}</div>
              <div class="item-value">{{item.value}}</div>
            </div>
          </div>
        </div>
      </div>
    </InfoContent>
  </div>
</template>

<script>
import InfoHeader from "@/components/infoHeader";
import InfoContent from "@/components/infoContent";
import { getWorkElevatorRunData, getVideoUrl } from "@/api/elevator";
export default {
  components: {
    InfoHeader,
    InfoContent,
  },

  data() {
    return {
      value1: 3,
      elevatorNum: "",

      runInfo: {},
      runStateMap: {
        0: "停梯",
        17: "上行",
        18: "下行",
        33: "上行到停梯",
        34: "下行到停梯",
        255: "未知",
        "": "未知",
      },
      doorStateMap: {
        0: "开门到位",
        1: "关门到位",
        2: "开门过程中",
        3: "关门过程中",
        255: "未知",
        "": "未知",
      },
    };
  },
  computed: {
    statusList() {
      return [
        { label: '事件编号', value: this.runInfo.type },
        { label: '平层状态', value: this.runInfo.levelStatus === 1 ? "平层" : "非平层" },
        { label: '行梯状态', value: this.runInfo.runState ? this.doorStateMap[this.runInfo.runState] : "未知" },
        { label: '门开关状态', value: this.runInfo.doorState ? this.doorStateMap[this.runInfo.doorState] : "未知" },
        { label: '当前显示楼层', value: this.runInfo.floor || "未知" },
        { label: '前后振幅峰值(mg)', value: this.runInfo.frontAndRearAmplitude || "" },
        { label: '左右振幅峰值(mg)', value: this.runInfo.leftAndRightAmplitude || "" },
        { label: '冲顶/下蹲状态', value: this.runInfo.headUpSquattingState },
        { label: '当前速度(cm/s)', value: this.runInfo.speed || "" },
        { label: '本次行梯距离(cm)', value: this.runInfo.currRunDis || "" },
        { label: '上行总距离(cm)', value: this.runInfo.upRunDis || "" },
        { label: '下行总距离(cm)', value: this.runInfo.downRunDis || "" }
      ]
    }
  },
  created() {
    console.log(this.$route.query);
    if (this.$route.query) {
      this.elevatorNum = this.$route.query.elevatorNum;
      this.getWorkElevatorRunDataApi();
    }
  },
  methods: {
    handlVideo() {
      getVideoUrl(this.elevatorNum).then((res) => {
        if (res.data) {
          window.open(res.data);
        }
      });
    },
    getWorkElevatorRunDataApi() {
      getWorkElevatorRunData(this.elevatorNum).then((res) => {
        this.runInfo = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.elevator-status {
  margin-bottom: 0.3rem;

  .status-content {
    padding: 0.3rem;

    .elevator-visual {
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 0.3rem;

      .elevator-box {
        position: relative;
        width: 2rem;
        margin-right: 0.5rem;

        img {
          width: 100%;
        }
      }

      .control-btns {
        .btn {
          margin: 0.2rem 0;
          opacity: 0.5;
          transition: all 0.3s;

          &.active {
            opacity: 1;
          }

          img {
            width: 0.6rem;
          }
        }

        .floor-num {
          color: #fff;
          font-size: .5rem;
          text-align: center;
        }
      }
    }

    .status-info {
      .info-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.2rem;

        .info-item {
          background: rgba(16, 41, 95, 0.8);
          padding: 0.2rem;
          border-radius: 0.1rem;

          .item-label {
            color: rgba(255,255,255,0.8);
            font-size: 0.24rem;
            margin-bottom: 0.1rem;
          }

          .item-value {
            color: #02dff6;
            font-size: 0.26rem;
          }
        }
      }
    }
  }
}
</style>