<template>
  <v-chart
    style="width:100%;height:100%"
    :auto-resize="true"
    :options="option"/>
</template>
<script>
import { getOtaPublicList } from '@/api/ota.js'
export default {
  Props: ['order-data'],
  data () {
    return {
      option: {
        color: ['#F5501E', '#EFDF2A', '#0AA6EB', '#7DB713', 'red', 'pink'],
        legend: {
          orient: 'horizontal',
          bottom: 20,
          left: '25%'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{b}: {c} ({d}%)'
        },
        grid: {
          top: 10,
          left: 10,
          right: 10,
          bottom: 0,
          containLabel: true
        },
        series: [
          {
            name: '票型销售统计',
            type: 'pie',
            center: ['50%', '37%'],
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false,
                position: 'center'
              },
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: '30',
                  fontWeight: 'bold'
                }
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            },
            data: this.actionData
          }
        ]
      },
      otaTotalData: [],
      actionData: []
    }
  },
  created () {
    this.getOtaPublicList()
    console.log(this.orderData)
  },
  watch: {
    'actionData': {
      handler (newAction, oldAction) {
        this.option.series[0].data = this.actionData
      }
      // immediate: true,
      // deep: true
    }
  },
  methods: {
    getOtaPublicList () {
      getOtaPublicList({}).then(res => {
        this.otaTotalData = res.list
        let arr = []
        for (let i = 0; i < this.otaTotalData.length; i++) {
          let otaData = {value: '', name: ''}
          otaData.value = '10'
          otaData.name = this.otaTotalData[i].publicotaSourceName
          arr.push(otaData)
          this.actionData = arr
        }
      })
    }
  }
}
</script>
