<template>
  <div class="chart" :id="id"></div>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
import * as echarts from 'echarts';
type EChartsOption = echarts.EChartsOption;

@Component
export default class Rose extends Vue {
  id=this.randomString();

  mounted(){
    this.init()
  }

  randomString(){
    const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let result = '';
    for (let i = 10; i > 0; --i) 
      result += str[Math.floor(Math.random() * str.length)];
    return result;
  }

  init(){
    let chartDom:any = document.getElementById(this.id);
    let myChart = echarts.init(chartDom);
    let option: EChartsOption;

    option = {
      title: {
        text: '月订单状态',
        left: 'center'
      },
      legend: {
        top: 'bottom'
      },
      toolbox: {
        show: true,
        feature: {
          mark: { show: true },
          // dataView: { show: true, readOnly: false },
          // restore: { show: true },
          // saveAsImage: { show: true }
        }
      },
      series: [
        {
          name: 'Nightingale Chart',
          type: 'pie',
          radius: [30, 120],
          center: ['50%', '50%'],
          roseType: 'area',
          itemStyle: {
            borderRadius: 8
          },
          data: [
            { value: 40, name: '待付款' },
            { value: 38, name: '等待供应商|外仓发货' },
            { value: 32, name: '已付款待审核' },
            { value: 30, name: '已客审待财审' },
            { value: 28, name: '发货中' },
            { value: 26, name: '已发货' },
            { value: 22, name: '取消订单' },
            { value: 18, name: '订单异常' }
          ]
        }
      ]
    };

    option && myChart.setOption(option);
  }
}
</script>

<style lang="scss" scoped>
.chart{
  height: 100%;
  width: 100%;
}
</style>