修复选择优惠券的bug(每次点击才请求搜索接口,判定优惠券是否存在)
Code Review By Rock Zhang
Showing
4 changed files
with
23 additions
and
6 deletions
@@ -67,9 +67,26 @@ $newCoupon.on('submit', function() { | @@ -67,9 +67,26 @@ $newCoupon.on('submit', function() { | ||
67 | 67 | ||
68 | $('#coupon-list').on('touchend', '.employ-main', function() { | 68 | $('#coupon-list').on('touchend', '.employ-main', function() { |
69 | var $this = $(this); | 69 | var $this = $(this); |
70 | + var couponCode = $this.data('coupon-code'); | ||
70 | 71 | ||
71 | - orderInfo('couponCode', $this.data('coupon-code')); | ||
72 | - orderInfo('couponName', $this.data('coupon-name')); | 72 | + $.ajax({ |
73 | + method: 'POST', | ||
74 | + url: '/cart/index/couponSearch', | ||
75 | + data: { | ||
76 | + couponCode: couponCode | ||
77 | + } | ||
78 | + }).then(function(res) { | ||
79 | + if (res.code === 200) { | ||
80 | + //tip.show('优惠券可用'); | ||
81 | + orderInfo('couponCode', res.data.coupon_code); | ||
82 | + orderInfo('couponName', res.data.coupon_title); | ||
83 | + window.location.href = '/cart/index/orderEnsure'; | ||
84 | + } else { | ||
85 | + tip.show(res.message || '网络错误'); | ||
86 | + } | ||
87 | + }).fail(function() { | ||
88 | + tip.show('网络错误'); | ||
89 | + }); | ||
73 | }).on('touchstart', '.employ-main', function() { | 90 | }).on('touchstart', '.employ-main', function() { |
74 | var $this = $(this); | 91 | var $this = $(this); |
75 | 92 |
@@ -46,9 +46,9 @@ | @@ -46,9 +46,9 @@ | ||
46 | <a href="/cart/index/selectCoupon"> | 46 | <a href="/cart/index/selectCoupon"> |
47 | <span class="title">优惠券</span> | 47 | <span class="title">优惠券</span> |
48 | {{# coupon}} | 48 | {{# coupon}} |
49 | - <span class="coupon-count"> | 49 | + {{!--<span class="coupon-count">}} |
50 | {{count}}张可用 | 50 | {{count}}张可用 |
51 | - </span> | 51 | + </span>--}} |
52 | 52 | ||
53 | {{#if couponName}} | 53 | {{#if couponName}} |
54 | <span class="used coupon-use" data-name="{{couponName}}"> | 54 | <span class="used coupon-use" data-name="{{couponName}}"> |
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | <script id="tmpl-coupon" type="text/tmpl"> | 13 | <script id="tmpl-coupon" type="text/tmpl"> |
14 | \{{#coupons}} | 14 | \{{#coupons}} |
15 | \{{^ notAvailable}} | 15 | \{{^ notAvailable}} |
16 | - <a class="employ-main" data-coupon-code="\{{ couponCode}}" data-coupon-name="\{{ couponDetailInfomation}}" href="/cart/index/orderEnsure"> | 16 | + <a class="employ-main" data-coupon-code="\{{ couponCode}}" data-coupon-name="\{{ couponDetailInfomation}}" href="javascript:void(0);"> |
17 | <span>\{{ couponValue}}</span> | 17 | <span>\{{ couponValue}}</span> |
18 | <p class="coupon-name">\{{ couponDetailInfomation}}</p> | 18 | <p class="coupon-name">\{{ couponDetailInfomation}}</p> |
19 | <p>有效期:\{{ couponValidity}}</p> | 19 | <p>有效期:\{{ couponValidity}}</p> |
@@ -485,7 +485,7 @@ class CartModel | @@ -485,7 +485,7 @@ class CartModel | ||
485 | // 优惠券数据 | 485 | // 优惠券数据 |
486 | $coupons = array('couponName' => ''); | 486 | $coupons = array('couponName' => ''); |
487 | if (!empty($orderCompute['coupon_amount'])) { | 487 | if (!empty($orderCompute['coupon_amount'])) { |
488 | - $coupons['couponName'] = $orderCompute['coupon_amount']; | 488 | + $coupons['couponName'] = $orderInfo['couponName']; |
489 | } | 489 | } |
490 | $result['coupon'] = $coupons; | 490 | $result['coupon'] = $coupons; |
491 | } | 491 | } |
-
Please register or login to post a comment