Authored by yyq

结算页运费券

@@ -43,7 +43,14 @@ const index = (uid, cartType) => { @@ -43,7 +43,14 @@ const index = (uid, cartType) => {
43 }; 43 };
44 44
45 // 获取优惠券列表 45 // 获取优惠券列表
46 -const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid); 46 +const getCoupons = (uid) => ensureApi.getUesrCouponAsync(uid).then(result => {
  47 + if (_.isEmpty(_.get(result, 'data.usable_coupons', [])) &&
  48 + _.isEmpty(_.get(result, 'data.usable_frees_coupons', []))) {
  49 + _.set(result, 'data.emptyUsable', true);
  50 + }
  51 +
  52 + return result;
  53 +});
47 54
48 // 订单计算 55 // 订单计算
49 const compute = (uid, cartType, pa) => { 56 const compute = (uid, cartType, pa) => {
@@ -147,20 +147,35 @@ @@ -147,20 +147,35 @@
147 </script> 147 </script>
148 148
149 <script id="coupons-tpl" type="text/html"> 149 <script id="coupons-tpl" type="text/html">
150 - \{{#if usable_coupons}}  
151 - <ul class="usable-list">  
152 - <li class="useable-title">可用优惠券</li>  
153 - \{{#each usable_coupons}}  
154 - <li>  
155 - <span class="title">\{{coupon_name}}</span>  
156 - <span class="time">\{{coupon_validity}}</span>  
157 - <span class="money">¥ \{{round coupon_value 2}}</span>  
158 - <span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>  
159 - </li>  
160 - \{{/each}}  
161 - </ul>  
162 - \{{^}} 150 + \{{#if emptyUsable}}
163 <p class="empty-tip">暂无可用优惠券~</p> 151 <p class="empty-tip">暂无可用优惠券~</p>
  152 + \{{^}}
  153 + \{{#if usable_frees_coupons}}
  154 + <ul class="usable-free-list">
  155 + <li class="useable-title">可用运费券</li>
  156 + \{{#each usable_frees_coupons}}
  157 + <li>
  158 + <span class="title">\{{coupon_name}}</span>
  159 + <span class="time">\{{coupon_validity}}</span>
  160 + <span class="money">¥ \{{round coupon_value 2}}</span>
  161 + <span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>
  162 + </li>
  163 + \{{/each}}
  164 + </ul>
  165 + \{{/if}}
  166 + \{{#if usable_coupons}}
  167 + <ul class="usable-list">
  168 + <li class="useable-title">可用优惠券</li>
  169 + \{{#each usable_coupons}}
  170 + <li>
  171 + <span class="title">\{{coupon_name}}</span>
  172 + <span class="time">\{{coupon_validity}}</span>
  173 + <span class="money">¥ \{{round coupon_value 2}}</span>
  174 + <span class="coupon-radio" data-id="\{{coupon_code}}" data-price="\{{round coupon_value 2}}"></span>
  175 + </li>
  176 + \{{/each}}
  177 + </ul>
  178 + \{{/if}}
164 \{{/if}} 179 \{{/if}}
165 \{{#if unusable_coupons}} 180 \{{#if unusable_coupons}}
166 <ul class="unusable-list"> 181 <ul class="unusable-list">
@@ -500,7 +500,6 @@ coupon = { @@ -500,7 +500,6 @@ coupon = {
500 }).then(function(data) { 500 }).then(function(data) {
501 if (data.code === 200) { 501 if (data.code === 200) {
502 $('.coupon-list-wrap', that.$couponWrap).html(that.couponsTpl(data.data)); 502 $('.coupon-list-wrap', that.$couponWrap).html(that.couponsTpl(data.data));
503 - that.$radios = that.$couponWrap.find('.coupon-radio');  
504 } 503 }
505 }); 504 });
506 }, 505 },
@@ -553,38 +552,47 @@ coupon = { @@ -553,38 +552,47 @@ coupon = {
553 } 552 }
554 }).on('click', '.coupon-radio', function() { 553 }).on('click', '.coupon-radio', function() {
555 var $this = $(this), 554 var $this = $(this),
556 - data, couponId; 555 + $par = $this.parent();
557 556
558 if ($this.hasClass('on')) { 557 if ($this.hasClass('on')) {
559 return; 558 return;
560 } 559 }
561 560
562 - if (that.$radios) {  
563 - that.$radios.filter('.on').removeClass('on');  
564 - } 561 + $par.siblings('.red').removeClass('red').children('.coupon-radio').removeClass('on');
565 $this.addClass('on'); 562 $this.addClass('on');
566 - $this.parent().siblings('.red').removeClass('red');  
567 - $this.parent().addClass('red');  
568 - data = $this.data(); 563 + $par.addClass('red');
569 564
570 - if (data) {  
571 - that.$ticketUseTip.find('.price').text('- ¥' + data.price);  
572 - that.$ticketUseTip.removeClass('hide');  
573 - couponId = data.id;  
574 - } 565 + // 改变优惠券使用搭配,重新计算订单价格
  566 + that.changeTicketsUse();
  567 + });
  568 + },
  569 + changeTicketsUse: function() {
  570 + var coupons = [],
  571 + price = 0;
575 572
576 - if (couponId) {  
577 - order.couponCode = couponId; 573 + this.$couponWrap.find('.coupon-radio.on').each(function() {
  574 + var data = $(this).data();
578 575
579 - // 重新计算订单价格  
580 - compute(); 576 + if (data) {
  577 + coupons.push(data.id);
  578 + price += +data.price;
581 } 579 }
582 }); 580 });
  581 +
  582 + if (coupons.length) {
  583 + this.$ticketUseTip.find('.num').text(coupons.length);
  584 + this.$ticketUseTip.find('.price').text('- ¥' + price.toFixed(2));
  585 + this.$ticketUseTip.removeClass('hide');
  586 + order.couponCode = coupons.join(',');
  587 +
  588 + // 重新计算订单价格
  589 + compute();
  590 + }
583 }, 591 },
584 cancelTicketUse: function() { 592 cancelTicketUse: function() {
585 if (order.couponCode) { 593 if (order.couponCode) {
586 this.$ticketUseTip.addClass('hide'); 594 this.$ticketUseTip.addClass('hide');
587 - this.$radios.filter('.on').removeClass('on'); 595 + this.$couponWrap.find('li.red').removeClass('red').find('.on').removeClass('on');
588 596
589 delete order.couponCode; 597 delete order.couponCode;
590 compute(); // 重新计算订单价格 598 compute(); // 重新计算订单价格
@@ -927,6 +927,10 @@ @@ -927,6 +927,10 @@
927 .ticket-use-tip { 927 .ticket-use-tip {
928 margin-left: 20px; 928 margin-left: 20px;
929 929
  930 + .num {
  931 + margin: 0 4px;
  932 + }
  933 +
930 .red { 934 .red {
931 color: $red; 935 color: $red;
932 } 936 }