followUpAnalysis.js 6.1 KB

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