Browse Source

小程序同步修改优惠券问题

beaver383 6 years ago
parent
commit
32bf4241d4

+ 9 - 0
litemall-wx/pages/checkout/checkout.js

@@ -17,6 +17,7 @@ Page({
     cartId: 0,
     addressId: 0,
     couponId: 0,
+    userCouponId: 0,
     message: '',
     grouponLinkId: 0, //参与的团购,如果是发起则为0
     grouponRulesId: 0 //团购规则ID
@@ -32,6 +33,7 @@ Page({
       cartId: that.data.cartId,
       addressId: that.data.addressId,
       couponId: that.data.couponId,
+      userCouponId: that.data.userCouponId,
       grouponRulesId: that.data.grouponRulesId
     }).then(function(res) {
       if (res.errno === 0) {
@@ -47,6 +49,7 @@ Page({
           orderTotalPrice: res.data.orderTotalPrice,
           addressId: res.data.addressId,
           couponId: res.data.couponId,
+          userCouponId: res.data.userCouponId,
           grouponRulesId: res.data.grouponRulesId,
         });
       }
@@ -90,6 +93,10 @@ Page({
       if (couponId === "") {
         couponId = 0;
       }
+      var userCouponId = wx.getStorageSync('userCouponId');
+      if (userCouponId === "") {
+        userCouponId = 0;
+      }
       var grouponRulesId = wx.getStorageSync('grouponRulesId');
       if (grouponRulesId === "") {
         grouponRulesId = 0;
@@ -103,6 +110,7 @@ Page({
         cartId: cartId,
         addressId: addressId,
         couponId: couponId,
+        userCouponId: userCouponId,
         grouponRulesId: grouponRulesId,
         grouponLinkId: grouponLinkId
       });
@@ -131,6 +139,7 @@ Page({
       cartId: this.data.cartId,
       addressId: this.data.addressId,
       couponId: this.data.couponId,
+      userCouponId: this.data.userCouponId,
       message: this.data.message,
       grouponRulesId: this.data.grouponRulesId,
       grouponLinkId: this.data.grouponLinkId

+ 17 - 2
litemall-wx/pages/ucenter/couponSelect/couponSelect.js

@@ -8,6 +8,7 @@ Page({
     couponList: [],
     cartId: 0,
     couponId: 0,
+    userCouponId: 0,
     grouponLinkId: 0,
     scrollTop: 0
   },
@@ -46,6 +47,11 @@ Page({
         couponId = 0;
       }
 
+      var userCouponId = wx.getStorageSync('userCouponId');
+      if (!userCouponId) {
+        userCouponId = 0;
+      }
+
       var grouponRulesId = wx.getStorageSync('grouponRulesId');
       if (!grouponRulesId) {
         grouponRulesId = 0;
@@ -54,6 +60,7 @@ Page({
       this.setData({
         cartId: cartId,
         couponId: couponId,
+        userCouponId: userCouponId,
         grouponRulesId: grouponRulesId
       });
 
@@ -116,8 +123,14 @@ Page({
       grouponRulesId: that.data.grouponRulesId,
     }).then(function (res) {
       if (res.errno === 0) {
+        let list = [];
+        for (var i = 0; i < res.data.list.length; i++) {
+          if (res.data.list[i].available) {
+            list.push(res.data.list[i]);
+          }
+        }
         that.setData({
-          couponList: res.data.list
+          couponList: list
         });
       }
       wx.hideToast();
@@ -126,7 +139,8 @@ Page({
   },
   selectCoupon: function (e) {
     try {
-      wx.setStorageSync('couponId', e.currentTarget.dataset.id);
+      wx.setStorageSync('couponId', e.currentTarget.dataset.cid);
+      wx.setStorageSync('userCouponId', e.currentTarget.dataset.id);
     } catch (error) {
 
     }
@@ -137,6 +151,7 @@ Page({
     // 如果优惠券ID设置-1,则表示订单不使用优惠券
     try {
       wx.setStorageSync('couponId', -1);
+      wx.setStorageSync('userCouponId', -1);
     } catch (error) {
 
     }

+ 1 - 1
litemall-wx/pages/ucenter/couponSelect/couponSelect.wxml

@@ -4,7 +4,7 @@
 
     <view class="unselect" bindtap='unselectCoupon'>不选择优惠券</view>
 
-    <view class="item" wx:for="{{couponList}}" wx:for-index="index" wx:for-item="item" wx:key="id" bindtap="selectCoupon" data-id="{{item.id}}">
+    <view class="item" wx:for="{{couponList}}" wx:for-index="index" wx:for-item="item" wx:key="id" bindtap="selectCoupon" data-id="{{item.id}}" data-cid="{{item.cid}}">
       <view class="tag">{{item.tag}}</view>
       <view class="content">
         <view class="left">