<template>
  <div id="elevator">
    <div class="side-area">
      <Title text="设备列表"></Title>
      <ShadowContainer>
        <div id="elevator-description">
          <div
            :class="['elevator', activeElevatorIndex == index ? 'active' : '']"
            v-for="(elevator, index) in elevatorList"
            :key="index"
            @click="selectElevator(elevator, index)"
          >
            <div class="elevator-title" @click="showElevatorStatus(elevator)">
              <img src="@/assets/elevator/icon_elevator.png" alt="" />
              {{ elevator.name }}
              <span class="status">
                <span
                  v-if="elevator.left_elevator"
                  :style="{
                    color:
                      elevator.left_elevator.is_online == 1 ? '#26D591' : '',
                  }"
                >
                  (左){{ elevator.left_elevator.is_online_text }}
                </span>
                <span v-if="elevator.left_elevator && elevator.right_elevator">
                  /
                </span>
                <span
                  v-if="elevator.right_elevator"
                  :style="{
                    color:
                      elevator.right_elevator.is_online == 1 ? '#26D591' : '',
                  }"
                >
                  (右){{ elevator.right_elevator.is_online_text }}
                </span>
              </span>
            </div>
          </div>
        </div>
      </ShadowContainer>
      <Title text="报警信息"></Title>
      <ShadowContainer>
        <div id="warning-info">
          <div>
            <div class="warning-info-text">今日报警</div>
            <div class="warning-info-num">
              {{ elevatorWarningStatus.today_num }}
            </div>
            <div class="warning-info-img">
              <img src="@/assets/fallprotection/today.png" alt="" />
            </div>
          </div>
          <div>
            <div class="warning-info-text">累计未处理报警</div>
            <div class="warning-info-num" style="color: #ffc74c">
              {{ elevatorWarningStatus.un_handle_num }}
            </div>
            <div class="warning-info-img">
              <img src="@/assets/fallprotection/total-no.png" alt="" />
            </div>
          </div>
          <div>
            <div class="warning-info-text">累计履责率</div>
            <div class="warning-info-num" style="color: #22c3ed">
              {{ elevatorWarningStatus.handle_rate
              }}<span style="font-size: 14px; margin-left: 12px">%</span>
            </div>
            <div class="warning-info-img">
              <img src="@/assets/fallprotection/percent.png" alt="" />
            </div>
          </div>
        </div>
        <div class="warning-table">
          <div class="warning-table-header">
            <div class="warning-table-time">报警时间</div>
            <div class="warning-table-device">设备</div>
            <div class="warning-table-message">报警信息</div>
            <div class="warning-table-status">处理状态</div>
          </div>
          <div class="warning-table-list" v-infinite-scroll="load">
            <div
              class="warning-table-column"
              v-for="(column, index) in elevatorWarningList"
              :key="index"
            >
              <div class="warning-table-time">{{ column.log_time }}</div>
              <div class="warning-table-device"></div>
              <div class="warning-table-message">
                {{ column.alarm_content }}
              </div>
              <div
                class="warning-table-status"
                :style="{ color: column.status == 1 ? '#FFC74C' : '' }"
              >
                {{ column.status_text }}
              </div>
            </div>
          </div>
        </div>
      </ShadowContainer>
    </div>
    <div class="elevator-container">
      <ShadowContainer>
        <div style="height: 980px" id="elevator-detail">
          <div class="left-detail">
            <template
              v-if="
                leftElevator &&
                leftElevator.current_person &&
                leftElevator.realtime_data &&
                leftElevator.device_info
              "
            >
              <div class="tower-title">左侧运行情况</div>
              <div class="driver-info">
                <div class="driver-icon">
                  <img :src="leftElevator.current_person.head_img" alt="" />
                </div>
                <div class="driver-description">
                  <div class="t-des">
                    姓名：{{ leftElevator.current_person.name }}
                  </div>
                  <div class="t-des">
                    身份证号：{{ leftElevator.current_person.id_card }}
                  </div>
                  <div class="t-des">
                    上机时间：{{ leftElevator.current_person.start_time }}
                  </div>
                </div>
              </div>
              <div class="current-status">
                <div class="t-des">
                  高度：{{ leftElevator.realtime_data.height }}m
                </div>
                <div class="t-des">
                  载重：{{ leftElevator.realtime_data.weight }}t
                </div>
                <div class="t-des">
                  运行速度：{{ leftElevator.realtime_data.speed }}m/s
                </div>
                <div class="t-des">
                  倾角X轴：{{ leftElevator.realtime_data.tilt_x }}°
                </div>
                <div class="t-des">
                  倾角Y轴：{{ leftElevator.realtime_data.tilt_y }}°
                </div>

                <div class="t-des">
                  前面：{{
                    leftElevator.realtime_data.switch_front_status_text
                  }}
                </div>
                <div class="t-des">
                  后面：{{ leftElevator.realtime_data.switch_back_status_text }}
                </div>
                <div class="t-des">
                  更新时间：{{ leftElevator.realtime_data.latest_record_time }}
                </div>
              </div>
              <div class="tower-title">设备信息</div>
              <div class="device-info">
                <div class="t-des">
                  设备名称：{{ leftElevator.device_info.device_name }}
                </div>
                <div class="t-des">
                  设备编号：{{ leftElevator.device_info.device_no }}
                </div>
                <div class="t-des">
                  设备型号：{{ leftElevator.device_info.model }}
                </div>
                <div class="t-des">
                  生产厂家：{{ leftElevator.device_info.produce_name }}
                </div>
              </div>
            </template>
          </div>
          <div class="elevator-tower">
            <div id="tower-main">
              <div
                v-if="leftElevator && leftElevator.realtime_data"
                class="left-elevator"
                :style="{
                  bottom: `${
                    (leftElevator.realtime_data.height /
                      currentElevatorTower.height) *
                    100
                  }%`,
                }"
              >
                <div class="online-status" v-if="leftElevator.device_info">
                  {{ leftElevator.device_info.is_online_text }}
                </div>
                <div>
                  <img
                    class="elevator"
                    src="@/assets/elevator/ele-left.png"
                    alt=""
                  />
                </div>
              </div>
              <img class="tower" src="@/assets/elevator/tower.png" alt="" />
              <div
                v-if="rightElevator && rightElevator.realtime_data"
                class="right-elevator"
                :style="{
                  bottom: `${
                    (rightElevator.realtime_data.height /
                      currentElevatorTower.height) *
                    100
                  }%`,
                }"
              >
                <div>
                  <div class="online-status" v-if="rightElevator.device_info">
                    {{ rightElevator.device_info.is_online_text }}
                  </div>
                  <img
                    class="elevator"
                    src="@/assets/elevator/ele-right.png"
                    alt=""
                  />
                </div>
              </div>
            </div>
            <div>
              <img class="bottom" src="@/assets/elevator/bottom.png" alt="" />
            </div>
          </div>
          <div class="right-detail">
            <template
              v-if="
                rightElevator &&
                rightElevator.current_person &&
                rightElevator.realtime_data &&
                rightElevator.device_info
              "
            >
              <div class="tower-title">右侧运行情况</div>
              <div class="driver-info">
                <div class="driver-icon">
                  <img :src="rightElevator.current_person.head_img" alt="" />
                </div>
                <div class="driver-description">
                  <div class="t-des">
                    姓名：{{ rightElevator.current_person.name }}
                  </div>
                  <div class="t-des">
                    身份证号：{{ rightElevator.current_person.id_card }}
                  </div>
                  <div class="t-des">
                    上机时间：{{ rightElevator.current_person.start_time }}
                  </div>
                </div>
              </div>
              <div class="current-status">
                <div class="t-des">
                  高度：{{ rightElevator.realtime_data.height }}m
                </div>
                <div class="t-des">
                  载重：{{ rightElevator.realtime_data.weight }}t
                </div>
                <div class="t-des">
                  运行速度：{{ rightElevator.realtime_data.speed }}m/s
                </div>
                <div class="t-des">
                  倾角X轴：{{ rightElevator.realtime_data.tilt_x }}°
                </div>
                <div class="t-des">
                  倾角Y轴：{{ rightElevator.realtime_data.tilt_y }}°
                </div>

                <div class="t-des">
                  前面：{{
                    rightElevator.realtime_data.switch_front_status_text
                  }}
                </div>
                <div class="t-des">
                  后面：{{
                    rightElevator.realtime_data.switch_back_status_text
                  }}
                </div>
                <div class="t-des">
                  更新时间：{{ rightElevator.realtime_data.latest_record_time }}
                </div>
              </div>
              <div class="tower-title">设备信息</div>
              <div class="device-info">
                <div class="t-des">
                  设备名称：{{ rightElevator.device_info.device_name }}
                </div>
                <div class="t-des">
                  设备编号：{{ rightElevator.device_info.device_no }}
                </div>
                <div class="t-des">
                  设备型号：{{ rightElevator.device_info.model }}
                </div>
                <div class="t-des">
                  生产厂家：{{ rightElevator.device_info.produce_name }}
                </div>
              </div>
            </template>
          </div>
        </div>
      </ShadowContainer>
    </div>
  </div>
