huanggang 7 lat temu
rodzic
commit
97fc7ecc72

+ 26 - 14
pages/shopCart/shopCart.js

@@ -31,8 +31,14 @@ Page({
         let free_info = res.datas.free_info;
         let summary_datas = res.datas.summary;
         let cart_list = res.datas.cart_list;
-        let lastCartListId = cart_list[cart_list.length - 1].cart_id;
         let summary = [];
+        if (cart_list.length <= 0) {
+          self.setData({
+            free_info: free_info || self.data.free_info
+          });
+          wx.hideLoading();
+          return;
+        }
         for (let item of cart_list) {
           item.checked = false;
         }
@@ -45,6 +51,7 @@ Page({
           }
         }
         if (hasmore) {
+          let lastCartListId = cart_list[cart_list.length - 1].cart_id;
           self.setData({
             hasmore: true,
             curpage: lastCartListId
@@ -52,8 +59,7 @@ Page({
         }
         else {
           self.setData({
-            hasmore: false,
-            curpage: lastCartListId
+            hasmore: false
           })
         }
         let localSummary = self.data.summary;
@@ -155,17 +161,7 @@ Page({
     else {
       quantity = num - quantity;
       if (quantity <= 0) {
-        wx.showModal({
-          title: "提示",
-          content: "确定要删除吗?",
-          success: function (res) {
-            if (res.confirm) {
-              self.req_goods_num(cart_id, quantity, self.del_cart(cart_id, goods_id));
-            } else if (res.cancel) {
-              return;
-            }
-          }
-        })
+        this.cancal_cart(e,goods_id, cart_id);
       }
       else {
         self.req_goods_num(cart_id, quantity);
@@ -190,6 +186,22 @@ Page({
       cart_list
     })
   },
+  cancal_cart(e,goodsid,cartid){
+    let self = this;
+    let goods_id = e.target.dataset.goodsid || goodsid;
+    let cart_id = e.target.dataset.cartid || cartid;
+    wx.showModal({
+      title: "提示",
+      content: "确定要删除吗?",
+      success: function (res) {
+        if (res.confirm) {
+          self.req_goods_num(cart_id, 0, self.del_cart(cart_id, goods_id));
+        } else if (res.cancel) {
+          return;
+        }
+      }
+    })
+  },
   total(){
     let self = this;
     let cart_item = [];

+ 2 - 1
pages/shopCart/shopCart.wxml

@@ -10,9 +10,10 @@
 <view class='cart_list'>
   <block wx:for="{{summary}}" wx:key="{{index}}">
     <view class='cart_item'>
+      <icon class='cancal_btn' type="cancel" size="22" color="#ff4e4e" bindtap='cancal_cart' data-goodsid="{{cart_list[index]['goods_id']}}" data-cartid="{{cart_list[index]['cart_id']}}"></icon>
       <view class='check_btn' data-goodsid="{{cart_list[index]['goods_id']}}" bindtap='goods_checked'>
         <block wx:if="{{cart_list[index]['checked']}}">
-          <icon type="success" size="15" color="#ff4e4e"></icon>
+          <icon type="success" size="18" color="#ff4e4e"></icon>
         </block>
         <block wx:else>
           <view class="icon_empty"></view>

+ 8 - 0
pages/shopCart/shopCart.wxss

@@ -152,4 +152,12 @@
 }
 .clear_fixed {
   height: 88rpx;
+}
+.cancal_btn {
+  position: absolute;
+  right: 10rpx;
+  top: 15rpx;
+  width: 40rpx;
+  height: 40rpx;
+  z-index: 10;
 }