rightPie.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const app = getApp();
  2. import * as echarts from '../../../../ec-canvas/echarts' // 这个是自己实际的目录
  3. Component({
  4. data:{
  5. Ec: { lazyLoad: true, },
  6. },
  7. lifetimes: {
  8. attached: function () {
  9. var token = wx.getStorageSync('token');
  10. if(!token){
  11. var list = [{name:"追溯产品",value:999,},{name:"非追溯产品",value:666,},]
  12. this.initChart(list);
  13. }
  14. },
  15. moved: function () { },
  16. detached: function () { },
  17. },
  18. properties:{
  19. prductIndex:{
  20. type:String,
  21. value:'',
  22. }
  23. },
  24. observers:{
  25. 'prductIndex':function(nv,ol){
  26. var token = wx.getStorageSync('token');
  27. if(token && nv){
  28. this.getRetransProductState(nv);
  29. }
  30. }
  31. },
  32. methods:{
  33. getRetransProductState(productName){
  34. app.requestP({
  35. url: '/daping/retransProductState?productName='+productName,
  36. method: 'post',
  37. }).then(res=>{
  38. var data = res.data.data[0];
  39. var list = [{name:"追溯产品",value:data.zs,},{name:"非追溯产品",value:data.normal,},]
  40. this.initChart(list);
  41. })
  42. },
  43. initChart(list){
  44. var that = this;
  45. that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => {
  46. const chart = echarts.init(canvas, null, {
  47. width: width,
  48. height: height,
  49. devicePixelRatio: dpr
  50. });
  51. var option = that.getOrderWarnOption(list);
  52. chart.setOption(option);
  53. return chart;
  54. });
  55. },
  56. getOrderWarnOption(list){
  57. var fontSize = 10
  58. var fontColor = "#999999"
  59. return {
  60. color:["#7A4AFF","#FFAE36"],
  61. legend:{
  62. icon:"circle",
  63. itemWidth:fontSize*0.8,
  64. itemHeight:fontSize*0.8,
  65. textStyle:{
  66. fontSize:fontSize*0.9,
  67. color:fontColor,
  68. },
  69. data:list.map(item=>item.name)
  70. },
  71. series:[
  72. {
  73. type: 'pie',
  74. silent:1,
  75. radius:'75%',
  76. center: ["50%", '55%'],
  77. label:{
  78. show:true,
  79. formatter:"{c}",
  80. fontSize:10,
  81. position:"inside",
  82. color:'#ffffff',
  83. },
  84. data: list,
  85. },
  86. ]
  87. }
  88. },
  89. },
  90. })