</template>
<script>
import {
  getElevatorList,
  getElevatorWarningList,
  getElevatorWarningStatus,
  getElevatorRealData,
} from "@/api/index";
export default {
  name: "Elevator",
  data() {
    return {
      elevatorList: [],
      page: 1,
      elevatorWarningList: [],
      elevatorWarningStatus: {
        today_num: 0,
        un_handle_num: 0,
        handle_rate: 0,
      },
      activeElevatorIndex: 0,
      leftElevator: {},
      rightElevator: {},
      currentElevatorTower: {},
    };
  },
  methods: {
    load() {
      if (this.elevatorWarningList.length == this.page * 20) {
        getElevatorWarningList({
          page: this.page + 1,
          limit: 20,
        }).then((res) => {
          this.page += 1;
          this.getElevatorWarningList += res.data.data;
        });
      }
    },
    getCurrentElevatorStatus(tower) {
      const elevatorArray = [];
      if (tower.left_elevator) {
        elevatorArray.push(tower.left_elevator.id);
      }
      if (tower.right_elevator) {
        elevatorArray.push(tower.right_elevator.id);
      }
      getElevatorRealData({ device_ids: elevatorArray.join(",") }).then(
        (res) => {
          console.log(res);
          this.leftElevator = res.data.filter((item) => {
            return item.device_id == tower.left_elevator.id;
          })[0];
          this.rightElevator = res.data.filter((item) => {
            return item.device_id == tower.right_elevator.id;
          })[0];
          console.log(this.leftElevator, "left");
          console.log(this.rightElevator, "right");
        }
      );
    },
    selectElevator(elevator, index) {
      this.activeElevatorIndex = index;
      this.getCurrentElevatorStatus(elevator);
    },
  },
  mounted() {
    getElevatorList().then((res) => {
      this.elevatorList = res.data;
      this.currentElevatorTower = res.data[0];
      this.getCurrentElevatorStatus(this.currentElevatorTower);
    });
    getElevatorWarningList({ page: 1, limit: 20 }).then((res) => {
      this.elevatorWarningList = res.data.data;
    });
    getElevatorWarningStatus().then((res) => {
      this.elevatorWarningStatus = res.data;
    });
  },
};
</script>
<style lang="less" scoped>
#elevator {
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
}
.side-area {
  width: 25%;
}

