index.js 2.7 KB

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