<template>
  <div class="hot">
    <!-- 标题区域 -->
    <div class="hot_title">
      <div class="title_text">销售热榜TOP3</div>
      <img src="@/assets/images/33.png" />
    </div>

    <!-- 列表区域 -->
    <div class="hot_list">
      <!-- 每一个盒子区域 -->
      <div class="hot_item" v-for="(item, index) in list" :key="index">
        <div class="item_info">
          <div class="info_rank">TOP{{ index + 1 }}</div>
          <div class="info_name">{{ item.name }}</div>
          <div class="info_num" ref="infoNum" :data-value="item.total">
            {{ item.total }}
          </div>
        </div>
        <div class="item_progress">
          <el-progress
            :stroke-width="12"
            :percentage="item.rate"
            :show-text="false"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, nextTick } from "vue";
import { countUpNum } from "@/utils/countUpNum.ts";
// 引入旅游服务相关的接口
import { reqGetTopByAmount } from "@/api/serve/index";

// Dom元素数组
const infoNum = ref();

// 特产销售热榜top3数据
const list = ref<any>([]);

onMounted(() => {
  // 获取特产销售热榜top3数据
  getTopByAmount();
});

// 获取特产销售热榜top3数据
const getTopByAmount = async () => {
  const res = await reqGetTopByAmount();
  // console.log(res);
  list.value = res.data;

  // 计算百分比
  list.value.forEach((ele: any) => {
    ele.rate = (ele.total / res.data[0].total) * 100;
  });

  nextTick(() => {
    // 让数字跳动
    infoNum.value.forEach((ele: any) => {
      countUpNum(ele, ele.dataset.value);
    });
  });
};
</script>

<style lang="scss" scoped>
.hot {
  width: 100%;
  height: 100%;

  .hot_title {
    position: relative;
    width: 548px;
    height: 41px;
    line-height: 41px;

    .title_text {
      position: absolute;
      left: 15px;
      z-index: 1;
      font-size: 23.5px;
      font-weight: bold;
      color: #e0efff;
    }

    img {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 548px;
      height: 16px;
    }
  }

  .hot_list {
    padding: 0 10px;
    margin-top: 40px;
    width: 100%;
    height: 228px;
    overflow-y: auto;

    .hot_item {
      margin-bottom: 20px;

      .item_info {
        display: flex;
        align-items: center;
        width: 100%;
        height: 28px;
        font-size: 21px;
        color: #75bcff;

        .info_rank {
          color: #3bfcff;
        }

        .info_name {
          margin-left: 5px;
        }

        .info_num {
          margin-left: auto;
        }
      }

      .item_progress {
        margin-top: 15px;
        width: 100%;
        height: 18px;
      }
    }
  }
}

::v-deep(.el-progress-bar__outer) {
  background: linear-gradient(
    180deg,
    rgba(43, 47, 57, 1) 0%,
    rgba(26, 29, 40, 1) 100%
  );
  box-shadow: inset 0px 1px 3px rgba(116, 129, 163, 0.5);
}

::v-deep(.el-progress-bar__inner) {
  background: linear-gradient(
    90deg,
    rgba(38, 42, 52, 1) 0%,
    rgba(69, 164, 196, 1) 44.47%,
    rgba(78, 185, 242, 1) 100%
  );
}

::v-deep(.el-progress-bar__inner::after) {
  width: 4px;
  height: 150%;
  background-color: #fff;
}
</style>