#elevator-description {
  height: 340px;
  overflow-y: scroll;
  .elevator {
    background: rgba(44, 96, 162, 0.2);
    &.active {
      background: rgba(44, 96, 162, 0.5);
    }
    &:hover {
      background: rgba(44, 96, 162, 0.5);
    }
  }
  .elevator-title {
    line-height: 22px;
    img {
      width: 22px;
      vertical-align: top;
    }

    font-size: 14px;
    color: #c6def9;
    padding: 10px 12px;
    cursor: pointer;
    .status {
      float: right;
    }
  }
  .elevator-info {
    line-height: 22px;

    img {
      width: 22px;
      vertical-align: top;
    }
    background: rgba(44, 96, 162, 0.1);
    font-size: 14px;
    color: #c6def9;
    padding: 10px 12px;
    border-top: 1px solid rgba(122, 143, 173, 0.2);
    cursor: pointer;
    span {
      float: right;
    }
  }
}
.elevator-container {
  width: calc(75% - 20px);
}
.platform {
  img {
    width: 20px;
    vertical-align: middle;
    margin-right: 6px;
  }
  font-size: 14px;
  color: #c6def9;
  .platform-title {
    background: rgba(44, 96, 162, 0.2);
    border-bottom: 1px solid rgba(122, 143, 173, 0.4);
    line-height: 40px;
    padding: 0 12px;
    .status {
      float: right;
    }
  }
  .platform-info {
    background: rgba(44, 96, 162, 0.1);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    & > div {
      width: calc(50% - 48px);
      padding: 6px 12px;
    }
  }
  &:hover {
    color: #27acfb;
    .platform-title,
    .platform-info {
      background: rgba(44, 96, 162, 0.4);
    }
  }
}
#warning-info {
  display: flex;
  justify-content: space-between;
  text-align: center;
  .warning-info-text {
    padding-top: 20px;
    font-size: 16px;
    color: #ffffff;
    line-height: 18px;
  }
  .warning-info-num {
    font-size: 24px;
    color: #ff6151;
  }
  .warning-info-img {
    position: relative;
    transform: translateY(-60px);
    margin-bottom: -60px;
    img {
      width: 80%;
      margin: 0 auto;
    }
  }
}

