YXXSWGJTSFX.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. dateType: "15-30天",
  20. enddate: new Date().toISOString().split('T')[0],
  21. where: {},
  22. pageNumber: 1,
  23. pageSize: 20,
  24. pageTotal: 1
  25. }
  26. },
  27. methods: {
  28. async getList(init = false) {
  29. if (init.detail != undefined) init = init.detail;
  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. if (init) {
  43. content.pageNumber = 1;
  44. content.pageSize = 20;
  45. }
  46. if (content.pageNumber > content.pageTotal) return;
  47. _Http.basic({
  48. "id": 20231015130604,
  49. content
  50. }).then(res => {
  51. console.log("有效线索未跟进天数分析", res)
  52. this.selectComponent('#ListBox').automaticSetHei();
  53. this.selectComponent('#ListBox').RefreshToComplete();
  54. if (res.code != '1') return wx.showToast({
  55. title: res.data,
  56. icon: "none"
  57. })
  58. this.setData({
  59. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  60. "content.pageNumber": res.pageNumber + 1,
  61. "content.pageSize": res.pageSize,
  62. "content.pageTotal": res.pageTotal,
  63. "total": res.total,
  64. })
  65. if (init) this.initChart(res.data[0].trend)
  66. })
  67. },
  68. initChart(data) {
  69. const colors = ['#6395FA'],
  70. getMapText = getApp().globalData.Language.getMapText;
  71. let that = this,
  72. countDown = null;
  73. function changeDateType(params) {
  74. clearTimeout(countDown)
  75. countDown = setTimeout(() => {
  76. let data = that.data.list[0].trend.find(v => getMapText(v.key) === getMapText(params.name));
  77. console.log("data", data)
  78. if (data.key === that.data.content.dateType) return;
  79. that.setData({
  80. "content.dateType": data.key,
  81. "content.pageNumber": 1,
  82. })
  83. that.getList();
  84. }, 200)
  85. }
  86. let legend = [getMapText('线索数')],
  87. series = [{
  88. name: getMapText('线索数'),
  89. type: 'bar',
  90. data: data.map(v => v.value),
  91. smooth: true
  92. }]
  93. const option = {
  94. color: colors,
  95. tooltip: {
  96. trigger: 'axis',
  97. confine: true, // Ensure tooltip stays within the chart area
  98. formatter: function (params) {
  99. changeDateType(params[0])
  100. return params.map((item, index) =>
  101. `${index === 0 ? item.axisValue + '\n' : ''}${item.marker}${item.seriesName}: ${item.value}`
  102. ).join('\n');
  103. },
  104. textStyle: {
  105. fontSize: 10, // Reduced font size
  106. lineHeight: 14 // Adjusted line height for smaller tooltip height
  107. }
  108. },
  109. legend: {
  110. data: legend,
  111. left: 'left' // Display legend on the left
  112. },
  113. xAxis: [{
  114. type: 'category',
  115. axisTick: {
  116. alignWithLabel: true
  117. },
  118. data: data.map(v => getMapText(v.key)),
  119. axisLabel: {
  120. interval: 0,
  121. rotate: 45
  122. }
  123. }],
  124. yAxis: [{
  125. type: 'value',
  126. position: 'left',
  127. axisLine: {
  128. show: true,
  129. },
  130. axisLabel: {
  131. formatter: '{value}'
  132. },
  133. splitLine: {
  134. lineStyle: {
  135. type: 'dashed' // Dashed grid lines for better readability
  136. }
  137. }
  138. }],
  139. series: series.map(item => ({
  140. ...item,
  141. label: {
  142. show: true,
  143. position: 'inside', // Display the label inside the bar
  144. formatter: '{c}', // Show the value of the bar
  145. fontSize: 10, // Adjust font size for better readability
  146. color: '#FFFFFF' // Set font color to white
  147. }
  148. }))
  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. })