<template>
  <div style="pointer-events: all">
    <!-- <InfoHeader name="电梯实时数据" eName="Elevator basic information"></InfoHeader> -->
    <!-- <InfoContent height="10rem"> -->
    <div
      v-loading="loading"
      element-loading-spinner="el-icon-loading"
      element-loading-text="正在刷新电梯数据"
      element-loading-background="rgba(0, 0, 0, 0.1)"
      style="background: rgb(6, 15, 48); padding-bottom: 0.15rem"
    >
      <div class="d-flex data-box">
        <div
          class="menu-item fs-24 font-weight-br d-flex a-c jc-center"
          :style="{ color: currentIndex === index ? 'white' : '' }"
          v-for="(item, index) in menuList"
          :key="index"
          @click="handleClickTab(index)"
        >
          {{ item.name }}
        </div>
      </div>
      <block v-if="currentIndex === 0">
        <div class="ele-list d-flex flex-wrap jc-space-between">
          <block v-for="(item, index) in eleList" :key="index">
            <ElevatorItem :eleInfo="item"></ElevatorItem>
          </block>
        </div>
        <div class="d-flex flex-end mt-3 pl-3">
          <el-pagination
            background
            :current-page="currentPage"
            layout="total,prev, pager, next"
            :total="elevatorNumList.length"
            @current-change="handlePagigationChange"
          >
          </el-pagination>
        </div>
      </block>
      <block v-else>
        <div class="video-list d-flex flex-wrap jc-space-between">
          <div
            class="video-item"
            v-for="(item, index) in videoList"
            :key="index"
          >
            <div class="d-flex jc-center video-name c-white fs-16">
              {{ item.name }}
            </div>
            <div class="d-flex a-c jc-center">
              <video
                src="https://openstatic.ys7.com/ezuikit_js/v2.0.2/ezuikit_static/PlayCtrlWasm/playCtrl3/noWorker/Decoder.wasm"
                style="width: 5.5rem; height: 3rem"
                controls
              ></video>
            </div>
          </div>
        </div>
      </block>
    </div>

    <!-- </InfoContent> -->
  </div>
</template>