.overflowed {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.warning-table {
  font-size: 14px;
  text-align: center;
  color: #c6def9;
  .warning-table-list {
    height: 280px;
    overflow-y: auto;
  }
  .warning-table-header {
    background: rgba(44, 96, 162, 0.2);
    display: flex;
    padding: 12px 0;
  }
  .warning-table-column {
    padding: 12px 0;
    background: rgba(44, 96, 162, 0.05);
    display: flex;
    &:nth-child(2n) {
      background: rgba(44, 96, 162, 0.1);
    }
  }
  .warning-table-time {
    width: 40%;
  }
  .warning-table-device,
  .warning-table-message,
  .warning-table-status {
    width: 20%;
  }
}
#elevator-detail {
  display: flex;
  justify-content: space-between;
  .left-detail,
  .right-detail {
    width: 30%;
  }
  .elevator-tower {
    width: 40%;
  }
  .elevator-tower {
    text-align: center;
    #tower-main {
      display: inline-block;
      position: relative;

      .left-elevator {
        position: absolute;
        left: 0;
        transform: translateX(-100%);
        bottom: 0%;
        .online-status {
          font-size: 18px;
          color: #c6def9;
          text-align: right;
          padding-right: 24px;
        }
      }
      .right-elevator {
        position: absolute;
        right: 0;
        transform: translateX(100%);
        bottom: 0%;
        .online-status {
          font-size: 18px;
          color: #c6def9;
          text-align: left;
          padding-left: 24px;
        }
      }
      .elevator {
        width: 124px;
      }
    }
    img {
      vertical-align: top;
    }
    .bottom {
      height: 10px;
    }
    .tower {
      height: 970px;
    }
  }
  .driver-info {
    display: flex;
    justify-content: space-between;
    .driver-icon {
      width: 100px;
      border: 1px solid #0f6996;
      img {
        width: 100%;
        height: 100%;
        vertical-align: top;
      }
    }
    .driver-description {
      width: calc(100% - 110px);
    }
  }
  .tower-title {
    text-align: center;
    margin-bottom: 16px;
    background: linear-gradient(
      90deg,
      rgba(39, 172, 251, 0.4) 0%,
      rgba(39, 172, 251, 0.15) 50%,
      rgba(39, 172, 251, 0.4) 100%
    );
    border-top: 1px solid
      linear-gradient(
        90deg,
        rgba(34, 195, 237, 0.79) 1%,
        rgba(34, 195, 237, 0.81) 100%
      );
    border-bottom: 1px solid
      linear-gradient(
        90deg,
        rgba(34, 195, 237, 0.79) 1%,
        rgba(34, 195, 237, 0.81) 100%
      );
    font-size: 18px;
    color: #ffffff;
    line-height: 40px;
  }
  .t-des {
    background: linear-gradient(
      90deg,
      rgba(39, 172, 251, 0.1) 0%,
      rgba(39, 172, 251, 0) 50%,
      rgba(39, 172, 251, 0.1) 100%
    );
    line-height: 40px;
    color: #c6def9;
    font-size: 14px;
    padding: 0 30px;
    margin-bottom: 2px;
    &:last-child {
      margin-bottom: 0;
    }
  }
  .current-status {
    margin: 10px 0 20px 0;
  }
}
</style>