<template>
  <div class="air-drop-pool">
    <div class="nav">
      <van-icon
        name="arrow-left"
        size="20"
        class="nav-left"
        @click="handlerBack"
      />
      <span class="nav-title">空投池</span>
    </div>
    <div class="air-panel-box">
      <div class="air-panel">
        <div class="notice-bar">
          <img src="@/assets/images/icon-notice.png" alt="" />
          <div class="notice-bar-show" id="scroll-box">
            <div class="user-id-list">
              <p v-for="(item, index) in userPoolVos" :key="index">
                {{ item.userId }}
              </p>
              <p v-for="(item, index) in userPoolVos" :key="index + 'us'">
                {{ item.userId }}
              </p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="air-panel-num">
      <div class="air-panel-num-content">
        <img src="@/assets/images/parachute.png" alt="" />
        <p>
          本月<span>{{ total }}</span> 人在池
        </p>
      </div>
    </div>
  </div>
</template>

<script>
import { queryAerialDelivery } from "@/api/airDropPool";
export default {
  name: "AirDrop",
  data() {
    return {
      total: 0,
      userPoolVos: [{ userId: this.$userId }],
      timer: null
    };
  },
  mounted() {
    this.queryData();
  },
  methods: {
    handlerBack() {
      try {
        this.$bridgeToAppFun.navigateBack();
      } catch {
        console.log("不能和App交互");
        this.$router.go(-1);
      }
    },
    queryData() {
      const _this = this;
      queryAerialDelivery().then(res => {
        console.log("空投池", res);
        if (res.code === 0) {
          _this.total = res.data.total;
          _this.userPoolVos = res.data.userPoolVos;
          _this.$nextTick(() => {
            _this.scroll();
          });
        } else {
          _this.$toast(res.msg);
        }
      });
    },
    scroll() {
      this.timer = setInterval(this.autoScrollLine, 100);
    },
    autoScrollLine() {
      let box = document.getElementById("scroll-box");
      let parent = document.getElementsByClassName("user-id-list")[0];
      const _this = this;
      if (box) {
        if (box.scrollTop != null && box.scrollTop >= parent.offsetHeight) {
          box.scrollTop = 0;
        } else {
          box.scrollTop += 1;
        }
        if (box.scrollTop % box.offsetHeight == 0) {
          clearInterval(_this.timer);
          box.scrollTop = 0;
          setTimeout(() => {
            _this.timer = setInterval(_this.autoScrollLine, 100);
          }, 0);
        }
      }
    }
  }
};
</script>

<style lang="scss" scoped>
$white: #ffffff;
.air-drop-pool {
  width: 100%;
  height: 100vh;
  background-image: url("../assets/images/空投池背景.png");
  background-size: cover;
  .nav {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 46px;
    color: #333333;
    .nav-left {
      position: absolute;
      top: 0;
      bottom: 0;
      width: 52px;
      height: 100%;
      line-height: 46px;
      text-align: center;
    }
    .nav-title {
      max-width: 60%;
      margin: 0 auto;
      font-weight: bold;
      font-size: 16px;
    }
  }
  .air-panel-box {
    padding: 25px 15px 0px 15px;
    box-sizing: border-box;
    .air-panel {
      height: 110px;
      background-color: #ffffff;
      box-shadow: 0px 2px 12px 0px rgba(6, 0, 1, 0.04);
      border-radius: 4px;
    }
  }
  .air-panel-num {
    padding: 10px 15px 15px 15px;
    box-sizing: border-box;
    height: calc(100vh - 220px);
  }
  .air-panel-num-content {
    padding: 20px 15px;
    height: 100%;
    box-shadow: 0px 2px 12px 0px rgba(6, 0, 1, 0.04);
    border-radius: 4px;
    background-size: cover;
    background-color: #ffffff;
    img {
      object-fit: contain;
      width: 100%;
      height: 100%;
    }
    p {
      font-size: 16px;
      font-weight: normal;
      font-stretch: normal;
      color: #333333;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      display: flex;
      align-items: center;
    }
    span {
      font-size: 32px;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: -1px;
      color: #333333;
      margin: 0 20px;
    }
  }
  .notice-bar {
    height: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    padding: 0 20px 0 50px;
    position: relative;
    &::before,
    &::after {
      content: "";
      display: inline-block;
      width: calc(100% - 81px);
      height: 33.33%;
      position: absolute;
      background-color: #ffffff;
      opacity: 0.4;
      left: 81px;
    }
    &::before {
      top: 0;
    }
    &::after {
      top: 66.66%;
    }
    img {
      width: 16px;
      margin-right: 15px;
    }
    .notice-bar-show {
      height: 100%;
      overflow: scroll;

      p {
        font-size: 16px;
        color: #999;
        height: 36.6px;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        color: #333;
      }
      .dark {
        opacity: 0.4;
      }
    }
  }
}
</style>
