const app = getApp();
import * as echarts from '../../../../ec-canvas/echarts' // 这个是自己实际的目录
Component({
  data:{
    Ec: { lazyLoad: true, },
  },
  lifetimes: {
    attached: function () {
      var token = wx.getStorageSync('token');
      if(token){
        this.getRetransProductState();
      }else{
        var list = [{name:"追溯产品",value:999,},{name:"非追溯产品",value:666,},]
        this.init(list);
      }
    },
    moved: function () { },
    detached: function () { },
  },
  methods:{
    getRetransProductState(){
      app.requestP({
        url: '/daping/retransProductState?productName=',
        method: 'post',
      }).then(res=>{
        var data = res.data.data[0];
        var list = [{name:"追溯产品",value:data.zs,},{name:"非追溯产品",value:data.normal,},]
        this.init(list);
      })
    },
    init(list){
      var that = this;
      that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => {
        const chart = echarts.init(canvas, null, {
          width: width,
          height: height,
          devicePixelRatio: dpr
        });
        var option = that.getOrderWarnOption(list);
        chart.setOption(option);
        return chart;
      });
    },
    getOrderWarnOption(list){
      var fontSize = 10
      var fontColor = "#999999"
      return {
        color:["#7A4AFF","#FFAE36"],
        legend:{
          icon:"circle",
          itemWidth:fontSize*0.8,
          itemHeight:fontSize*0.8,
          textStyle:{
            fontSize:fontSize*0.9,
            color:fontColor,
          },
          data:list.map(item=>item.name)
        },
			  series:[
          {
            type: 'pie',
            silent:1,
            radius:["35%", '75%'],
            center: ["50%", '55%'],
            label:{
              show:true,
              formatter:"{c}",
              fontSize:10,
              position:"inside",
              color:'#ffffff',
            },
            data: list,
          },
        ]
      }
    },
  },
})