<template>
  <div class="ranking">
    <div class="ranking-header">
      {{ activityName }}
    </div>
    <div class="ranking-content">
      <div class="ranking-content-left">
        <div class="ranking-content-left-points">
          <div class="list">
            <div class="my-points">
              <p>My Points</p>
              <div class="list-btm">
                <div class="points">
                  <!-- <formatPrice /> -->
                  <span>{{ userData.scoreTotal }}</span>
                  <img src="./../../assets/common/Icon_Points.png" alt="">
                </div>
              </div>
            </div>
            <div class="my-ranking">
              <p>My Ranking</p>
              <div class="list-btm">
                <div class="ranking">10</div>
              </div>
            </div>
          </div>
        </div>
        <div class="ranking-content-left-forward">
          <div class="forward-list">
            <li>
              <div class="forward-list-item-star">
                <img src="@/assets/box/Icon_Star_01.png" alt="">
              </div>
              <div class="forward-list-item-top">
                <div class="user-img">
                  <img :src="rankingTableData[1].avatar" alt="">
                </div>
              </div>
              <div class="forward-list-item-btm">
                <div class="name">{{ rankingTableData[1].nickname }}</div>
                <div>{{ rankingTableData[1].score }}</div>
              </div>
            </li>
            <li>
              <div class="forward-list-item-star">
                <img src="@/assets/box/Icon_Star_01.png" alt="">
              </div>
              <div class="forward-list-item-top">
                <div class="user-img">
                  <img :src="rankingTableData[0].avatar" alt="">
                </div>
                <!-- <div>{{ rankingTableData[0].nickname.slice(0,4) }}{{ '…'+rankingTableData[0].nickname.slice(-4) }}</div> -->
              </div>
              <div class="forward-list-item-btm">
                <div class="name">{{ rankingTableData[0].nickname }}</div>
                <div>{{ rankingTableData[0].score }}</div>
              </div>
            </li>
            <li>
              <div class="forward-list-item-star">
                <img src="@/assets/box/Icon_Star_01.png" alt="">
              </div>
              <div class="forward-list-item-top">
                <div class="user-img">
                  <img :src="rankingTableData[0].avatar" alt="">
                </div>
              </div>
              <div class="forward-list-item-btm">
                <div class="name">{{ rankingTableData[2].nickname }}</div>
                <div>{{ rankingTableData[2].score }}</div>
              </div>
            </li>
          </div>
        </div>
      </div>
      <div class="ranking-content-right">
        <div class="ranking-content-right-list">
          <li v-for="(item, index) in rankingTableData" :key="index">
            <div class="left">
              <div class="left-left">
                <div class="rank">
                  <img v-if="item.rank == 1" src="./../../assets/ranking/Ranking1.png" alt="">
                  <img v-else-if="item.rank == 2" src="./../../assets/ranking/Ranking2.png" alt="">
                  <img v-else-if="item.rank == 3" src="./../../assets/ranking/Ranking3.png" alt="">
                  <span v-else>{{ item.rank }}</span>
                </div>
              </div>
              <div class="left-right">
                <div class="user-img">
                  <img class="one-img" v-if="item.avatar != ''" :src="item.avatar" alt="">
                  <img class="one-img" v-else src="./../../assets/home/Nav bar_character.png" alt="">
                </div>
                <div class="user-name">
                  <div class="label">Name</div>
                  <div class="name">{{ item.nickname }}</div>
                </div>
              </div>
            </div>
            <div class="right">
              <div class="label">Points</div>
              <div class="records">{{ item.score }}</div>
            </div>
          </li>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getToken } from './../../utils/cookies.js'
