index.js 3.2 KB

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