Authored by 毕凯

订单确认增加价格价格计算

@@ -7,11 +7,15 @@ @@ -7,11 +7,15 @@
7 var $ = require('jquery'), 7 var $ = require('jquery'),
8 lazyLoad = require('yoho.lazyload'), 8 lazyLoad = require('yoho.lazyload'),
9 Hammer = require('yoho.hammer'), 9 Hammer = require('yoho.hammer'),
  10 + Handlebars = require('yoho.handlebars'),
  11 + tip = require('../plugin/tip'),
10 orderInfo = require('./order-info').orderInfo; 12 orderInfo = require('./order-info').orderInfo;
11 13
12 var dispatchModeHammer, 14 var dispatchModeHammer,
13 dispatchTimeHammer, 15 dispatchTimeHammer,
14 - $invoice = $('.invoice'); 16 + $invoice = $('.invoice'),
  17 + $price = $('.price-cal'),
  18 + priceTmpl = Handlebars.compile($('#tmpl-price').html());
15 19
16 lazyLoad(); 20 lazyLoad();
17 21
@@ -26,6 +30,38 @@ function dispacthTapEvt(e) { @@ -26,6 +30,38 @@ function dispacthTapEvt(e) {
26 $cur.addClass('chosed'); 30 $cur.addClass('chosed');
27 } 31 }
28 32
  33 +function orderCompute() {
  34 + $.ajax({
  35 + method: 'POST',
  36 + url: '/shoppingCart/orderCompute',
  37 + data: {
  38 + cartType: orderInfo('cartType'),
  39 + deliveryId: orderInfo('deliveryId'),
  40 + paymentTypeId: orderInfo('paymentTypeId'),
  41 + couponCode: orderInfo('couponCode'),
  42 + yohoCoin: orderInfo('yohoCoin')
  43 + }
  44 + }).then(function(res) {
  45 + var priceHtml;
  46 +
  47 + if (!res) {
  48 + tip.show('网络出错');
  49 + } else {
  50 + priceHtml = priceTmpl({
  51 + sumPrice: res.order_amount,
  52 + salePrice: res.discount_amount,
  53 + freight: res.promotion_formula_list[1].promotion_amount,
  54 + yohoCoin: res.use_yoho_coin,
  55 + price: res.last_order_amount
  56 + });
  57 +
  58 + $price.html(priceHtml);
  59 + }
  60 + }).fail(function() {
  61 + tip.show('网络出错');
  62 + });
  63 +}
  64 +
