<script>
import apiDashboard from "@/api/dashboard/apiDashboard";

export default {
  data() {
    return {
      dataIndexes: ['saving', 'amountSubsidy'],
      option: {
        color: ['#80D4FF', '#FFDF80'],
        tooltip: {
          trigger: 'item'
        },
        legend: {
          bottom: '8%',
          left: 'center',
          icon: 'circle'
        },
        series: [
          {
            name: '金额',
            type: 'pie',
            center: ['50%','40%'],
            data: [
              { value: 0, name: '补贴金额' },
              { value: 0, name: '节约金额' },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
    }
  },
  props: {
    height: Number,
  },
  mounted() {
    this.$nextTick(()=>{
      this.initChart();
      this.getData();
    })
  },
  methods: {
    initChart() {
      let chart = this.$echarts.init(this.$refs.myChart)
      this.chart = chart;
      chart.setOption(this.option)
    },
    getData() {
      apiDashboard.getPvProfitOverview({}).then(res=>{
        this.option.series[0].data[0].value = res.saving;
        this.option.series[0].data[1].value = res.amountSubsidy;
        this.chart.setOption(this.option);
      })
    }
  }
}
</script>

<template>
  <div style="width: 100%" :style="{height: height+'px'}" ref="myChart"></div>
</template>

<style lang="less" scoped>

</style>