<template>
  <div class="wrapper rightPic">
    <div class="math">
      <div>
        <span :title="rightPicData.alarmNum" class="ddd">{{ rightPicData.alarmNum }}</span>
        <i>报警总数</i>
      </div>
      <div>
        <span :title="rightPicData.onlineNum" class="ddd">{{ rightPicData.onlineNum }}</span>
        <i>在线设备</i>
      </div>
      <div>
        <span :title="rightPicData.offlineNum" class="ddd">{{ rightPicData.offlineNum }}</span>
        <i>离线设备</i>
      </div>
    </div>

    <div class="left">
      <div
        class="bottom right-bottom-data-left"
        @mouseover="tableEnter"
        @mouseout="timerAni"
      >
        <el-table
          size="mini"
          :data="tableData"
          style="width: 100%"
          :height="tableHeight"
          class="el-bottom"
          ref="table"
        >
          <el-table-column prop="unitName" label="所在单位" width="100">
            <template slot-scope="scope">
              <div class="ddd" :title="scope.row.unitName">
                {{ scope.row.unitName }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="detectorType" label="设备类型" width="">
            <template slot-scope="scope">
              <div class="ddd" :title="scope.row.detectorType">
                {{ scope.row.detectorType }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="statusName" label="预警信息" width="">
            <template slot-scope="scope">
              <div class="ddd" :title="scope.row.statusName">
                {{ scope.row.statusName }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="alarmTime" label="预警时间" width="160">
          </el-table-column>
          <el-table-column prop="handledStatus" label="状态" width="">
            <template slot-scope="scope">
              <div class="ddd" :title="scope.row.handledStatus">
                {{ scope.row.handledStatus }}
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { listDeviceAlarm } from "@/api/dataMonitoring/deviceAlarm";

export default {
  props: {
    rightPicData: {
      type: Object,
    },
  },
  data() {
    return {
      timer: null,
      repeatFinshed: false,
      tableHeight: 202,
      tableData: [],
      scrollHeight: 0,
      timer: null,
    };
  },
  watch: {
    rightPicData(newData) {
      console.log("newData", newData);
      // if (newData.pageData.length > 0) {
      this.tableData = [...newData.pageData];
      // }
      // this.tableData = [...newData.pageData];
      // 列表容器
      this.$nextTick(() => {
        this.getScrollHeight();
      });
    },
  },

  mounted() {},

  methods: {
    getScrollHeight() {
      const selectWrap = this.$refs.table.$el.querySelector(
        ".el-table__body-wrapper"
      );
      // 列表
      const select = this.$refs.table.$el
        .querySelector(".el-table__body-wrapper")
        .querySelector(".el-table__body");
      // 列表容器高度
      const { height: heightWrapper } = selectWrap.getBoundingClientRect();
      // 列表高度
      const { height: heightSelect } = select.getBoundingClientRect();
      // 滚动条的高度 = 列表高度-列表容器高度
      this.scrollHeight = heightSelect - heightWrapper;
      this.timerAni();
    },
    timerAni() {
      const selectWrap = this.$refs.table.$el.querySelector(
        ".el-table__body-wrapper"
      );
      this.timer = setInterval(() => {
        if (selectWrap.scrollTop == this.scrollHeight) {
          selectWrap.scrollTop = 1;
        }
        selectWrap.scrollTop += 1;
      }, 100);
    },
    tableEnter() {
      console.log(123);
      clearInterval(this.timer);
    },
  },
};
</script>

<style lang="scss"  scoped>
.wrapper {
  width: 520px;
  max-height: 258px;
  box-sizing: border-box;
  padding: 10px;
  padding-top: 15px;
  padding-right: 0px;
  position: fixed;
  right: 20px;
  top: 160px;
  // background-color: #fff;
  display: flex;
  justify-content: space-between;
  background-image: url(../../../../assets/images/bg/newPicBg.png);
  background-size: 100% 100%;
  .math {
    width: 520px;
    position: absolute;
    top: -50px;
    left: 0px;
    display: flex;
    justify-content: space-between;
    & > div {
      > span {
        color: aqua;
        font-size: 20px;
        display: inline-block;
        margin-right: 8px;
        max-width: 50px;
        overflow: hidden;
      }
      > i {
        display: inline-block;
        overflow: hidden;
        font-style: normal;

      }
      font-size: 14px;
      color: #fff;
      text-align: center;
      // padding:5px 10px;
      line-height: 35px;
      width: 138px;
      height: 35px;
      background-image: url(../../../../assets/images/bg/bg.png);
      background-size: 100% 100%;
      background-repeat: no-repeat;
    }
  }
  & > div {
  }
  .left {
    width: 500px;
    max-height: 256px;
    margin-right: 12px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.16);
    // background-color: #fff;
    // color: #fff;
    font-size: 14px;
    font-weight: 400;

    .el-table__body-wrappe {
      max-height: 140px !important;
    }
    .top {
      height: 19px;
      // background-color: #053b6a;
      color: #fff;
      // line-height: 32px;
      // padding-left: 12px;
      position: relative;

      .title {
        position: absolute;
        left: 50%;
        margin-left: -92px;
        top: -5px;
      }
      .repeat {
        position: absolute;
        top: -5px;
        right: 160px;
        color: #fff;
        cursor: pointer;
        &:hover {
          color: #2788ea;
        }
      }
      .repeat2 {
        position: absolute;
        right: 206px;
        color: #67c23a;
      }
      .more {
        position: absolute;
        right: 38px;
        top: -5px;
        color: #fff;
        float: right;
        margin-right: 20px;
        cursor: pointer;
        &:hover {
          color: #2788ea;
        }
      }
    }
    .bottom {
      // width: 680px;
      margin: 0 auto;
    }
  }
  .right {
    width: 740px;
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-between;
    align-content: flex-start;
    // margin-top: 7px;
    & > .right-content {
      background-color: #fff;
      width: 238px;
      height: 82px;
      margin-bottom: 29px;
      box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.16);
      margin-right: 10px;
      display: flex;
      &.three {
        margin-right: 0px;
      }
      // align-items: center;
      .text-icon {
        line-height: 82px;
        padding-left: 22px;
        margin-right: 22px;
        i {
          color: #053b6a;
          font-size: 60px;
        }
      }
      .text {
        font-size: 14px;
        padding-top: 16px;
        .top {
          color: #000;
          margin-bottom: 10px;
          font-weight: 600;
        }
        .bottom {
          color: #2788ea;
        }
      }
    }
  }
  // 单独调整下最后一个icon的大小
  .iconFontSize {
    font-size: 50px !important;
  }
  .fade-enter-to,
  .fade-leave {
    opacity: 1;
  }
  .fade-leave-active {
    transition: opacity 0.5s;
  }
  .fade-enter-active {
    transition: opacity 0s;
  }
  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
    opacity: 0;
  }
  .el-table__body-wrappe {
    overflow-x: hidden !important;
    overflow-y: hidden !important;
  }
}
</style>