followUpAnalysis.js 6.5 KB

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