index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.getProductTypeStateList();
  12. }else{
  13. var list = [{name:"生化诊断",value:50,},{name:"免疫诊断",value:30,},{name:"分子诊断",value:30,},{name:"血液检测",value:30,}]
  14. this.init(list);
  15. }
  16. },
  17. moved: function () { },
  18. detached: function () { },
  19. },
  20. methods:{
  21. getProductTypeStateList(){
  22. app.requestP({
  23. url: '/daping/productTypeState',
  24. method: 'post',
  25. }).then(res=>{
  26. var statisticProductList = res.data.data.map(item=>{
  27. var name = item.product_type_name || 'N/A';
  28. name = name.length > 5 ? name.slice(0,2)+'...':name;
  29. return {...item,name,value:item.num}
  30. });
  31. this.init(statisticProductList);
  32. })
  33. },
  34. init(list){
  35. var that = this;
  36. that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => {
  37. const chart = echarts.init(canvas, null, {
  38. width: width,
  39. height: height,
  40. devicePixelRatio: dpr
  41. });
  42. var option = that.getOrderWarnOption(list);
  43. chart.setOption(option);
  44. return chart;
  45. });
  46. },
  47. getOrderWarnOption(list){
  48. var fontSize = 10
  49. var fontColor = "#999999"
  50. return {
  51. color:["#333FFF","#FFAE36"],
  52. title:{
  53. text:"产品分类信息",
  54. show:0,
  55. textStyle:{
  56. color:fontColor,
  57. fontSize:fontSize,
  58. },
  59. left:'center',
  60. top:0,
  61. },
  62. tooltip: {
  63. trigger: 'axis',
  64. axisPointer: {
  65. type: 'cross',
  66. }
  67. },
  68. grid: {
  69. top: '20%',
  70. left: '6%',
  71. right: '4%',
  72. bottom: '3%',
  73. containLabel: true
  74. },
  75. yAxis: {
  76. type: 'value',
  77. axisTick:{show:false,},
  78. axisLabel:{
  79. fontSize:fontSize,
  80. color:fontColor,
  81. },
  82. },
  83. xAxis: {
  84. type: 'category',
  85. axisTick:{show:false,},
  86. axisLabel:{
  87. fontSize:fontSize,
  88. color:fontColor,
  89. },
  90. axisLine:{
  91. lineStyle:{
  92. color:"#cccccc"
  93. }
  94. },
  95. data: list.map(item=>item.name)
  96. },
  97. series:[
  98. {
  99. type: 'bar',
  100. barMaxWidth:fontSize*1.5,
  101. data:list
  102. },
  103. ],
  104. }
  105. },
  106. },
  107. })