ReportAnalysis.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. const _Http = getApp().globalData.http;
  2. import * as echarts from '../../ec-canvas/echarts';
  3. Component({
  4. options: {
  5. addGlobalClass: true
  6. },
  7. lifetimes: {
  8. attached: function () {
  9. getApp().globalData.Language.getLanguagePackage(this)
  10. this.setData({
  11. "content.dataid": wx.getStorageSync('userMsg').userid,
  12. "content.username": wx.getStorageSync('userMsg').name,
  13. })
  14. }
  15. },
  16. data: {
  17. year: new Date().getFullYear().toString(),
  18. "content": {
  19. enddate: new Date().toISOString().split('T')[0],
  20. where: {}
  21. }
  22. },
  23. methods: {
  24. async getList(init = false) {
  25. let content = this.data.content
  26. const {
  27. dataid,
  28. type,
  29. username,
  30. isleave
  31. } = getCurrentPages()[getCurrentPages().length - 1].data;
  32. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  33. content.dataid = dataid;
  34. content.type = type;
  35. content.username = username;
  36. content.where.isleave = isleave;
  37. _Http.basic({
  38. "id": 20231018160504,
  39. content
  40. }).then(res => {
  41. if (res.code != '1') return wx.showToast({
  42. title: res.data,
  43. icon: "none"
  44. })
  45. this.initChart(res.data)
  46. })
  47. },
  48. initChart(data) {
  49. console.log("data", data)
  50. const colors = ['#6CD2A1', '#5F9DFC', '#ECB937', '#F69240'],
  51. getMapText = getApp().globalData.Language.getMapText;
  52. let legend = [getMapText('去年同期报备'), getMapText('本期报备'), `${getMapText('同比增长率')}`],
  53. series = [{
  54. name: getMapText('去年同期报备'),
  55. type: 'bar',
  56. data: data.histogram.filter(v => v.type == '去年同期报备' || v.key == '去年同期报备').map(v => v.value),
  57. smooth: true
  58. },
  59. {
  60. name: getMapText('本期报备'),
  61. type: 'bar',
  62. yAxisIndex: 1,
  63. data: data.histogram.filter(v => v.type == '本期报备' || v.key == '本期报备').map(v => v.value),
  64. smooth: true
  65. },
  66. {
  67. name: getMapText('同比增长率'),
  68. type: 'line',
  69. yAxisIndex: 2,
  70. data: data.lineChart.map(v => v.value),
  71. smooth: true
  72. }
  73. ]
  74. const option = {
  75. color: colors,
  76. tooltip: {
  77. trigger: 'axis',
  78. confine: true, // Ensure tooltip stays within the chart area
  79. formatter: function (params) {
  80. let tooltipText = '';
  81. params.forEach((item, index) => {
  82. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.value}${item.seriesName == getMapText('同比增长率')||item.seriesName == getMapText('准交率') ? '%' : ''}\n`;
  83. });
  84. return tooltipText;
  85. },
  86. textStyle: {
  87. fontSize: 10, // Reduced font size
  88. lineHeight: 14 // Adjusted line height for smaller tooltip height
  89. }
  90. },
  91. legend: {
  92. data: legend
  93. },
  94. xAxis: [{
  95. type: 'category',
  96. axisTick: {
  97. alignWithLabel: true
  98. },
  99. data: data.lineChart.map(v => v.date),
  100. axisLabel: {
  101. interval: 0,
  102. rotate: 45
  103. }
  104. }],
  105. yAxis: [{
  106. type: 'value',
  107. name: '',
  108. position: 'right',
  109. offset: 80,
  110. alignTicks: true,
  111. axisLine: {
  112. show: true,
  113. },
  114. axisLabel: {
  115. formatter: '{value}'
  116. }
  117. },
  118. {
  119. type: 'value',
  120. name: '',
  121. position: 'left',
  122. alignTicks: true,
  123. axisLine: {
  124. show: false,
  125. },
  126. axisLabel: {
  127. formatter: '{value}',
  128. rotate: 45
  129. }
  130. },
  131. {
  132. type: 'value',
  133. name: '',
  134. position: 'right',
  135. alignTicks: true,
  136. offset: 80,
  137. axisLine: {
  138. show: false,
  139. lineStyle: {
  140. color: colors[1]
  141. }
  142. },
  143. axisLabel: {
  144. formatter: '{value}'
  145. }
  146. },
  147. ],
  148. series
  149. };
  150. this.chartComponent = this.selectComponent('#mychart');
  151. this.chartComponent.init((canvas, width, height, dpr) => {
  152. const chart = echarts.init(canvas, null, {
  153. width,
  154. height,
  155. devicePixelRatio: dpr
  156. });
  157. chart.setOption(option);
  158. return chart;
  159. });
  160. },
  161. changeDate({
  162. detail
  163. }) {
  164. this.setData({
  165. "content.enddate": detail
  166. })
  167. this.getList(true)
  168. },
  169. }
  170. })