ClientQuotationQuantity.js 5.8 KB

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