...
|
...
|
@@ -491,7 +491,7 @@ coupon = { |
|
|
this.getList();
|
|
|
this.eventBind();
|
|
|
},
|
|
|
getList: function() {
|
|
|
getList: function(choose) {
|
|
|
var that = this;
|
|
|
|
|
|
$.ajax({
|
...
|
...
|
@@ -499,57 +499,66 @@ coupon = { |
|
|
url: '/cart/ensure/coupons'
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$('.coupon-list-wrap', that.$couponWrap).html(that.couponsTpl(data.data));
|
|
|
$('.coupon-list-wrap', that.$couponWrap).html(that.couponsTpl(that.selectUsedCoupon(data.data)));
|
|
|
|
|
|
if (choose) { // 兑换券后默认使用该券
|
|
|
$('.coupon-radio', that.$couponWrap).each(function() {
|
|
|
$(this).data('id') === choose && $(this).trigger('click');
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
eventBind: function() {
|
|
|
useCode: function(code) {
|
|
|
var that = this;
|
|
|
|
|
|
this.$couponWrap.on('click', '.radio-btn', function() {
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.hasClass('on')) {
|
|
|
return;
|
|
|
}
|
|
|
$this.siblings('.radio-btn.on').removeClass('on');
|
|
|
$this.addClass('on').parent().toggleClass('using-code');
|
|
|
if (!code) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($this.hasClass('code')) {
|
|
|
that.cancelTicketUse();
|
|
|
that.$couponList.slideUp();
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/cart/ensure/couponcode',
|
|
|
data: {code: code}
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
that.getList(data.data.coupon_code);
|
|
|
} else {
|
|
|
that.cancelCodeUse();
|
|
|
that.$couponList.slideDown();
|
|
|
that.$errorTip.text(data.message || '兑换失败,请稍后再试');
|
|
|
}
|
|
|
}).on('click', '.cancel-use-ticket', function() {
|
|
|
that.cancelTicketUse();
|
|
|
}).on('change', '.coupon-code', function() {
|
|
|
that.$errorTip.empty();
|
|
|
}).on('click', '.sure-use-ticket', function() {
|
|
|
that.close();
|
|
|
}).on('click', '.sure-use-code', function() {
|
|
|
var $this = $(this);
|
|
|
var couponId;
|
|
|
|
|
|
couponId = $this.siblings('.coupon-code').val();
|
|
|
});
|
|
|
},
|
|
|
selectUsedCoupon: function(data) {
|
|
|
var i;
|
|
|
|
|
|
if (couponId) {
|
|
|
order.couponCode = couponId;
|
|
|
if (order.couponCode) {
|
|
|
data.usable_coupons = data.usable_coupons || [];
|
|
|
data.usable_frees_coupons = data.usable_frees_coupons || [];
|
|
|
|
|
|
// 重新计算订单价格
|
|
|
compute(0, function(resData) {
|
|
|
if (resData.code === 200) {
|
|
|
that.close();
|
|
|
} else {
|
|
|
that.$errorTip.text(resData.message);
|
|
|
for (i = 0; i < data.usable_coupons.length; i++) {
|
|
|
if (order.couponCode.indexOf(data.usable_coupons[i].coupon_code) > -1) {
|
|
|
data.usable_coupons[i].using = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (order.couponCode) {
|
|
|
delete order.couponCode;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
for (i = 0; i < data.usable_frees_coupons.length; i++) {
|
|
|
if (order.couponCode.indexOf(data.usable_frees_coupons[i].coupon_code) > -1) {
|
|
|
data.usable_frees_coupons[i].using = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
},
|
|
|
eventBind: function() {
|
|
|
var that = this;
|
|
|
|
|
|
this.$couponWrap.on('click', '.cancel-use-ticket', function() {
|
|
|
that.cancelTicketUse();
|
|
|
}).on('change', '.coupon-code', function() {
|
|
|
that.$errorTip.empty();
|
|
|
}).on('click', '.sure-convert', function() {
|
|
|
that.useCode($(this).siblings('.coupon-code').val());
|
|
|
}).on('click', '.coupon-radio', function() {
|
|
|
var $this = $(this),
|
|
|
$par = $this.parent();
|
...
|
...
|
|