29 dispatchModeHammer = new Hammer(document.getElementsByClassName('dispatch-mode')[0]); 65 dispatchModeHammer = new Hammer(document.getElementsByClassName('dispatch-mode')[0]);
30 dispatchModeHammer.on('tap', dispacthTapEvt); 66 dispatchModeHammer.on('tap', dispacthTapEvt);
31 67
@@ -58,6 +94,7 @@ $('.invoice').on('touchend', '.checkbox', function() { @@ -58,6 +94,7 @@ $('.invoice').on('touchend', '.checkbox', function() {
58 // 界面点击,状态存 cookie 94 // 界面点击,状态存 cookie
59 $('.dispatch-mode').on('touchend', 'li', function() { 95 $('.dispatch-mode').on('touchend', 'li', function() {
60 orderInfo('deliveryId', $(this).data('id')); 96 orderInfo('deliveryId', $(this).data('id'));
  97 + orderCompute();
61 }); 98 });
62 99
63 $('.dispatch-time').on('touchend', 'li', function() { 100 $('.dispatch-time').on('touchend', 'li', function() {
@@ -69,9 +106,12 @@ $('.coin').on('touchend', function() { @@ -69,9 +106,12 @@ $('.coin').on('touchend', function() {
69 106
70 if ($this.find('.checkbox').hasClass('icon-cb-checked')) { 107 if ($this.find('.checkbox').hasClass('icon-cb-checked')) {
71 orderInfo('yohoCoin', $this.data('yoho-coin')); 108 orderInfo('yohoCoin', $this.data('yoho-coin'));
  109 + $this.find('.coin-check em').show();
72 } else { 110 } else {
73 orderInfo('yohoCoin', 0); 111 orderInfo('yohoCoin', 0);
  112 + $this.find('.coin-check em').hide();
74 } 113 }
  114 + orderCompute();
75 }); 115 });
76 116
77 $invoice.on('touchend', function() { 117 $invoice.on('touchend', function() {
@@ -102,23 +102,23 @@ @@ -102,23 +102,23 @@
102 </form> 102 </form>
103 </section> 103 </section>
104 104
105 - <section class="block"> 105 + <section class="price-cal block">
106 <ul class="total"> 106 <ul class="total">
107 <li> 107 <li>
108 <span>总价</span> 108 <span>总价</span>
109 - &nbsp;&nbsp;¥ {{sumPrice}} 109 + &nbsp;&nbsp;¥{{sumPrice}}
110 </li> 110 </li>
111 <li> 111 <li>
112 <span>活动价</span> 112 <span>活动价</span>
113 - - ¥ {{salePrice}} 113 + - ¥{{salePrice}}
114 </li> 114 </li>
115 <li> 115 <li>
116 <span>运费</span> 116 <span>运费</span>
117 - + ¥ {{freight}} 117 + + ¥{{freight}}
118 </li> 118 </li>
119 <li> 119 <li>
120 <span>YOHO币</span> 120 <span>YOHO币</span>
121 - - ¥ {{yohoCoin}} 121 + - ¥{{yohoCoin}}
122 </li> 122 </li>
123 <li class="cost"> 123 <li class="cost">
124 应付金额: <em>¥{{price}}</em> 124 应付金额: <em>¥{{price}}</em>
@@ -142,4 +142,27 @@ @@ -142,4 +142,27 @@
142 </ul> 142 </ul>
143 {{/ orderEnsure}} 143 {{/ orderEnsure}}
144 </div> 144 </div>
  145 +<script id="tmpl-price" type="text/tmpl">
  146 + <ul class="total">
  147 + <li>
  148 + <span>总价</span>
  149 + &nbsp;&nbsp;¥\{{sumPrice}}
  150 + </li>
  151 + <li>
  152 + <span>活动价</span>
  153 + - ¥\{{salePrice}}
  154 + </li>
  155 + <li>
  156 + <span>运费</span>
  157 + + \{{freight}}
  158 + </li>
  159 + <li>
  160 + <span>YOHO币</span>
  161 + - ¥\{{yohoCoin}}
  162 + </li>
  163 + <li class="cost">
  164 + 应付金额: <em>¥\{{price}}</em>
  165 + </li>
  166 + </ul>
  167 +</script>
145 {{> layout/footer}} 168 {{> layout/footer}}
@@ -169,10 +169,10 @@ class ShoppingCartController extends AbstractAction @@ -169,10 +169,10 @@ class ShoppingCartController extends AbstractAction
169 169
170 if ($this->isAjax()) { 170 if ($this->isAjax()) {
171 $cartType = $this->post('cartType', 'ordinary'); 171 $cartType = $this->post('cartType', 'ordinary');
172 - $deliveryWay = $this->post('deliveryWay', 1);  
173 - $paymentType = $this->post('paymentType', 1);  
174 - $couponCode = $this->post('paymentType', null);  
175 - $yohoCoin = $this->post('paymentType', null); 172 + $deliveryWay = $this->post('deliveryId', 1);
  173 + $paymentType = $this->post('paymentTypeId', 1);
  174 + $couponCode = $this->post('couponCode', null);
  175 + $yohoCoin = $this->post('yohoCoin', null);
176 $uid = $this->getUid(true); 176 $uid = $this->getUid(true);
177 $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin); 177 $result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
178 } 178 }