index.js 3.2 KB

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