<template>
  <div class="echarts">
    <ECharts :option="option" :resize="false" />
  </div>
</template>

<script setup>
import ECharts from "@/components/ECharts/index.vue";
import { ranking1, ranking2, ranking3, ranking4 } from "../assets/ranking-icon";
import echarts from "@/components/ECharts/config";
import { getReturnRateByPlatform } from '@/api/dataScreen';
import { computed } from "vue";
import { reactive, ref } from 'vue';

var salvProName =ref([]);
var salvProValue =ref([]);
getReturnRateByPlatform().then(res => {
  if (res.result) {
    const arr = res.result
    arr.sort((a,b) => a.rate - b.rate)
    salvProName.value = arr.map(v => v.loanPlatform)
    salvProValue.value = arr.map(v => v.rate?.toFixed(2))
  }
})


const option = computed(() => {
  return {
    grid: {
        left: '2%',
        right: '2%',
        bottom: '2%',
        top: '2%',
        containLabel: true
    },
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'none'
        },
        formatter: function(params) {
            return params[0].name  + ' : ' + params[0].value
        }
    },
    xAxis: {
        show: false,
        type: 'value'
    },
    yAxis: [{
        type: 'category',
        inverse: true,
        axisLabel: {
            show: false,
            textStyle: {
                color: '#fff',
                fontSize: '14'
            },
        },
        splitLine: {
            show: false
        },
        axisTick: {
            show: false
        },
        axisLine: {
            show: false
        },
        data: salvProName.value
    }, {
        type: 'category',
        inverse: true,
        axisTick: 'none',
        axisLine: 'none',
        show: true,
        axisLabel: {
            textStyle: {
                color: '#ffffff',
                fontSize: '14'
            },
        },
        data:salvProValue.value
    }],
    series: [{
            name: '值',
            type: 'bar',
            zlevel: 1,
            itemStyle: {
                normal: {
                    // barBorderRadius: 30,
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: 'rgb(57,89,255,1)'
                    }, {
                        offset: 1,
                        color: 'rgb(46,200,207,1)'
                    }]),
                },
            },
            label: {
              normal: {
                color: '#fff',
                show: true,
                position: [0, '-24px'],
                textStyle: {
                  fontSize: 16
                },
                formatter: function (a, b) {
                  return a.name
                }
              }
            },
            barWidth: 50,
            data: salvProValue.value
        },
        {
            name: '背景',
            type: 'bar',
            barWidth: 50,
            barGap: '-100%',
            data: salvProValue.value.map(v => 100),
            itemStyle: {
                normal: {
                    color: '#05091e',
                    // barBorderRadius: 30,
                }
            },
        },
    ]
  }
})
</script>
<style lang="scss" scoped>
.echarts {
  width: 100%;
  height: calc(100% - 56px);
}
.echarts-header {
  box-sizing: border-box;
  display: flex;
  height: 36px;
  margin: 10px 10px 0;
  line-height: 36px;
  background: url("../images/rankingChart-bg.png") no-repeat;
  background-size: 100% 100%;
  span {
    width: 18%;
    margin-left: 4px;
    font-size: 14px;
    font-weight: bold;
    color: #fdbc52;
    text-align: center;
    &:nth-child(2) {
      margin-left: 4px;
    }
    &:last-child {
      width: 20%;
      margin-left: 60px;
    }
  }
}
</style>
