index.js 7.9 KB

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