index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 = [
  12. {name:"已使用",data:[{name:"2022",value:35,},{name:"2021",value:30,},{name:"2020",value:20,},{name:"2019",value:30,}]},
  13. {name:"未使用",data:[{name:"2022",value:50,},{name:"2021",value:30,},{name:"2020",value:30,},{name:"2019",value:30,}]},
  14. {name:"不良率",data:[{name:"2022",value:10,},{name:"2021",value:5,},{name:"2020",value:10,},{name:"2019",value:10,}]},
  15. ]
  16. this.initChart(list);
  17. }
  18. },
  19. moved: function () { },
  20. detached: function () { },
  21. },
  22. properties:{
  23. prductIndex:{
  24. type:String,
  25. value:'',
  26. }
  27. },
  28. observers:{
  29. 'prductIndex':function(nv,ol){
  30. var token = wx.getStorageSync('token');
  31. if(token && nv){
  32. this.getYearStatusStateList(nv);
  33. }
  34. }
  35. },
  36. methods:{
  37. getYearStatusStateList(productName){
  38. app.requestP({
  39. url: '/daping/yearStatusState?productName=',
  40. method: 'post',
  41. }).then(res=>{
  42. console.log(res.data.data);
  43. var yearType = [{name:'已使用',type:'use'},{name:'未使用',type:'unuse'},{name:'不良率',type:'fail'}];
  44. var datas = [];
  45. for (var index = 0; index < yearType.length; index++) {
  46. var types = [];
  47. res.data.data.map((item,i)=>{
  48. types.push({
  49. name:item.year,value:item[yearType[index].type],
  50. })
  51. if(i == res.data.data.length-1){
  52. datas.push(
  53. {name:yearType[index].name, data:types}
  54. )
  55. }
  56. })
  57. }
  58. this.initChart(datas)
  59. })
  60. },
  61. initChart(list){
  62. var that = this;
  63. that.selectComponent('#chartConDom').init((canvas, width, height, dpr) => {
  64. const chart = echarts.init(canvas, null, {
  65. width: width,
  66. height: height,
  67. devicePixelRatio: dpr
  68. });
  69. var option = that.getOrderWarnOption(list);
  70. chart.setOption(option);
  71. return chart;
  72. });
  73. },
  74. getOrderWarnOption(list){
  75. var fontSize = 10
  76. var fontColor = "#999999"
  77. return {
  78. color:["#2D59E6","#7FD1FF","#E1291C","#2D59E6"],
  79. title:{
  80. text:"历年所有试剂的数据",
  81. show:0,
  82. textStyle:{
  83. color:fontColor,
  84. fontSize:fontSize,
  85. },
  86. left:'15%',
  87. top:0,
  88. },
  89. grid: {
  90. top: '20%',
  91. left: '6%',
  92. right: '4%',
  93. bottom: '3%',
  94. containLabel: true
  95. },
  96. tooltip: {
  97. trigger: 'axis',
  98. axisPointer: {
  99. type: 'cross',
  100. }
  101. },
  102. legend:{
  103. icon:"circle",
  104. right:'auto',
  105. top:0,
  106. itemWidth:fontSize*0.8,
  107. itemHeight:fontSize,
  108. textStyle:{
  109. fontSize:fontSize,
  110. color:fontColor,
  111. },
  112. data:list.map(item=>item.name)
  113. },
  114. yAxis: [
  115. {
  116. type: 'value',
  117. name:"",
  118. splitNumber:5,
  119. axisTick:{show:false,},
  120. axisLabel:{
  121. fontSize:fontSize,
  122. color:fontColor,
  123. },
  124. nameTextStyle:{
  125. fontSize:fontSize,
  126. color:fontColor,
  127. },
  128. nameGap:5,
  129. },
  130. {
  131. type: 'value',
  132. position: 'right',
  133. splitNumber:5,
  134. boundaryGap:[0,1],
  135. name:"%",
  136. axisTick:{show:false,},
  137. splitLine:{show:false,},
  138. axisLabel:{
  139. fontSize:fontSize,
  140. color:fontColor,
  141. },
  142. nameTextStyle:{
  143. fontSize:fontSize,
  144. color:fontColor,
  145. },
  146. nameGap:5,
  147. },
  148. ],
  149. xAxis: {
  150. type: 'category',
  151. // boundaryGap: false,
  152. axisTick:{show:false,},
  153. axisLabel:{
  154. fontSize:fontSize,
  155. color:fontColor,
  156. },
  157. data: list.length? list[0].data.map(item=>item.name) : []
  158. },
  159. series:this.setOptItem(list),
  160. }
  161. },
  162. setOptItem(list){
  163. var data = []
  164. var fontSize = 10
  165. for(var i in list){
  166. if(i==2){
  167. data.push({
  168. type: 'line',
  169. name:"%",
  170. silent:1,
  171. yAxisIndex: 1,
  172. barMaxWidth:fontSize*1.5,
  173. name:list[i].name,
  174. data:list[i].data
  175. })
  176. }else{
  177. data.push({
  178. type: 'bar',
  179. stack: 'Total',
  180. name:"千万",
  181. silent:1,
  182. barMaxWidth:fontSize*1.5,
  183. name:list[i].name,
  184. data:list[i].data
  185. })
  186. }
  187. }
  188. return data
  189. },
  190. },
  191. })