import formatPrice from '@/components/formatPrice.vue'
export default  {
  components: {
    
  },
  props: {
    activityName: String,
  },
  data() {
    return {
      token: getToken(),
      detailsDialog: false,
      detailsList: [
        {
          action: 'Task',
          time: '2024-03-08 12:59:37',
          pts: '90'
        }
      ],
      rankingTableData: [],
      userData: [
        {
          scoreTotal: '0'
        }
      ]
    }
  },
  mounted() {
    
    if(this.token) {
      this.getLeaderBoard()
      // this.getUserState()
      this.userData = JSON.parse(localStorage.getItem("userData"));
      this.getMyIntegralList()
    }
  },
  methods: {
    // 我的积分记录
    async getMyIntegralList() {
      let res = await this.$axios.get(process.env.VUE_APP_API_URL+`/api/user/checkin/list/all`,{ params: '',
        headers: { Authorization: `Bearer ${this.token}` },
      })
      this.detailsList = res.data.data
    },

    // 获取总积分榜
    async getLeaderBoard () {
      let res = await this.$axios.get(process.env.VUE_APP_API_URL+`/api/activity/leaderboard/uaw_activity/0`)
      console.log(res.data.data)
      this.rankingTableData = res.data.data
    },
    // 获取用户状态
    getUserState() {
      this.$axios.get(process.env.VUE_APP_API_URL+'/api/user/state',{ params: '',
          headers: { Authorization: `Bearer ${this.token}` },
      }).then(res => {
        this.userData = res.data.data
        console.log(this.userData)
        localStorage.setItem('userData', JSON.stringify(res.data.data))
      })
    },
  },
}

</script>

