Authored by yyq

结算页运费券

... ... @@ -43,7 +43,14 @@ const index = (uid, cartType) => {
};
// 获取优惠券列表
const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid);
const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid).then(result => {
if (_.isEmpty(_.get(result, 'data.usable_coupons', [])) &&
_.isEmpty(_.get(result, 'data.usable_frees_coupons', []))) {
_.set(result, 'data.emptyUsable', true);
}
return result;
});
// 订单计算
const compute = (uid, cartType, pa) => {
... ...
... ... @@ -147,20 +147,35 @@
</script>
<script id="coupons-tpl" type="text/html">
\{{#if usable_coupons}}
<ul class="usable-list">
<li class="useable-title">可用优惠券</li>
\{{#each usable_coupons}}
<li>
<span class="title">\{{coupon_name}}</span>
<span class="time">\{{coupon_validity}}</span>
<span class="money">¥ \{{round coupon_value 2}}</span>
<span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>
</li>
\{{/each}}
</ul>
\{{^}}
\{{#if emptyUsable}}
<p class="empty-tip">暂无可用优惠券~</p>
\{{^}}
\{{#if usable_frees_coupons}}
<ul class="usable-free-list">
<li class="useable-title">可用运费券</li>
\{{#each usable_frees_coupons}}
<li>
<span class="title">\{{coupon_name}}</span>
<span class="time">\{{coupon_validity}}</span>
<span class="money">¥ \{{round coupon_value 2}}</span>
<span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>
</li>
\{{/each}}
</ul>
\{{/if}}
\{{#if usable_coupons}}
<ul class="usable-list">
<li class="useable-title">可用优惠券</li>
\{{#each usable_coupons}}
<li>
<span class="title">\{{coupon_name}}</span>
<span class="time">\{{coupon_validity}}</span>
<span class="money">¥ \{{round coupon_value 2}}</span>
<span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>
</li>
\{{/each}}
</ul>
\{{/if}}
\{{/if}}
\{{#if unusable_coupons}}
<ul class="unusable-list">
... ...
... ... @@ -500,7 +500,6 @@ coupon = {
}).then(function(data) {
if (data.code === 200) {
$('.coupon-list-wrap', that.$couponWrap).html(that.couponsTpl(data.data));
that.$radios = that.$couponWrap.find('.coupon-radio');
}
});
},
... ... @@ -553,38 +552,47 @@ coupon = {
}
}).on('click', '.coupon-radio', function() {
var $this = $(this),
data, couponId;
$par = $this.parent();
if ($this.hasClass('on')) {
return;
}
if (that.$radios) {
that.$radios.filter('.on').removeClass('on');
}
$par.siblings('.red').removeClass('red').children('.coupon-radio').removeClass('on');
$this.addClass('on');
$this.parent().siblings('.red').removeClass('red');
$this.parent().addClass('red');
data = $this.data();
$par.addClass('red');
if (data) {
that.$ticketUseTip.find('.price').text('- ¥' + data.price);
that.$ticketUseTip.removeClass('hide');
couponId = data.id;
}
// 改变优惠券使用搭配,重新计算订单价格
that.changeTicketsUse();
});
},
changeTicketsUse: function() {
var coupons = [],
price = 0;
if (couponId) {
order.couponCode = couponId;
this.$couponWrap.find('.coupon-radio.on').each(function() {
var data = $(this).data();
// 重新计算订单价格
compute();
if (data) {
coupons.push(data.id);
price += +data.price;
}
});
if (coupons.length) {
this.$ticketUseTip.find('.num').text(coupons.length);
this.$ticketUseTip.find('.price').text('- ¥' + price.toFixed(2));
this.$ticketUseTip.removeClass('hide');
order.couponCode = coupons.join(',');
// 重新计算订单价格
compute();
}
},
cancelTicketUse: function() {
if (order.couponCode) {
this.$ticketUseTip.addClass('hide');
this.$radios.filter('.on').removeClass('on');
this.$couponWrap.find('li.red').removeClass('red').find('.on').removeClass('on');
delete order.couponCode;
compute(); // 重新计算订单价格
... ...
... ... @@ -927,6 +927,10 @@
.ticket-use-tip {
margin-left: 20px;
.num {
margin: 0 4px;
}
.red {
color: $red;
}
... ...