<template>
  <ul class="star_list apass_scroll">
    <li class="item_list" v-for="(option, index) in options" :key="'star_info_' + index">
      <el-rate
        v-if="show_star"
        class="item-rate"
        :colors="['#8890a7', '#8890a7', '#8890a7']"
        :value="option.star"
        disabled
        disabled-void-color="transparent"
      ></el-rate>
      <span v-else class="data_title">{{ option.title }}</span>
      <el-progress
        class="item-progress"
        :percentage="getPercent(option.count)"
        :show-text="false"
        :color="show_star ? color : colors[index]"
      ></el-progress>
      <span v-if="!show_star" class="item_text_1" v-text="option.percent + '%'"></span>
      <span class="item-text" v-text="option.count + '个'"></span>
    </li>
  </ul>
</template>

<script>
export default {
  props: {
    options: {
      type: Array,
      default: () => []
    },
    total: {
      type: Number,
      default: () => 10
    },
    show_star: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      color: "#e56600",
      colors: ["#25bdb1", "#f5ab4c", "#e15260", "#274fee", "#58617a"]
    };
  },
  methods: {
    getPercent(value) {
      return Math.min((value / this.total) * 100, 100);
    }
  }
};
</script>

<style scoped>
.star_list {
  overflow-x: hidden;
  overflow-y: auto;
}
.item_list {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  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;
  margin-right: 10px;
}
.item-text {
  flex-shrink: 0;
  width: 60px;
  font-size: 14px;
  line-height: 20px;
  color: #242c43;
  text-align: right;
}
.item_text_1 {
  flex-shrink: 0;
  width: 40px;
  font-size: 14px;
  line-height: 20px;
  color: #8890a7;
  text-align: left;
}
.data_title {
  display: inline-block;
  margin-right: 10px;
  width: 100px;
  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>
