index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. const _Http = getApp().globalData.http;
  2. let pageNumber = 1,
  3. pageTotal = 1,
  4. currency = require("../../utils/currency"),
  5. CNY = value => currency(value, {
  6. symbol: "¥",
  7. precision: 2
  8. }).format();
  9. import {
  10. formatTime
  11. } from "../../utils/getTime";
  12. Page({
  13. data: {
  14. accountList: [],
  15. active: 0,
  16. ymonth: "", //年月
  17. dateEnd: "", //日期结束时间
  18. },
  19. onLoad(options) {
  20. let ymonth = formatTime(new Date(), '年').split(" ")[0].slice(0, 7);
  21. this.setData({
  22. ymonth,
  23. dateEnd: ymonth
  24. });
  25. _Http.basic({
  26. id: 20221008145903,
  27. "content": {
  28. pageSize: 999,
  29. type: 1,
  30. "where": {
  31. "condition": ""
  32. }
  33. }
  34. }).then(res => {
  35. console.log(res)
  36. this.setData({
  37. accountList: res.data.map(v => {
  38. v.creditquota = CNY(v.creditquota);
  39. v.usable = CNY(currency(v.creditquota).add(v.balance));
  40. v.balance = CNY(v.balance)
  41. return v
  42. })
  43. });
  44. this.getList(true);
  45. })
  46. },
  47. /* 切换查看账户 */
  48. changeAccount(e) {
  49. this.setData({
  50. active: e.detail.value || e.detail.current
  51. });
  52. this.getList(true);
  53. },
  54. /* 切换查看时间 */
  55. changeDate(e) {
  56. this.setData({
  57. ymonth: e.detail.value.replace('-', '年')
  58. })
  59. this.getList();
  60. },
  61. getList(init = false) {
  62. if (init) {
  63. pageNumber = 1;
  64. pageTotal = 1
  65. }
  66. if (pageNumber > pageTotal) return;
  67. let data = this.data.accountList[this.data.active];
  68. _Http.basic({
  69. "id": "20230111103403",
  70. "version": 1,
  71. "content": {
  72. pageNumber,
  73. "sys_enterpriseid": data.sys_enterpriseid,
  74. "sa_accountclassid": data.sa_accountclassid,
  75. "where": {
  76. "year": this.data.ymonth.split("年")[0],
  77. "month": this.data.ymonth.split("年")[1]
  78. }
  79. }
  80. }).then(res => {
  81. console.log("账户流水", res)
  82. if (res.msg == '成功') {
  83. let expend = 0, //收入
  84. earning = 0; //支出
  85. if (res.data.length) {
  86. let expendObj = res.data[0].total.find(v => v.type == 1);
  87. if (expendObj) expend = CNY(expendObj.sumamount);
  88. let earningObj = res.data[0].total.find(v => v.type == 0);
  89. if (earningObj) earning = CNY(earningObj.sumamount);
  90. }
  91. res.data = res.data.map(v=>{
  92. v.amount = CNY(v.amount)
  93. v.showBalance = CNY(v.balance)
  94. return v
  95. })
  96. pageNumber += 1;
  97. pageTotal = res.pageTotal;
  98. this.setData({
  99. recordList: res.pageNumber == 1 ? res.data : this.data.recordList.concat(res.data),
  100. expend,
  101. earning
  102. });
  103. }
  104. })
  105. },
  106. onReachBottom() {
  107. this.getList();
  108. }
  109. })