index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. unwriteoffamounttype: "订单",
  25. where: {}
  26. },
  27. pages: {
  28. pageNumber: 1,
  29. pageTotal: 1,
  30. pageSize: 20
  31. },
  32. list: []
  33. },
  34. methods: {
  35. async getList(init = false) {
  36. if (init.detail != undefined) init = init.detail;
  37. let content = this.data.content,
  38. pages = this.data.pages;
  39. const {
  40. dataid,
  41. type,
  42. username,
  43. isleave
  44. } = getCurrentPages()[getCurrentPages().length - 1].data;
  45. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  46. content.dataid = dataid;
  47. content.type = type;
  48. content.username = username;
  49. content.where.isleave = isleave;
  50. if (init) {
  51. pages.pageNumber = 1;
  52. pages.pageTotal = 1;
  53. }
  54. if (pages.pageNumber <= pages.pageTotal) _Http.basic({
  55. "id": 20231017084504,
  56. content: Object.assign(content, pages)
  57. }).then(res => {
  58. console.log("回款分析", res)
  59. this.selectComponent('#ListBox').RefreshToComplete();
  60. if (res.code != '1') return wx.showToast({
  61. title: res.data,
  62. icon: "none"
  63. })
  64. res.data = res.data.map(v => {
  65. v.zerotothree = CNY(v.zerotothree)
  66. v.threetosix = CNY(v.threetosix)
  67. v.sixtotwelve = CNY(v.sixtotwelve)
  68. v.twelveup = CNY(v.twelveup)
  69. v.total = CNY(v.total)
  70. return v
  71. })
  72. pages.pageNumber++;
  73. pages.pageTotal = res.pageTotal;
  74. this.setData({
  75. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  76. pages
  77. })
  78. })
  79. if (init) _Http.basic({
  80. "id": 20231016211904,
  81. content
  82. }).then(res => {
  83. console.log("回款分析图表", res)
  84. if (res.code != '1') return wx.showToast({
  85. title: res.data,
  86. icon: "none"
  87. })
  88. this.initChart(res.data)
  89. })
  90. },
  91. toDetail(e) {
  92. let content = this.data.content;
  93. content.sys_enterpriseid = e.currentTarget.dataset.item.sys_enterpriseid;
  94. content.enterprisename = e.currentTarget.dataset.item.enterprisename;
  95. wx.navigateTo({
  96. url: '/salesPanel/FinancialCollectionAnalysis/detail?content=' + JSON.stringify(content)
  97. })
  98. },
  99. initChart(data) {
  100. let dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  101. list = [{
  102. name: "0-3月未回款金额(万元)",
  103. color: "#5B8FF9"
  104. }, {
  105. name: "3-6月未回款金额(万元)",
  106. color: "#5AD8A6"
  107. }, {
  108. name: "6-12月未回款金额(万元)",
  109. color: "#5D7092"
  110. }, {
  111. name: "12月以上未回款金额(万元)",
  112. color: "#F6BD16"
  113. }];
  114. let series = list.map(item => ({
  115. name: getApp().globalData.Language.getMapText(item.name),
  116. type: 'bar',
  117. stack: 'total',
  118. label: {
  119. show: true
  120. },
  121. emphasis: {
  122. focus: 'series'
  123. },
  124. itemStyle: {
  125. color: item.color
  126. },
  127. data: ['订单', '出货', '开票'].map(type => {
  128. let filtered = data.filter(d => d.type === type && d.key.includes(item.name.split('(')[0]));
  129. return filtered.length ? (filtered[0].value / dividend).toFixed(2) : 0;
  130. })
  131. }));
  132. let option = {
  133. tooltip: {
  134. trigger: 'axis',
  135. confine: true, // Ensure tooltip stays within the chart area
  136. formatter: function (params) {
  137. let tooltipText = '';
  138. changeUnwriteoffamounttype(['订单', '出货', '开票'][params[0].dataIndex])
  139. params.forEach((item, index) => {
  140. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.value}\n`;
  141. });
  142. return tooltipText;
  143. },
  144. textStyle: {
  145. fontSize: 10,
  146. }
  147. },
  148. legend: {
  149. data: list.map(item => getApp().globalData.Language.getMapText(item.name))
  150. },
  151. grid: {
  152. left: '3%',
  153. right: '4%',
  154. bottom: '3%',
  155. containLabel: true
  156. },
  157. xAxis: {
  158. type: 'value'
  159. },
  160. yAxis: {
  161. type: 'category',
  162. data: ['订单', '出货', '开票'].map(v => getApp().globalData.Language.getMapText(v))
  163. },
  164. series
  165. };
  166. let countDown = null,
  167. that = this;
  168. function changeUnwriteoffamounttype(type) {
  169. if (countDown) return;
  170. countDown = setTimeout(() => {
  171. clearTimeout(countDown)
  172. countDown = null;
  173. if (type != that.data.content.unwriteoffamounttype) {
  174. that.setData({
  175. "content.unwriteoffamounttype": type,
  176. "pages.pageNumber": 1
  177. })
  178. }
  179. that.getList()
  180. }, 200)
  181. };
  182. this.chartComponent = this.selectComponent('#mychart');
  183. this.chartComponent.init((canvas, width, height, dpr) => {
  184. const chart = echarts.init(canvas, null, {
  185. width,
  186. height,
  187. devicePixelRatio: dpr
  188. });
  189. chart.setOption(option);
  190. return chart;
  191. });
  192. },
  193. changeDate({
  194. detail
  195. }) {
  196. this.setData({
  197. "content.enddate": detail
  198. })
  199. this.getList(true)
  200. },
  201. showExplain(e) {
  202. const {
  203. name
  204. } = e.currentTarget.dataset;
  205. getApp().globalData.Language.modeBoxPrompts(getApp().globalData.Language.getMapText('统计到当前查询时间为止的') + name + "(" + getApp().globalData.Language.getMapText('审核状态') + ")")
  206. },
  207. }
  208. })