<template>
  <div class="m-subbox m-sqrfph">
    <div class="table" v-if="pmList.length > 0">
      <div class="tr">
        <div class="th">排名</div>
        <div class="th">社区</div>
        <div class="th">房屋更新数</div>
        <div class="th">人口更新数</div>
        <div class="th">人房更新总数</div>
      </div>
      <div style="overflow: hidden" @mouseenter="yiru()" @mouseleave="yichu()">
        <div ref="animation1">
          <div class="tr" v-for="(item, index) in pmList" :key="index">
            <div :class="index - 0 + 1 < 4 ? `td tdbg${index - 0 + 1}` : 'td'">
              {{ index - 0 + 1 }}
            </div>
            <div class="td">
              <el-tooltip
                class="item"
                effect="dark"
                :content="item.orgName"
                placement="top"
                ><span>{{ item.orgName }}</span>
              </el-tooltip>
            </div>
            <div class="td">{{ item.houseNum }}</div>
            <div class="td">{{ item.residentNum }}</div>
            <div class="td">{{ item.sumNum }}</div>
          </div>
          <!-- 无缝滚动 -->
          <div v-if="pmList.length > 3">
            <div class="tr" v-for="(item, index) in pmList" :key="index">
              <div :class="index - 0 + 1 < 4 ? `td tdbg${index - 0 + 1}` : 'td'">
                {{ index - 0 + 1 }}
              </div>
              <div class="td">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="item.orgName"
                  placement="top"
                  ><span>{{ item.orgName }}</span>
                </el-tooltip>
              </div>
              <div class="td">{{ item.houseNum }}</div>
              <div class="td">{{ item.residentNum }}</div>
              <div class="td">{{ item.sumNum }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-else style="width: 100%; height: 100%; text-align: center; padding-top: 15px">
      <img width="268px" height="128px" src="~@/assets/images/overview/zanwu.png" />
      <div class="zanwuText">近3日暂无更新</div>
    </div>
  </div>
</template>
<script>
export default {
  name: "GridUpdateRanking",
  props: {
    date: {
      type: String,
      default: "",
    },
    currentLevelData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      org: this.$store.state.chooseArea.chooseName,
      pmList: [],
    };
  },
  watch: {
    currentLevelData(val) {
      if (val.orgId) {
        this.getList(val);
      }
    },
    date() {
      this.getList();
    },
  },
  mounted() {
    if (this.currentLevelData.orgId) {
      this.getList(this.currentLevelData);
    }
  },
  methods: {
    yichu() {
      this.$refs.animation1.style["animation-play-state"] = "running";
    },
    yiru() {
      this.$refs.animation1.style["animation-play-state"] = "paused";
    },
    getList(item) {
      this.$http.get("/actual/base/streetOverview/residentHouseUpdateGroupByGrid?level=" + item.orgLevel + "&orgId=" + item.orgId).then(({ data: { data } }) => {
        this.pmList = data;
        if (this.pmList.length > 3) {
          this.$nextTick(() => {
            const aniHeight = this.$refs.animation1.querySelector(".tr").offsetHeight * this.pmList.length;
            this.$refs.animation1.style.animation = `move1 ${this.pmList.length}s linear infinite`;
            document.styleSheets[0].insertRule(`@keyframes move1{0% {transform: translateY(0px);}100% {transform: translateY(-${aniHeight}px);}`, 0);
          });
        } else {
          this.$refs.animation1.style.animation = null;
        }
      });
    },
  },
};
</script>

<style lang="scss" src="@/assets/scss/dataBoard/overview/index.scss" scoped />
<style lang="scss" scoped>
.m-sqrfph {
  padding-top: 0 !important;
  height: 205px !important;
}
.zanwuText {
  margin-top: -34px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #a3b9da;
}
</style>
