huanggang 7 năm trước cách đây
mục cha
commit
6b00323a5e
1 tập tin đã thay đổi với 28 bổ sung21 xóa
  1. 28 21
      pages/shopCart/shopCart.js

+ 28 - 21
pages/shopCart/shopCart.js

@@ -1,15 +1,9 @@
 const getReq = require('./../../config.js').getReq;
 Page({
   data: {
-    free_info: {
-      type: Array
-    },
-    summary: {
-      type: Array
-    },
-    cart_list: {
-      type: Array
-    },
+    free_info: [],
+    summary: [],
+    cart_list: [],
     all_checked: false,
     allPrice: 0,
     allGoodsPrice: 0,
@@ -20,18 +14,24 @@ Page({
 
   },
   onShow: function () {
+    this.req_datas();
+  },
+  req_datas(){
     let self = this;
+    wx.showLoading({
+      title: '加载中',
+    });
     getReq({
       act: 'cart',
       op: 'list',
-      minest_cartid: this.data.curpage
+      minest_cartid: self.data.curpage
     }, function (res) {
       if (res.code == 200) {
         let hasmore = res.datas.mobile_page.hasmore;
         let free_info = res.datas.free_info;
         let summary_datas = res.datas.summary;
         let cart_list = res.datas.cart_list;
-        let lashCartListId = cart_list[cart_list.length - 1].cart_id;
+        let lastCartListId = cart_list[cart_list.length - 1].cart_id;
         let summary = [];
         for (let item of cart_list) {
           item.checked = false;
@@ -40,24 +40,33 @@ Page({
           for (let j = 0; j < summary_datas.length; j++) {
             if (cart_list[i].goods_id == summary_datas[j].goods_id) {
               summary.push(summary_datas[j]);
+              continue;
             }
           }
         }
         if (hasmore) {
           self.setData({
             hasmore: true,
-            curpage: lashCartListId
+            curpage: lastCartListId
+          })
+        }
+        else {
+          self.setData({
+            hasmore: false,
+            curpage: lastCartListId
           })
-        }  
+        }
+        let localSummary = self.data.summary;
+        let localCartList = self.data.cart_list;
         self.setData({
-          free_info,
-          summary,
-          cart_list
+          free_info: free_info || self.data.free_info,
+          summary: localSummary.concat(summary),
+          cart_list: localCartList.concat(cart_list)
         });
+        wx.hideLoading();
       }
     })
   },
-
   goods_checked(e) {
     let goods_id = e.currentTarget.dataset.goodsid;
     let cart_list = this.data.cart_list;
@@ -217,16 +226,14 @@ Page({
     let self = this;
     let hasmore = this.data.hasmore;
     if(hasmore) {
+      
       let req_curpage = this.data.curpage;
       getReq({
         act: 'cart',
         op: 'list',
         minest_cartid: req_curpage
       }, function (res) {
-        self.setData({
-          curpage: req_curpage
-        })
-        console.log(res);
+        self.req_datas();
       })
     }
   },