YXXSWGJTSFX.js 6.2 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. 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').RefreshToComplete();
  53. if (res.code != '1') return wx.showToast({
  54. title: res.data,
  55. icon: "none"
  56. })
  57. this.setData({
  58. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  59. "content.pageNumber": res.pageNumber + 1,
  60. "content.pageSize": res.pageSize,
  61. "content.pageTotal": res.pageTotal,
  62. "total": res.total,
  63. })
  64. if (init) this.initChart(res.data[0].trend)
  65. })
  66. },
  67. initChart(data) {
  68. const colors = ['#6395FA'],
  69. getMapText = getApp().globalData.Language.getMapText;
  70. let that = this,
  71. countDown = null;
  72. function changeDateType(params) {
  73. clearTimeout(countDown)
  74. countDown = setTimeout(() => {
  75. let data = that.data.list[0].trend.find(v => getMapText(v.key) === getMapText(params.name));
  76. console.log("data", data)
  77. if (data.key === that.data.content.dateType) return;
  78. that.setData({
  79. "content.dateType": data.key,
  80. "content.pageNumber": 1,
  81. })
  82. that.getList();
  83. }, 200)
  84. }
  85. let legend = [getMapText('线索数')],
  86. series = [{
  87. name: getMapText('线索数'),
  88. type: 'bar',
  89. data: data.map(v => v.value),
  90. smooth: true
  91. }]
  92. const option = {
  93. color: colors,
  94. tooltip: {
  95. trigger: 'axis',
  96. confine: true, // Ensure tooltip stays within the chart area
  97. formatter: function (params) {
  98. changeDateType(params[0])
  99. return params.map((item, index) =>
  100. `${index === 0 ? item.axisValue + '\n' : ''}${item.marker}${item.seriesName}: ${item.value}`
  101. ).join('\n');
  102. },
  103. textStyle: {
  104. fontSize: 10, // Reduced font size
  105. lineHeight: 14 // Adjusted line height for smaller tooltip height
  106. }
  107. },
  108. legend: {
  109. data: legend,
  110. left: 'left' // Display legend on the left
  111. },
  112. xAxis: [{
  113. type: 'category',
  114. axisTick: {
  115. alignWithLabel: true
  116. },
  117. data: data.map(v => getMapText(v.key)),
  118. axisLabel: {
  119. interval: 0,
  120. rotate: 45
  121. }
  122. }],
  123. yAxis: [{
  124. type: 'value',
  125. position: 'left',
  126. axisLine: {
  127. show: true,
  128. },
  129. axisLabel: {
  130. formatter: '{value}'
  131. },
  132. splitLine: {
  133. lineStyle: {
  134. type: 'dashed' // Dashed grid lines for better readability
  135. }
  136. }
  137. }],
  138. series: series.map(item => ({
  139. ...item,
  140. label: {
  141. show: true,
  142. position: 'inside', // Display the label inside the bar
  143. formatter: '{c}', // Show the value of the bar
  144. fontSize: 10, // Adjust font size for better readability
  145. color: '#FFFFFF' // Set font color to white
  146. }
  147. }))
  148. };
  149. this.chartComponent = this.selectComponent('#mychart');
  150. this.chartComponent.init((canvas, width, height, dpr) => {
  151. const chart = echarts.init(canvas, null, {
  152. width,
  153. height,
  154. devicePixelRatio: dpr
  155. });
  156. chart.setOption(option);
  157. return chart;
  158. });
  159. },
  160. changeDate({
  161. detail
  162. }) {
  163. this.setData({
  164. "content.enddate": detail
  165. })
  166. this.getList(true)
  167. },
  168. }
  169. })