瀏覽代碼

接口修改数据结构

xiaohaizhao 2 年之前
父節點
當前提交
6cbd630d71
共有 1 個文件被更改,包括 24 次插入14 次删除
  1. 24 14
      packageA/account/index.js

+ 24 - 14
packageA/account/index.js

@@ -1,4 +1,6 @@
 const _Http = getApp().globalData.http;
+let pageNumber = 1,
+    pageTotal = 1;
 import {
     formatTime
 } from "../../utils/getTime";
@@ -10,7 +12,7 @@ Page({
         dateEnd: "", //日期结束时间
     },
     onLoad(options) {
-        let ymonth = formatTime(new Date(), '-').split(" ")[0].slice(0, 7);
+        let ymonth = formatTime(new Date(), '').split(" ")[0].slice(0, 7);
         this.setData({
             ymonth,
             dateEnd: ymonth
@@ -37,26 +39,32 @@ Page({
         this.setData({
             active: e.detail.value || e.detail.current
         });
-        this.getList();
+        this.getList(true);
     },
     /* 切换查看时间 */
     changeDate(e) {
         this.setData({
-            ymonth: e.detail.value
+            ymonth: e.detail.value.replace('-', '年')
         })
         this.getList();
     },
-    getList() {
+    getList(init = false) {
+        if (init){
+            pageNumber = 1;
+            pageTotal = 1
+        }
+        if (pageNumber > pageTotal) return;
         let data = this.data.accountList[this.data.active];
         _Http.basic({
             "id": "20230111103403",
             "version": 1,
             "content": {
+                pageNumber,
                 "sys_enterpriseid": data.sys_enterpriseid,
                 "sa_accountclassid": data.sa_accountclassid,
                 "where": {
-                    "year": this.data.ymonth.split("-")[0],
-                    "month": this.data.ymonth.split("-")[1]
+                    "year": this.data.ymonth.split("")[0],
+                    "month": this.data.ymonth.split("")[1]
                 }
             }
         }).then(res => {
@@ -64,21 +72,23 @@ Page({
             if (res.msg == '成功') {
                 let expend = 0, //收入
                     earning = 0; //支出
-                if (res.data.total.length) {
-                    let expendObj = res.data.total.find(v => v.type == 1);
+                if (res.data.length) {
+                    let expendObj = res.data[0].total.find(v => v.type == 1);
                     if (expendObj) expend = expendObj.sumamount;
-                    let earningObj = res.data.total.find(v => v.type == 1);
+                    let earningObj = res.data[0].total.find(v => v.type == 0);
                     if (earningObj) earning = earningObj.sumamount;
                 }
+                pageNumber += 1;
+                pageTotal = res.pageTotal;
                 this.setData({
-                    recordList: res.data.rows,
+                    recordList: res.pageNumber == 1 ? res.data : this.data.recordList.concat(res.data),
                     expend,
                     earning
-                })
+                });
             }
         })
     },
-    onReady() {
-
-    },
+    onReachBottom(){
+        this.getList();
+    }
 })