AnalysisOfLeadConversion.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../utils/currency"),
  3. CNY = (value, symbol = "¥", precision = 2) => currency(value, {
  4. symbol,
  5. precision
  6. }).format();
  7. import * as echarts from '../../ec-canvas/echarts';
  8. Component({
  9. properties: {
  10. },
  11. options: {
  12. addGlobalClass: true
  13. },
  14. lifetimes: {
  15. attached: function () {
  16. getApp().globalData.Language.getLanguagePackage(this)
  17. this.setData({
  18. "content.dataid": wx.getStorageSync('userMsg').userid,
  19. "content.username": wx.getStorageSync('userMsg').name,
  20. })
  21. }
  22. },
  23. data: {
  24. "content": {
  25. enddate: new Date().toISOString().split('T')[0],
  26. where: {}
  27. },
  28. },
  29. methods: {
  30. async getList(init = false) {
  31. let content = this.data.content
  32. const {
  33. dataid,
  34. type,
  35. username,
  36. isleave
  37. } = getCurrentPages()[getCurrentPages().length - 1].data;
  38. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  39. content.dataid = dataid;
  40. content.type = type;
  41. content.username = username;
  42. content.where.isleave = isleave;
  43. _Http.basic({
  44. "id": 20231015124404,
  45. content
  46. }).then(res => {
  47. console.log("近12月线索转化分析", res)
  48. if (res.code != '1') return wx.showToast({
  49. title: res.data,
  50. icon: "none"
  51. })
  52. this.initChart(res.data.histogram.concat(res.data.lineChart), res.data.lineChart.map(v => v.date))
  53. })
  54. },
  55. initChart(data, dates) {
  56. console.log("data", data)
  57. let dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  58. getMapText = getApp().globalData.Language.getMapText,
  59. list = [{
  60. name: "转化总次数",
  61. color: "#6395F9"
  62. }, {
  63. name: "转化项目次数",
  64. color: "#62DAAB"
  65. }, {
  66. name: "转化客户次数",
  67. color: "#657797"
  68. }, {
  69. name: "总次数同比增长率",
  70. color: "#F6C022"
  71. }];
  72. list.map(item => {
  73. item.data = data.filter(v => v.key == item.name).map(v => v.value)
  74. return item
  75. })
  76. console.log("list", list)
  77. const option = {
  78. tooltip: {
  79. trigger: 'axis',
  80. confine: true,
  81. formatter: function (params) {
  82. let tooltipText = '';
  83. params.forEach((item, index) => {
  84. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.seriesName == getMapText('总次数同比增长率') ? (item.value * 100).toFixed(2) :item.value}${item.seriesName == getMapText('总次数同比增长率') ? '%' : ''}\n`;
  85. });
  86. return tooltipText;
  87. },
  88. textStyle: {
  89. fontSize: 10,
  90. }
  91. },
  92. legend: {
  93. data: list.map(v => getMapText(v.name)),
  94. top: '0rpx', // Moved legend position upwards by 10rpx
  95. textStyle: {
  96. fontSize: 12 // Reduced font size for legend text
  97. }
  98. },
  99. grid: {
  100. top: '32%', // Adjust grid top to leave space for the legend
  101. left: '3%',
  102. right: '4%',
  103. bottom: '3%',
  104. containLabel: true
  105. },
  106. xAxis: {
  107. type: 'category',
  108. boundaryGap: false,
  109. data: dates,
  110. axisLabel: {
  111. interval: 0, // Force display all labels
  112. rotate: 45, // Rotate labels to prevent overlap
  113. fontSize: 10 // Reduced font size for X-axis labels
  114. }
  115. },
  116. yAxis: {
  117. type: 'value',
  118. axisLabel: {
  119. fontSize: 10 // Reduced font size for Y-axis labels
  120. }
  121. },
  122. series: list.map(v => {
  123. return {
  124. name: getMapText(v.name),
  125. type: 'line',
  126. data: v.data,
  127. smooth: true, // Enable smooth transition for line charts
  128. itemStyle: {
  129. color: v.color
  130. },
  131. lineStyle: {
  132. color: v.color
  133. }
  134. }
  135. })
  136. };
  137. this.chartComponent = this.selectComponent('#mychart');
  138. this.chartComponent.init((canvas, width, height, dpr) => {
  139. const chart = echarts.init(canvas, null, {
  140. width,
  141. height,
  142. devicePixelRatio: dpr
  143. });
  144. chart.setOption(option);
  145. return chart;
  146. });
  147. },
  148. changeDate({
  149. detail
  150. }) {
  151. this.setData({
  152. "content.enddate": detail
  153. })
  154. this.getList(true)
  155. },
  156. showExplain(e) {
  157. const {
  158. name
  159. } = e.currentTarget.dataset;
  160. getApp().globalData.Language.modeBoxPrompts(getApp().globalData.Language.getMapText('统计到当前查询时间为止的') + name + "(" + getApp().globalData.Language.getMapText('审核状态') + ")")
  161. },
  162. }
  163. })