<style lang="scss" scoped>
.ranking {
  position: relative;
  .ranking-header {
    height: 40px;
    line-height: 40px;
    text-align: left;
    position: absolute;
    top: -50px;
    left: 50px;
    font-size: 42px;
    font-weight: 700;
    font-family: "Anton-Regular";
  }
  .ranking-content {
    display: flex;
    justify-content: space-around;
    .ranking-content-left {
      width: 60%;
      position: relative;
      .ranking-content-left-points {
        width: 160px;
        padding: 20px;
        background: url('./../../assets/ranking/My points bg.png') no-repeat;
        background-size: 100% 100%;
        margin-top: 10px;
        .list {
          .my-points {
            p {
              text-align: left;
              font-size: 12px;
            }
            .list-btm {
              position: relative;
              height: 40px;
              margin-bottom: 20px;
              .points {
                width: 280px;
                height: 140px;
                background: url('@/assets/ranking/Point bg.png') no-repeat;
                background-size: 100% 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                position: absolute;
                top: -88%;
                left: 43%;
                transform: translateX(-50%);
                span {
                  font-size: 28px;
                  font-weight: 700;
                  font-family: "Anton-Regular";
                  color: #9950fd;
                }
                img {
                  width: 16px;
                  height: 22px;
                  margin-left: 20px;
                }
              }
            }
          }
          .my-ranking {
            p {
              font-size: 12px;
              text-align: left;
              margin-top: 40px;
            }
            .list-btm {
              font-size: 28px;
              font-weight: 700;
              font-family: 'Anton-Regular';
              .ranking {
                margin-left: 10px;
                color: #FFC35B;
                text-align: left;
              }
            }
          }
        }
      }
      .ranking-content-left-forward {
        width: 70%;
        height: 500px;
        background: url('@/assets/ranking/Background_shine.png') no-repeat;
        background-size: 100% 100%;
        margin: 0 auto;
        padding: 10px;
        position: absolute;
        top: -15%;
        left: 55%;
        transform: translateX(-50%);
        .forward-list {
          width: 1000px;
          height: 100%;
          display: flex;
          justify-content: space-evenly;
          position: absolute;
          left: 50%;
          bottom: -38%;
          transform: translateX(-50%);
          position: relative;
          li {
            width: 300px;
            height: 300px;
            padding: 10px;
            margin-top: 50px;
            box-sizing: content-box;
            background: url('@/assets/ranking/Bg_chest.png') no-repeat;
            background-size: 100% 100%;
            position: relative;
            .forward-list-item-star {
              position: absolute;
              top: 0;
              left: 50%;
              transform: translateX(-50%);
              width: 40px;
              height: 40px;
              img {
                width: 100%;
                height: 100%;
              }
            }
            .forward-list-item-top {
              position: absolute;
              top: 40%;
              left: 50%;
              transform: translate(-50%, -50%);
              .user-img {
                width: 120px;
                height: 120px;
                border-radius: 50%;
                overflow: hidden;
                img {
                  width: 100%;
                  height: 100%;
                }
              }
            }
            .forward-list-item-btm {
              font-size: 14px;
              position: absolute;
              bottom: 18%;
              left: 50%;
              transform: translateX(-50%);
              .name {
                font-weight: 700;
                font-size: 16px;
              }
            }
            &:nth-child(3) {
              position: absolute;
              right: 8%;
              top: 30%;
            }
          }
          li:nth-child(1) {
            position: absolute;
            left: 10%;
            top: 30%;
          }
          li:nth-child(2) {
            position: absolute;
            top: -35%;
            left: 50%;
            transform: translateX(-50%);
            width: 420px;
            height: 420px;
            .forward-list-item-star {
              width: 60px;
              height: 60px;
            }
            .forward-list-item-top {
              .user-img {
                width: 180px;
                height: 180px;
              }
            }
          }
        }
      }
    }
    .ranking-content-right {
      width: 30%;
      height: 680px;
      padding: 0 30px;
      box-sizing: border-box;
      position: relative;
      overflow-y: scroll;
      .ranking-content-right-list {
        
        li {
          display: flex;
          align-items: center;
          justify-content: space-between;
          background: #2d2738;
          padding: 8px 50px;
          border-radius: 30px;
          margin-top: 15px;
          .left {
            display: flex;
            align-items: center;
            .left-left {
              width: 50px;
              margin-right: 30px;
              .rank {
                span {
                  font-size: 18px;
                  font-weight: 700;
                  // font-family: "Anton-Regular";
                  color: #9950fd;
                }
                img {
                  width: 40px;
                  height: 30px;
                }
              }
            }
            .left-right {
              display: flex;
              align-items: center;
              .user-img {
                width: 45px;
                height: 45px;
                display: flex;
                align-items: center;
                justify-content: center;
                border-radius: 50%;
                background: url('@/assets/common/Picture frame .png') no-repeat;
                background-size: 100% 100%;
                overflow: hidden;
                img {
                  width: 95%;
                  height: 95%;
                }
              }
              .user-name {
                font-size: 16px;
                margin-left: 20px;
                line-height: 1.4;
                .label {
                  text-align: left;
                  color: #5b5862;
                  font-size: 12px;
                }
              }
            }
          }
          .right {
            line-height: 1.4;
            .label {
              text-align: left;
              color: #5b5862;
              font-size: 12px;
            }
            .records {
              text-align: left;
              // font-size: 12px;
              // color: #9950fd;
            }
            .icon {
              width: 10px;
              height: 12px;
              margin-left: 5px;
              display: flex;
              align-items: center;
              img {
                width: 100%;
                height: 100%;
              }
            } 
          }
          &:nth-child(1) {
            .left {
              .user-img {
                width: 40px;
                height: 40px;
                position: relative;
                .one-bg {
                  width: 60px;
                  height: 60px;
                  position: absolute;
                  top: 50%;
                  left: 50%;
                  transform: translate(-50%, -50%);
                }
                .one-img {
                  width: 40px;
                  height: 40px;
                  position: absolute;
                  top: 50%;
                  left: 50%;
                  transform: translate(-50%, -50%)
                } 
              }
            }
          }
        }
      }
      &::-webkit-scrollbar {
        width: 5px;
      }
      &::-webkit-scrollbar-track{
        background: #171220;
        border-radius:2px;
      }
      &::-webkit-scrollbar-corner{
        display: block;
      }
      &::-webkit-scrollbar-thumb{
        height: 15px;
        background: #9950fd;
      }
    }
  }
}
</style>