<script>
// import InfoHeader from "@/components/infoHeader";
// import InfoContent from "@/components/infoContent";
import { fillArray } from "../../utils";
import ElevatorItem from "./components/elevatorItem.vue";
import { getElevatorBehaviorList } from "@/api/elevator";
export default {
  components: {
    // InfoHeader,
    // InfoContent,
    ElevatorItem,
  },
  data() {
    return {
      currentIndex: 0,
      loading: false,
      currentPage: 1,
      videoList: [
        {
          name: "鳳凰苑",
          url: "",
        },
        {
          name: "鳳凰苑",
          url: "",
        },
        {
          name: "鳳凰苑",
          url: "",
        },
        {
          name: "鳳凰苑",
          url: "",
        },
      ],
      eleList: [
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
        {
          name: "众博科技办公楼电梯",
          floor: 2,
          status: 1,
          level: 3,
        },
      ],
      menuList: [
        {
          name: "实时运行",
        },
        { name: "实时监控" },
      ],
      tableData: [
        {
          date: "凤凰园A1",
          name: "光电谷科创中心-凤凰园A1",
          address: "光电谷科创中心",
        },
      ],
      elevatorNumList: [],
      interval: null,
    };
  },
  beforeDestroy() {
    clearInterval(this.interval);
    this.interval = null;
  },
  destroyed() {
    clearInterval(this.interval);
    this.interval = null;
  },
  created() {
    this.$EventBus.$on("elevatorNumList", (elevatorNumList) => {
      // A发送来的消息
      // clearInterval(this.interval);
      // this.interval = null;
      this.elevatorNumList = JSON.parse(elevatorNumList);
      console.log(this.elevatorNumList, "elevatorNumList");
      this.currentPage = 1;
      this.getElevatorBehaviorListApi(this.elevatorNumList.slice(0, 8));
      // this.interval = setInterval(() => {
      //   this.getElevatorBehaviorListApi(this.elevatorNumList.slice(0, 8));
      // }, 12000);
    });
  },
  methods: {
    handleClickTab(index) {
      this.currentIndex = index;
    },
    handlePagigationChange(e) {
      console.log(e);
      this.currentPage = e;
      const list = this.elevatorNumList.slice((e - 1) * 8, e * 8);
      // clearInterval(this.interval);
      // this.interval = null;
      this.getElevatorBehaviorListApi(list);
      // this.interval = setInterval(() => {
      //   this.getElevatorBehaviorListApi(list);
      // }, 12000);
    },
    async getElevatorBehaviorListApi(list) {
      this.loading = true;
      const res = await getElevatorBehaviorList({
        elevatorNumList: list.join(","),
        largeScreenFlag: true,
      });
      this.eleList = res.rows;
      if (this.eleList.length < 8) {
        fillArray(this.eleList, 8, {
          elevatorName: "楼梯",
          floor: "1",
          runStatus: 255,
          doorStatus: 255,
        });
      } else {
        this.eleList = res.rows.slice(0, 8);
      }
      this.loading = false;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-pagination span:not([class*="suffix"]) {
  color: white;
}
::v-deep .el-pagination.is-background .btn-prev {
  background: rgba(1, 13, 56, 0.9);
  border: solid 1px #409eff;
  color: white;
}
::v-deep .el-pagination.is-background .btn-prev:disabled {
  background: rgba(1, 13, 56, 0.9);
  border: solid 1px #409eff;
  color: white;
}
::v-deep .el-pagination.is-background .btn-next {
  background: rgba(1, 13, 56, 0.9);
  border: solid 1px #409eff;
  color: white;
}
::v-deep .el-pagination.is-background .el-pager li {
  background: rgba(1, 13, 56, 0.9);
  border: solid 1px #409eff;
  color: white;
}
::v-deep
  .el-table--enable-row-hover
  .el-table__body
  tr:hover
  > td.el-table__cell {
  background: rgba(1, 13, 56, 0.9) !important;
}
::v-deep .el-table__cell {
  background-color: #10295f;
  color: white;
  border-bottom: none !important;
}
/* 针对特定元素的滚动条 */
.info-list::-webkit-scrollbar {
  width: 0px;
  height: 0px;
}
.video-list {
  padding: 0.3rem;
  padding-top: 0rem;

  .video-item {
    margin-right: 0.1rem;
    margin-top: 0.1rem;
    .video-name {
      padding: 0.1rem 0;
      background: linear-gradient(
        to right,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0) 10%,
        rgba(9, 94, 163, 0.3) 20%,
        rgba(9, 94, 163, 0.4) 30%,
        rgba(9, 94, 163, 0.5) 40%,
        rgba(9, 94, 163, 0.8) 50%,
        rgba(9, 94, 163, 0.5) 60%,
        rgba(9, 94, 163, 0.4) 70%,
        rgba(9, 94, 163, 0.3) 80%,
        rgba(0, 0, 0, 0) 90%,
        rgba(0, 0, 0, 0) 100%
      );
    }
    background: url("../../assets/images/elevator-monitor.png");
    background-repeat: no-repeat;
    width: 6.5rem;
    height: 3.475rem;
  }
}
.ele-list {
  padding: 0.3rem;
  padding-top: 0rem;

  margin: 0.2rem;

  border: solid 1px #0b69bb;
  border-radius: 0.1rem;
}
.data-box {
  width: 90%;
  margin: auto;
  .menu-item {
    margin-right: 0.4rem;
    // background: url("../../assets/images/home_page_06.png");
    background: rgb(35, 50, 107);
    border: solid 1px rgb(189, 189, 240);
    background-size: cover;
    width: 1.65rem;
    height: 0.9rem;
    cursor: pointer;
    color: #afafaf;
    &:hover {
      color: white;
    }
  }
}
</style>
