index.js 8.6 KB

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