index.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. accounts: [],
  29. accountno: "",
  30. },
  31. methods: {
  32. async getList(init = false) {
  33. let accounts = []
  34. if (!this.data.accounts.length) accounts = await _Http.basic({
  35. "id": 20221008134803,
  36. "content": {
  37. "isExport": 0,
  38. "pageNumber": 1,
  39. "pageSize": 100,
  40. "where": {
  41. "condition": ""
  42. }
  43. },
  44. })
  45. let content = this.data.content
  46. const {
  47. dataid,
  48. type,
  49. username,
  50. isleave
  51. } = getCurrentPages()[getCurrentPages().length - 1].data;
  52. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  53. content.dataid = dataid;
  54. content.type = type;
  55. content.username = username;
  56. content.where.isleave = isleave;
  57. let dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000;
  58. try {
  59. content.accountno = accounts.data[0].accountno
  60. this.setData({
  61. accounts: accounts.data.map(v => {
  62. if (Math.abs(v.balance) > dividend) {
  63. v.balance = CNY(v.balance / (wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000))
  64. v.conversion = true;
  65. } else {
  66. v.balance = CNY(v.balance)
  67. v.conversion = false;
  68. }
  69. v.remarks = v.accountname
  70. v.value = v.accountno
  71. return v
  72. }),
  73. content
  74. })
  75. } catch (error) {
  76. }
  77. _Http.basic({
  78. "id": 20231019151704,
  79. content
  80. }).then(res => {
  81. console.log("客户余额", res)
  82. this.selectComponent("#Filtrate").onCancel();
  83. if (res.code != '1') return wx.showToast({
  84. title: res.data,
  85. icon: "none"
  86. })
  87. this.setData({
  88. accounts: res.data.accountclass.map(v => {
  89. if (Math.abs(v.balance) > dividend) {
  90. v.balance = CNY(v.balance / (wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000))
  91. v.conversion = true;
  92. } else {
  93. v.balance = CNY(v.balance)
  94. v.conversion = false;
  95. }
  96. v.remarks = v.accountname
  97. v.value = v.accountno
  98. return v
  99. })
  100. })
  101. console.log("accounts", accounts)
  102. this.initChart(res.data)
  103. })
  104. },
  105. initChart(data) {
  106. const dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  107. colors = ['#6CD2A1', '#5F9DFC', '#ECB937'],
  108. getMapText = getApp().globalData.Language.getMapText;
  109. const option = {
  110. color: colors,
  111. tooltip: {
  112. trigger: 'axis',
  113. confine: true, // Ensure tooltip stays within the chart area
  114. formatter: function (params) {
  115. let tooltipText = '';
  116. params.forEach((item, index) => {
  117. tooltipText += `${index==0?item.axisValue+'\n':''}${item.marker}${item.seriesName}: ${item.value}${item.seriesName == getMapText('同比增长率') ? '%' : ''}\n`;
  118. });
  119. return tooltipText;
  120. },
  121. textStyle: {
  122. fontSize: 10, // Reduced font size
  123. lineHeight: 14 // Adjusted line height for smaller tooltip height
  124. }
  125. },
  126. legend: {
  127. data: [`${getMapText('去年同期金额')}(${getMapText('万元')})`, `${getMapText('本期金额')}(${getMapText('万元')})`, `${getMapText('同比增长率')}`],
  128. textStyle: {
  129. fontSize: 10 // Reduced font size for legend
  130. }
  131. },
  132. xAxis: [{
  133. type: 'category',
  134. axisTick: {
  135. alignWithLabel: true
  136. },
  137. data: data.tbzzl.map(v => v.date),
  138. axisLabel: {
  139. interval: 0,
  140. rotate: 45,
  141. fontSize: 10 // Reduced font size for x-axis labels
  142. }
  143. }],
  144. yAxis: [{
  145. type: 'value',
  146. name: '',
  147. position: 'right',
  148. offset: 80,
  149. alignTicks: true,
  150. axisLine: {
  151. show: true,
  152. },
  153. axisLabel: {
  154. formatter: '{value}',
  155. fontSize: 10 // Reduced font size for y-axis labels
  156. }
  157. },
  158. {
  159. type: 'value',
  160. name: '',
  161. position: 'left',
  162. alignTicks: true,
  163. axisLine: {
  164. show: false,
  165. },
  166. axisLabel: {
  167. formatter: '{value}',
  168. rotate: 45,
  169. fontSize: 10 // Reduced font size for y-axis labels
  170. }
  171. },
  172. {
  173. type: 'value',
  174. name: '',
  175. position: 'right',
  176. alignTicks: true,
  177. offset: 80,
  178. axisLine: {
  179. show: false,
  180. lineStyle: {
  181. color: colors[1]
  182. }
  183. },
  184. axisLabel: {
  185. formatter: '{value}',
  186. fontSize: 10 // Reduced font size for y-axis labels
  187. }
  188. },
  189. ],
  190. series: [{
  191. name: `${getMapText('去年同期金额')}(${getMapText('万元')})`,
  192. type: 'bar',
  193. data: data.balance.filter(v => v.name == '去年同期金额').map(v => (v.value / dividend).toFixed(2)),
  194. smooth: true
  195. },
  196. {
  197. name: `${getMapText('本期金额')}(${getMapText('万元')})`,
  198. type: 'bar',
  199. yAxisIndex: 1,
  200. data: data.balance.filter(v => v.name == '本年金额').map(v => (v.value / dividend).toFixed(2)),
  201. smooth: true
  202. },
  203. {
  204. name: getMapText('同比增长率'),
  205. type: 'line',
  206. yAxisIndex: 2,
  207. data: data.tbzzl.map(v => (v.value * 100).toFixed(2)),
  208. smooth: true
  209. }
  210. ]
  211. };
  212. this.chartComponent = this.selectComponent('#mychart');
  213. this.chartComponent.init((canvas, width, height, dpr) => {
  214. const chart = echarts.init(canvas, null, {
  215. width,
  216. height,
  217. devicePixelRatio: dpr
  218. });
  219. chart.setOption(option);
  220. return chart;
  221. });
  222. },
  223. changeDate({
  224. detail
  225. }) {
  226. this.setData({
  227. "content.enddate": detail
  228. })
  229. this.getList(true)
  230. },
  231. changeType({
  232. detail
  233. }) {
  234. this.setData({
  235. "content.accountno": detail
  236. })
  237. this.getList(true)
  238. },
  239. changeType1(e) {
  240. let {
  241. item
  242. } = e.currentTarget.dataset;
  243. this.changeType({
  244. detail: item.accountno
  245. })
  246. },
  247. toDetail() {
  248. let content = this.data.content;
  249. wx.navigateTo({
  250. url: '/salesPanel/customerBlance/detail?content=' + JSON.stringify(content)
  251. })
  252. },
  253. showExplain(e) {
  254. const {
  255. name
  256. } = e.currentTarget.dataset;
  257. getApp().globalData.Language.modeBoxPrompts(getApp().globalData.Language.getMapText('统计到当前查询时间为止的客户') + getApp().globalData.Language.getMapText(name) + getApp().globalData.Language.getMapText('总余额'))
  258. },
  259. }
  260. })