<template>
  <div class="rank-container">
    <div class="rank-item" v-for="(item, index) in rankList" :key="index">
      <div class="rank-index-wrapper" :class="index < 3 ? 'rank-index-top3' : 'rank-index-other'">
        <span class="rank-index">{{ index + 1 }}</span>
      </div>
      <div class="rank-name" v-if="item.name!=null">{{ item.name | limitText }}</div>
      <div class="rank-name" v-if="item.name==null">商品已被删除</div>
      <div class="rank-score">{{ item.score  }}</div>
    </div>
  </div>
</template>

<script>
import { storeChartData } from "@/api/store/index";
export default {
  data() {
    return {
      rankList: [
      ],
    };
  },
  filters: {
    limitText(value) {
      if (typeof value === 'string' && value.length > 20) {
        return value.slice(0, 20)+"...";
      }
      return value;
    }
  },
  mounted() {
      storeChartData(0).then(response => {
        this.rankList = response.data;
      });

  },
  methods: {
    getDoc(row){
      storeChartData(row).then(response => {
        this.rankList = response.data;
      });
    }
  },
};
</script>

<style scoped>
.rank-container {
  display: flex;
  flex-direction: column;
}

.rank-item {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 10px;
  margin-bottom: 10px;
}

.rank-index-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  margin-right: 10px;
}

.rank-index-top3 {
  background-color: #000;
  color: #fff;
}

.rank-index-other {
  background-color: #dddddd;
  color: #fff;
}

.rank-index {
  font-size: 10px;
  font-weight: bold;
}

.rank-name {
  flex: 1;
  margin-left: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100px;
}

.rank-score {
  font-weight: bold;
}
</style>
