ProjectQuotationQuantity.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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": 20231018161604,
  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)
  53. })
  54. },
  55. initChart(data) {
  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. dates = [...new Set(data.map(v => v.date))]; // Use Set to remove duplicates
  67. list.map(item => {
  68. item.data = data.filter(v => v.key == item.name).map(v => v.value)
  69. return item
  70. })
  71. console.log("list", list)
  72. const option = {
  73. tooltip: {
  74. trigger: 'axis',
  75. confine: true,
  76. formatter: function (params) {
  77. let tooltipText = '';
  78. params.forEach((item, index) => {
  79. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.seriesName == getMapText('总次数同比增长率') ? (item.value * 100).toFixed(2) :item.value}${item.seriesName == getMapText('总次数同比增长率') ? '%' : ''}\n`;
  80. });
  81. return tooltipText;
  82. },
  83. textStyle: {
  84. fontSize: 10,
  85. }
  86. },
  87. legend: {
  88. data: list.map(v => getMapText(v.name)),
  89. top: '0rpx', // Moved legend position upwards by 10rpx
  90. textStyle: {
  91. fontSize: 12 // Reduced font size for legend text
  92. }
  93. },
  94. grid: {
  95. top: '15%', // Adjust grid top to leave space for the legend
  96. left: '3%',
  97. right: '4%',
  98. bottom: '3%',
  99. containLabel: true
  100. },
  101. xAxis: {
  102. type: 'category',
  103. boundaryGap: false,
  104. data: dates,
  105. axisLabel: {
  106. interval: 0, // Force display all labels
  107. rotate: 45, // Rotate labels to prevent overlap
  108. fontSize: 10 // Reduced font size for X-axis labels
  109. }
  110. },
  111. yAxis: {
  112. type: 'value',
  113. axisLabel: {
  114. fontSize: 10 // Reduced font size for Y-axis labels
  115. }
  116. },
  117. series: list.map(v => {
  118. return {
  119. name: getMapText(v.name),
  120. type: 'line',
  121. stack: 'Total',
  122. data: v.data,
  123. smooth: true, // Enable smooth transition for line charts
  124. itemStyle: {
  125. color: v.color
  126. },
  127. lineStyle: {
  128. color: v.color
  129. }
  130. }
  131. })
  132. };
  133. this.chartComponent = this.selectComponent('#mychart');
  134. this.chartComponent.init((canvas, width, height, dpr) => {
  135. const chart = echarts.init(canvas, null, {
  136. width,
  137. height,
  138. devicePixelRatio: dpr
  139. });
  140. chart.setOption(option);
  141. return chart;
  142. });
  143. },
  144. changeDate({
  145. detail
  146. }) {
  147. this.setData({
  148. "content.enddate": detail
  149. })
  150. this.getList(true)
  151. },
  152. showExplain(e) {
  153. const {
  154. name
  155. } = e.currentTarget.dataset;
  156. getApp().globalData.Language.modeBoxPrompts(getApp().globalData.Language.getMapText('统计到当前查询时间为止的') + name + "(" + getApp().globalData.Language.getMapText('审核状态') + ")")
  157. },
  158. }
  159. })