<template>
  <div>
    <ul class="star_list">
      <li
        class="item_list"
        v-for="(option, index) in options"
        :key="'star_info_' + index"
      >
        <el-rate
          class="item-rate"
          :colors="['#8890a7', '#8890a7', '#8890a7']"
          :value="option.star"
          disabled
          disabled-void-color="transparent"
        >
        </el-rate>
        <el-progress
          class="item-progress"
          :percentage="getPercent(option.count)"
          :show-text="false"
          color="#e56600"
        ></el-progress>
        <span class="item-text" v-text="option.count + '个'"></span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    options: {
      type: Array,
      default: () => [
        {
          star: 5,
          count: 5,
          unit: "个",
        },
        {
          star: 4,
          count: 4,
          unit: "个",
        },
        {
          star: 3,
          count: 3,
          unit: "个",
        },
        {
          star: 2,
          count: 10002,
          unit: "个",
        },
        {
          star: 1,
          count: 1,
          unit: "个",
        },
      ],
    },
    total: {
      type: Number,
      default: () => 10015,
    },
  },
  methods: {
    getPercent(value) {
      return Math.min((value / this.total) * 100, 100);
    },
  },
};
</script>

<style scoped>
.star_list {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}
.item_list {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  margin-right: 10px;
  margin-bottom: 12px;
}
.item-rate {
  flex-shrink: 0;
  display: inline-flex;
  flex-direction: row-reverse;
  justify-content: flex-start;
  align-items: center;
  margin-right: 10px;
}
.item-progress {
  flex-grow: 1;
  max-width: 200px;
  margin-right: 10px;
}
.item-text {
  flex-shrink: 0;
  width: 60px;
  font-size: 14px;
  line-height: 20px;
  color: #242c43;
  text-align: right;
}
</style>

<style>
.item-rate .el-rate {
  height: 14px;
}
.item-rate .el-rate__icon {
  font-size: 14px;
  margin-right: 0;
}
.item-progress .el-progress-bar__outer {
  background: #e2e3ed;
}
</style>
