<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', canScroll && 'scroll']"
              :style="canScroll && `animation-duration: ${animationDuration}s`"
            >
              <p
                v-for="(item, index) in userPoolVos"
                :key="index"
                @click="openUserInfo(item)"
              >
                用户{{ item.userId }}进入空投池
              </p>
            </div>
            <div
              :class="['user-id-list', canScroll && 'scroll']"
              :style="canScroll && `animation-duration: ${animationDuration}s`"
            >
              <p
                v-for="(item, index) in userPoolVos"
                :key="index + 'down'"
                @click="openUserInfo(item)"
              >
                用户{{ 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 || 0 }}</span> 人在池
        </p>
      </div>
    </div>
    <base-dialog
      class="user-dialog"
      :base-dialog-show="userInfoDialog"
      @onClick="onCloseUser"
    >
      <div slot="content" class="user-dialog-content">
        <img :src="currentUser.avatar" alt="头像" />
        <span class="normal">账号</span>
        <span class="user-id">{{ currentUser.userId }}</span>
        <span class="normal">进入空投池时间</span>
        <span class="time">{{ currentUser.intoTime }}</span>
      </div>
    </base-dialog>
  </div>
</template>

<script>
import { queryAerialDelivery } from "@/api/airDropPool";
import BaseDialog from "../components/BaseDialog.vue";
export default {
  components: { BaseDialog },
  name: "AirDrop",
  data() {
    return {
      animationDuration: 10,
      canScroll: false,
      currentUser: {},
      userInfoDialog: false,
      total: 0,
      userPoolVos: [],
      timer: null
    };
  },
  mounted() {
    this.queryData();
  },
  methods: {
    onCloseUser() {
      this.userInfoDialog = false;
      this.canScroll = true;
    },
    openUserInfo(item) {
      console.log(123);
      this.canScroll = false;
      this.userInfoDialog = true;
      this.currentUser = item;
      this.currentUser.avatar = process.env.VUE_APP_BASE_URL + item.headImage;
    },
    handlerBack() {
      try {
        this.$bridgeToAppFun.navigateBack();
      } catch {
        console.log("不能和App交互");
        this.$router.go(-1);
      }
    },
    queryData() {
      const _this = this;
      queryAerialDelivery().then(res => {
        if (res.code === 0) {
          _this.total = res.data.total;
          _this.userPoolVos = res.data.userPoolVos.map(item => {
            const temp = item;
            temp.userId =
              item.userId.substring(0, 3) + "****" + item.userId.substring(7);
            return temp;
          });
          if (_this.userPoolVos.length > 3) {
            this.canScroll = true;
            this.animationDuration = _this.userPoolVos.length * 3;
          }
          // _this.$nextTick(() => {
          //   if (_this.canScroll) {
          //     _this.scroll();
          //   }
          // });
        } else {
          _this.$toast(res.msg);
        }
      });
    },
    scroll() {
      // this.timer = setInterval(this.autoScrollLine, 100);
      // const marquee = document.querySelector(".user-id-list");
      // const contents = marquee.innerHTML;
      // marquee.innerHTML = contents + contents;
    }
    // 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 < 1) {
    //       clearInterval(_this.timer);
    //       box.scrollTop = 0;
    //       _this.timer = setInterval(_this.autoScrollLine, 200);
    //     }
    //   }
    // }
  }
};
</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: -15px;
      z-index: 1;
    }
    &::after {
      top: 66.66%;
    }
    img {
      width: 16px;
      margin-right: 15px;
    }
    .notice-bar-show {
      width: 100%;
      height: 100%;
      .user-id-list {
        display: flex;
        flex-direction: column;
        &:hover {
          animation-play-state: paused;
        }
        p {
          pointer-events: auto;
        }
      }

      .scroll {
        animation-name: marquee;
        animation-timing-function: linear;
        animation-iteration-count: infinite;
      }

      @keyframes marquee {
        0% {
          transform: translateY(0%);
        }
        100% {
          transform: translateY(-100%);
        }
      }

      p {
        font-size: 16px;
        color: #999;
        height: 36.6px;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: center;
        color: #333;
      }
      .dark {
        opacity: 0.4;
      }
    }
  }
  .user-dialog-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    margin-top: 20px;

    img {
      width: 67px;
      height: 67px;
      margin-bottom: 5px;
    }

    .normal {
      font-size: 14px;
      color: #999999;
    }
    .user-id,
    .time {
      font-size: 16px;
    }

    .user-id {
      margin-bottom: 20px;
    }
  }
  .user-dialog {
    ::v-deep .van-button {
      color: #666666;
      background-color: #ffffff;
    }
  }
}
</style>