<template>
  <div class="map-table-container" ref="mapTableContainer">
    <ul class="map-table-list" ref="mapTableList">
      <li class="map-table-list-item" v-for="item in 10" :key="item">
        <div class="serial">{{ item }}</div>
        <div class="name">高德大厦</div>
        <div class="province">广东区域</div>
        <div class="city">珠海市</div>
        <div class="num">22</div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      mapTableListHeight: 0,
      mapTableContainerHeight: 0,
      h: 0,
    };
  },
  mounted() {
    this.getHeight();
    this.compareH();
  },
  methods: {
    // 获取map-table-list的高度
    getHeight() {
      // 获取map-table-list的高度
      let mapTableContainer = this.$refs.mapTableContainer;
      this.mapTableContainerHeight = mapTableContainer.offsetHeight;
    },
    // 比较map-table-list高度
    compareH() {
      let mapTableList = this.$refs.mapTableList;
      this.mapTableListHeight = mapTableList.offsetHeight;
      if (this.mapTableContainerHeight < this.mapTableListHeight) {
        console.log(this.mapTableContainerHeight, this.mapTableListHeight);
        // 添加定时器滚动map-table-list-item
        setInterval(() => {
          this.h -= 25;
          if (Math.abs(this.h) > this.mapTableListHeight) {
            this.h = 0;
          }
          this.$refs.mapTableList.style.transform = `translateY(${this.h}px) `;
        }, 1500);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.map-table-container {
  height: 100%;
  overflow: auto;
}
.map-table-list {
  transition: all 1s;
  margin: 0;
  padding: 0;
  &-item {
    display: flex;
    height: 30px;
    margin-bottom: 5px;
    line-height: 30px;
    color: #fff;
    text-align: center;
    background: linear-gradient(
      180deg,
      rgba(0, 102, 153, 1) 0%,
      rgba(0, 102, 153, 1) 17%,
      rgba(9, 60, 106, 1) 100%,
      rgba(9, 60, 106, 1) 100%
    );
    .serial {
      width: 40px;
      height: 100%;
      position: relative;
      text-align: center;
      background: #2a719d;
      color: #fff;
      font-weight: bold;
      font-size: 16px;
      &::after {
        position: absolute;
        right: -14px;
        top: 0;
        content: "";
        display: block;
        border-top: 16px solid transparent;
        border-bottom: 16px solid transparent;
        border-left: 16px solid #2a719d;
      }
    }
    .name {
      width: 30%;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      margin-left: 18px;
    }
    .province,
    .city,
    .num {
      width: 20%;
    }
    .province {
      color: #02a7f0;
    }
    // #FFEA00
    .city {
      color: #ffea00;
    }
    .num {
      color: rgba(217, 0, 27, 0.9);
      font-size: 12px;
    }
  }
  &-item:hover {
    background: rgba(255, 166, 0, 0.802);
    color: #000;
    .province,
    .city {
      color: #000;
    }
    .serial {
      background: linear-gradient(#ff6048 0%, #ff7346 100%);
      &::after {
        border-left-color: #ff7346;
      }
    }
  }
}
</style>