index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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": 20231016122504,
  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: "0-3月出货未开票金额(万元)",
  61. key: 'zerotothree',
  62. color: "#6395F9"
  63. }, {
  64. name: "3-6月出货未开票金额(万元)",
  65. key: 'threetosix',
  66. color: "#62DAAB"
  67. }, {
  68. name: "6-12月出货未开票金额(万元)",
  69. key: 'sixtotwelve',
  70. color: "#657797"
  71. }, {
  72. name: "一年以上出货未开票金额(万元)",
  73. key: 'twelveup',
  74. color: "#F6C022"
  75. }];
  76. // Format data values to keep two decimal places
  77. data = data.map(item => {
  78. let formattedItem = {
  79. ...item
  80. };
  81. list.forEach(v => {
  82. formattedItem[v.key] = (formattedItem[v.key]).toFixed(2);
  83. });
  84. return formattedItem;
  85. });
  86. const option = {
  87. tooltip: {
  88. trigger: 'axis',
  89. confine: true, // Ensure tooltip stays within the chart area
  90. formatter: function (params) {
  91. let tooltipText = '';
  92. params.forEach((item, index) => {
  93. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.value}${item.seriesName == getMapText('同比增长率') ? '%' : ''}\n`;
  94. });
  95. return tooltipText;
  96. },
  97. textStyle: {
  98. fontSize: 10, // Reduced font size
  99. // Adjusted line height for smaller tooltip height
  100. }
  101. },
  102. legend: {
  103. data: list.map(v => getMapText(v.name)),
  104. top: '0rpx', // Moved legend position upwards by 10rpx
  105. textStyle: {
  106. fontSize: 12 // Reduced font size for legend text
  107. }
  108. },
  109. grid: {
  110. top: '32%', // Adjust grid top to leave space for the legend
  111. left: '3%',
  112. right: '4%',
  113. bottom: '3%',
  114. containLabel: true
  115. },
  116. xAxis: {
  117. type: 'category',
  118. boundaryGap: false,
  119. data: data.map(v => v.date),
  120. axisLabel: {
  121. interval: 0, // Force display all labels
  122. rotate: 45, // Rotate labels to prevent overlap
  123. fontSize: 10 // Reduced font size for X-axis labels
  124. }
  125. },
  126. yAxis: {
  127. type: 'value',
  128. axisLabel: {
  129. fontSize: 10 // Reduced font size for Y-axis labels
  130. }
  131. },
  132. series: list.map(v => {
  133. return {
  134. name: getMapText(v.name),
  135. type: 'line',
  136. data: data.map(obj => (obj[v.key] / dividend).toFixed(2)),
  137. itemStyle: {
  138. color: v.color
  139. },
  140. lineStyle: {
  141. color: v.color
  142. }
  143. }
  144. })
  145. };
  146. this.chartComponent = this.selectComponent('#mychart');
  147. this.chartComponent.init((canvas, width, height, dpr) => {
  148. const chart = echarts.init(canvas, null, {
  149. width,
  150. height,
  151. devicePixelRatio: dpr
  152. });
  153. chart.setOption(option);
  154. return chart;
  155. });
  156. },
  157. changeDate({
  158. detail
  159. }) {
  160. this.setData({
  161. "content.enddate": detail
  162. })
  163. this.getList(true)
  164. },
  165. showExplain(e) {
  166. const {
  167. name
  168. } = e.currentTarget.dataset;
  169. getApp().globalData.Language.modeBoxPrompts(getApp().globalData.Language.getMapText('统计到当前查询时间为止的') + name + "(" + getApp().globalData.Language.getMapText('审核状态') + ")")
  170. },
  171. }
  172. })