// TODO
import * as echarts from 'echarts'; // 调试开关

var DEBUG = process.env.NODE_ENV === 'development';
import './index-sfc.css';

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    ref: "CircleProgress"
  });
};

var __vue_staticRenderFns__ = [];
export default {
  _scopeId: 'data-v-6c58f6ae',
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__,
  name: 'CircleProgress',
  props: {
    percentage: {
      type: Number,
      required: false,
      default: 0
    },
    color: {
      type: String,
      default: '#4fc08d'
    },
    reverseColor: {
      type: String,
      default: 'rgba(0,0,0,0.1)'
    },
    text: {
      // 中心文字
      type: String,
      required: false
    },
    textColor: {
      type: String,
      required: false
    },
    strokeWidth: {
      type: Number,
      default: 25
    }
  },
  data: function data() {
    return {
      Chart: null
    };
  },
  watch: {
    percentage: {
      handler: function handler() {
        var _this = this;

        this.$nextTick(function () {
          _this.draw();
        });
      },
      immediate: true
    }
  },
  mounted: function mounted() {
    // 图表实例化
    this.Chart = echarts.init(this.$refs.CircleProgress);
  },
  methods: {
    draw: function draw() {
      var option = {
        title: {
          text: this.text || undefined,
          // 主标题文本
          left: 'center',
          top: 'center',
          textStyle: {
            fontWeight: 'normal',
            fontSize: Math.max(16, 45 - this.strokeWidth),
            color: this.textColor || this.color
          }
        },
        series: [{
          type: 'pie',
          radius: [95 - this.strokeWidth + "%", '95%'],
          hoverAnimation: false,
          label: {
            show: false
          },
          labelLine: {
            show: false
          },
          tooltip: {
            show: false
          },
          legend: {
            show: false
          },
          data: [{
            value: this.percentage,
            name: 'Progress',
            itemStyle: {
              color: this.color
            }
          }, {
            value: 100 - this.percentage,
            name: '',
            itemStyle: {
              color: this.reverseColor // 反色

            }
          }]
        }]
      };
      this.Chart && this.Chart.setOption(option);
    }
  }
};