index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. this.getRetransProductState();
  12. }else{
  13. var list = [{name:"追溯产品",value:999,},{name:"非追溯产品",value:666,},]
  14. this.init(list);
  15. }
  16. },
  17. moved: function () { },
  18. detached: function () { },
  19. },
  20. methods:{
  21. getRetransProductState(){
  22. app.requestP({
  23. url: '/daping/retransProductState?productName=',
  24. method: 'post',
  25. }).then(res=>{
  26. var data = res.data.data[0];
  27. var list = [{name:"追溯产品",value:data.zs,},{name:"非追溯产品",value:data.normal,},]
  28. this.init(list);
  29. })
  30. },
  31. init(list){
  32. var that = this;
  33. that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => {
  34. const chart = echarts.init(canvas, null, {
  35. width: width,
  36. height: height,
  37. devicePixelRatio: dpr
  38. });
  39. var option = that.getOrderWarnOption(list);
  40. chart.setOption(option);
  41. return chart;
  42. });
  43. },
  44. getOrderWarnOption(list){
  45. var fontSize = 10
  46. var fontColor = "#999999"
  47. return {
  48. color:["#7A4AFF","#FFAE36"],
  49. legend:{
  50. icon:"circle",
  51. itemWidth:fontSize*0.8,
  52. itemHeight:fontSize*0.8,
  53. textStyle:{
  54. fontSize:fontSize*0.9,
  55. color:fontColor,
  56. },
  57. data:list.map(item=>item.name)
  58. },
  59. series:[
  60. {
  61. type: 'pie',
  62. silent:1,
  63. radius:["35%", '75%'],
  64. center: ["50%", '55%'],
  65. label:{
  66. show:true,
  67. formatter:"{c}",
  68. fontSize:10,
  69. position:"inside",
  70. color:'#ffffff',
  71. },
  72. data: list,
  73. },
  74. ]
  75. }
  76. },
  77. },
  78. })