index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. mode: {
  11. type: String
  12. }
  13. },
  14. options: {
  15. addGlobalClass: true
  16. },
  17. lifetimes: {
  18. attached: function () {
  19. getApp().globalData.Language.getLanguagePackage(this)
  20. this.setData({
  21. "content.dataid": wx.getStorageSync('userMsg').userid,
  22. "content.username": wx.getStorageSync('userMsg').name,
  23. })
  24. }
  25. },
  26. data: {
  27. year: new Date().getFullYear().toString(),
  28. "content": {
  29. year: new Date().getFullYear().toString(),
  30. where: {}
  31. },
  32. isbooked: 0,
  33. },
  34. methods: {
  35. async getList(init = false) {
  36. let content = this.data.content
  37. const {
  38. dataid,
  39. type,
  40. username,
  41. isleave
  42. } = getCurrentPages()[getCurrentPages().length - 1].data;
  43. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  44. content.dataid = dataid;
  45. content.type = type;
  46. content.username = username;
  47. content.where.isleave = isleave;
  48. if (this.properties.mode == '出货趋势分析') content.isbooked = this.data.isbooked;
  49. let ids = {
  50. '订单趋势分析': 20231012094804,
  51. '出货趋势分析': 20231012152004,
  52. '开票金额趋势分析': 20231016095304
  53. }
  54. _Http.basic({
  55. "id": ids[this.properties.mode],
  56. content
  57. }).then(res => {
  58. console.log(this.properties.mode, res)
  59. if (res.code != '1') return wx.showToast({
  60. title: res.data,
  61. icon: "none"
  62. })
  63. this.initChart(res.data)
  64. })
  65. },
  66. onCheckboxChange(e) {
  67. this.setData({
  68. isbooked: this.data.isbooked == 0 ? 1 : 0
  69. })
  70. this.getList(true)
  71. },
  72. initChart(data) {
  73. const dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  74. colors = ['#6CD2A1', '#5F9DFC', '#ECB937', '#F69240'],
  75. getMapText = getApp().globalData.Language.getMapText;
  76. let legend = [`${getMapText('去年同期金额')}(${getMapText('万元')})`, `${getMapText('本期金额')}(${getMapText('万元')})`, `${getMapText('同比增长率')}`],
  77. series = [{
  78. name: `${getMapText('去年同期金额')}(${getMapText('万元')})`,
  79. type: 'bar',
  80. data: data.map(v => (v.oldamount / dividend).toFixed(2)),
  81. smooth: true
  82. },
  83. {
  84. name: `${getMapText('本期金额')}(${getMapText('万元')})`,
  85. type: 'bar',
  86. yAxisIndex: 1,
  87. data: data.map(v => (v.amount / dividend).toFixed(2)),
  88. smooth: true
  89. },
  90. {
  91. name: getMapText('同比增长率'),
  92. type: 'line',
  93. yAxisIndex: 2,
  94. data: data.map(v => (v.tbzzl * 100).toFixed(2)),
  95. smooth: true
  96. }
  97. ]
  98. if (this.properties.mode == '出货趋势分析') {
  99. legend.push(getMapText('准交率'))
  100. series.push({
  101. name: getMapText('准交率'),
  102. type: 'line',
  103. yAxisIndex: 2,
  104. data: data.map(v => (v.zjl * 100).toFixed(2)),
  105. smooth: true
  106. })
  107. }
  108. const option = {
  109. color: colors,
  110. tooltip: {
  111. trigger: 'axis',
  112. confine: true, // Ensure tooltip stays within the chart area
  113. formatter: function (params) {
  114. let tooltipText = '';
  115. params.forEach((item, index) => {
  116. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.value}${item.seriesName == getMapText('同比增长率')||item.seriesName == getMapText('准交率') ? '%' : ''}\n`;
  117. });
  118. return tooltipText;
  119. },
  120. textStyle: {
  121. fontSize: 10, // Reduced font size
  122. lineHeight: 14 // Adjusted line height for smaller tooltip height
  123. }
  124. },
  125. legend: {
  126. data: legend
  127. },
  128. xAxis: [{
  129. type: 'category',
  130. axisTick: {
  131. alignWithLabel: true
  132. },
  133. data: data.map(v => v.date),
  134. axisLabel: {
  135. interval: 0,
  136. rotate: 45
  137. }
  138. }],
  139. yAxis: [{
  140. type: 'value',
  141. name: '',
  142. position: 'right',
  143. offset: 80,
  144. alignTicks: true,
  145. axisLine: {
  146. show: true,
  147. },
  148. axisLabel: {
  149. formatter: '{value}'
  150. }
  151. },
  152. {
  153. type: 'value',
  154. name: '',
  155. position: 'left',
  156. alignTicks: true,
  157. axisLine: {
  158. show: false,
  159. },
  160. axisLabel: {
  161. formatter: '{value}',
  162. rotate: 45
  163. }
  164. },
  165. {
  166. type: 'value',
  167. name: '',
  168. position: 'right',
  169. alignTicks: true,
  170. offset: 80,
  171. axisLine: {
  172. show: false,
  173. lineStyle: {
  174. color: colors[1]
  175. }
  176. },
  177. axisLabel: {
  178. formatter: '{value}'
  179. }
  180. },
  181. ],
  182. series
  183. };
  184. this.chartComponent = this.selectComponent('#mychart');
  185. this.chartComponent.init((canvas, width, height, dpr) => {
  186. const chart = echarts.init(canvas, null, {
  187. width,
  188. height,
  189. devicePixelRatio: dpr
  190. });
  191. chart.setOption(option);
  192. return chart;
  193. });
  194. },
  195. changeDate({
  196. detail
  197. }) {
  198. this.setData({
  199. "content.year": detail
  200. })
  201. this.getList(true)
  202. },
  203. }
  204. })