Authored by Rock Zhang

修复选择优惠券的bug(每次点击才请求搜索接口,判定优惠券是否存在)

Code Review By Rock Zhang
... ... @@ -67,9 +67,26 @@ $newCoupon.on('submit', function() {
$('#coupon-list').on('touchend', '.employ-main', function() {
var $this = $(this);
var couponCode = $this.data('coupon-code');
orderInfo('couponCode', $this.data('coupon-code'));
orderInfo('couponName', $this.data('coupon-name'));
$.ajax({
method: 'POST',
url: '/cart/index/couponSearch',
data: {
couponCode: couponCode
}
}).then(function(res) {
if (res.code === 200) {
//tip.show('优惠券可用');
orderInfo('couponCode', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
window.location.href = '/cart/index/orderEnsure';
} else {
tip.show(res.message || '网络错误');
}
}).fail(function() {
tip.show('网络错误');
});
}).on('touchstart', '.employ-main', function() {
var $this = $(this);
... ...
... ... @@ -46,9 +46,9 @@
<a href="/cart/index/selectCoupon">
<span class="title">优惠券</span>
{{# coupon}}
<span class="coupon-count">
{{!--<span class="coupon-count">}}
{{count}}张可用
</span>
</span>--}}
{{#if couponName}}
<span class="used coupon-use" data-name="{{couponName}}">
... ...
... ... @@ -13,7 +13,7 @@
<script id="tmpl-coupon" type="text/tmpl">
\{{#coupons}}
\{{^ notAvailable}}
<a class="employ-main" data-coupon-code="\{{ couponCode}}" data-coupon-name="\{{ couponDetailInfomation}}" href="/cart/index/orderEnsure">
<a class="employ-main" data-coupon-code="\{{ couponCode}}" data-coupon-name="\{{ couponDetailInfomation}}" href="javascript:void(0);">
<span>\{{ couponValue}}</span>
<p class="coupon-name">\{{ couponDetailInfomation}}</p>
<p>有效期:\{{ couponValidity}}</p>
... ...
... ... @@ -485,7 +485,7 @@ class CartModel
// 优惠券数据
$coupons = array('couponName' => '');
if (!empty($orderCompute['coupon_amount'])) {
$coupons['couponName'] = $orderCompute['coupon_amount'];
$coupons['couponName'] = $orderInfo['couponName'];
}
$result['coupon'] = $coupons;
}
... ...