Authored by 毕凯

增加 cookie 操作

@@ -6,9 +6,12 @@ @@ -6,9 +6,12 @@
6 6
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 + orderInfo = require('./order-info').orderInfo;
10 11
11 -var dispatchModeHammer, dispatchTimeHammer; 12 +var dispatchModeHammer,
  13 + dispatchTimeHammer,
  14 + $invoice = $('.invoice');
12 15
13 lazyLoad(); 16 lazyLoad();
14 17
@@ -51,3 +54,42 @@ $('.invoice').on('touchend', '.checkbox', function() { @@ -51,3 +54,42 @@ $('.invoice').on('touchend', '.checkbox', function() {
51 $('.invoice').removeClass('focus'); 54 $('.invoice').removeClass('focus');
52 } 55 }
53 }); 56 });
  57 +
  58 +// 界面点击,状态存 cookie
  59 +$('.dispatch-mode').on('touchend', 'li', function() {
  60 + orderInfo('deliveryId', $(this).data('id'));
  61 +});
  62 +
  63 +$('.dispatch-time').on('touchend', 'li', function() {
  64 + orderInfo('deliveryTimeId', $(this).data('id'));
  65 +});
  66 +
  67 +$('.coin').on('touchend', function() {
  68 + var $this = $(this);
  69 +
  70 + if ($this.find('.checkbox').hasClass('icon-cb-checked')) {
  71 + orderInfo('yohoCoin', $this.data('yoho-coin'));
  72 + } else {
  73 + orderInfo('yohoCoin', 0);
  74 + }
  75 +});
  76 +
  77 +$invoice.on('touchend', function() {
  78 + var $this = $(this);
  79 +
  80 + orderInfo('invoice', $this.find('.checkbox').hasClass('icon-cb-checked'));
  81 +});
  82 +
  83 +$invoice.find('[name="invoice-title"]').on('blur', function() {
  84 + orderInfo('invoiceText', $(this).val());
  85 +}).end().find('.invoice-type').on('change', function() {
  86 + orderInfo('invoiceType', $(this).val());
  87 +});
  88 +
  89 +$('#msg').find('input').on('blur', function() {
  90 + orderInfo('msg', $(this).val());
  91 +});
  92 +
  93 +$('.pay-mode').on('click', 'li', function() {
  94 + orderInfo('paymentTypeId', $(this).data('pay-id'));
  95 +});
@@ -3,12 +3,11 @@ @@ -3,12 +3,11 @@
3 * @author: bikai<kai.bi@yoho.cn> 3 * @author: bikai<kai.bi@yoho.cn>
4 * @date: 2015/12/14 4 * @date: 2015/12/14
5 */ 5 */
6 -var info = window.cookie('order-info'),  
7 - orderInfo; 6 +var info = window.cookie('order-info');
8 7
9 // info 必须是 JSON 字符串 8 // info 必须是 JSON 字符串
10 try { 9 try {
11 - info = JSON.parse(orderInfo); 10 + info = JSON.parse(info);
12 } catch (e) { 11 } catch (e) {
13 info = {}; 12 info = {};
14 } 13 }
@@ -16,14 +16,15 @@ var page = 1, @@ -16,14 +16,15 @@ var page = 1,
16 isGetData; 16 isGetData;
17 17
18 var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()), 18 var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()),
19 - conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()); 19 + conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()),
  20 + $newCoupon = $('#new-coupon');
20 21
21 ellipsis.init(); 22 ellipsis.init();
22 23
23 -$('#search-coupon').on('submit', function() { 24 +$newCoupon.on('submit', function() {
24 $.ajax({ 25 $.ajax({
25 method: 'POST', 26 method: 'POST',
26 - url: '/shoppingCart/coupon', 27 + url: '/shoppingCart/couponSearch',
27 data: $(this).serialize() 28 data: $(this).serialize()
28 }).then(function(res) { 29 }).then(function(res) {
29 if (res.code === 200) { 30 if (res.code === 200) {
@@ -39,8 +40,19 @@ $('#search-coupon').on('submit', function() { @@ -39,8 +40,19 @@ $('#search-coupon').on('submit', function() {
39 return false; 40 return false;
40 }); 41 });
41 42
42 -$('#coupon-list').on('touchend', 'employ-main', function() {  
43 - orderInfo('couponCode', $(this).data('coupon-code')); 43 +$('#coupon-list').on('touchend', '.employ-main', function() {
  44 + var $this = $(this);
  45 +
  46 + orderInfo('couponCode', $this.data('coupon-code'));
  47 + orderInfo('couponValue', $this.data('coupon-value'));
  48 +});
  49 +
  50 +$newCoupon.find('input').on('input', function() {
  51 + if ($(this).val() !== '') {
  52 + $newCoupon.find('.submit').css('background', '#444');
  53 + } else {
  54 + $newCoupon.find('.submit').css('background', '#b0b0b0');
  55 + }
44 }); 56 });
45 57
46 function getCouponHandle(coupons) { 58 function getCouponHandle(coupons) {
@@ -117,7 +129,7 @@ function getCouponDate() { @@ -117,7 +129,7 @@ function getCouponDate() {
117 129
118 $.ajax({ 130 $.ajax({
119 type: 'POST', 131 type: 'POST',
120 - url: '/home/couponData', 132 + url: '/shoppingCart/couponList',
121 dataType: 'json', 133 dataType: 'json',
122 data: { 134 data: {
123 page: page 135 page: page
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 margin-top: pxToRem(30px); 2 margin-top: pxToRem(30px);
3 margin-bottom: pxToRem(30px); 3 margin-bottom: pxToRem(30px);
4 4
5 - #search-coupon { 5 + #new-coupon {
6 margin-bottom: pxToRem(30px); 6 margin-bottom: pxToRem(30px);
7 padding-left: pxToRem(30px); 7 padding-left: pxToRem(30px);
8 padding-right: pxToRem(30px); 8 padding-right: pxToRem(30px);
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <p class="infos"> 5 <p class="infos">
6 收货地址 6 收货地址
7 <span class="per-info">{{name}} {{phoneNum}}</span> 7 <span class="per-info">{{name}} {{phoneNum}}</span>
8 - <span class="address">{{address}}</span> 8 + <span class="address">{{area}} {{address}}</span>
9 </p> 9 </p>
10 <span class="iconfont">&#xe614;</span> 10 <span class="iconfont">&#xe614;</span>
11 </a> 11 </a>
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 <h3 class="title">配送方式</h3> 15 <h3 class="title">配送方式</h3>
16 <ul class="dispatch-mode clearfix"> 16 <ul class="dispatch-mode clearfix">
17 {{#each dispatchMode}} 17 {{#each dispatchMode}}
18 - <li {{#if @first}}class="chosed"{{/if}} data-id="{{id}}">{{name}}</li> 18 + <li {{#if isSelected}}class="chosed"{{/if}} data-id="{{id}}">{{name}}</li>
19 {{/each}} 19 {{/each}}
20 </ul> 20 </ul>
21 </div> 21 </div>
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 <h3 class="title">送货时间</h3> 24 <h3 class="title">送货时间</h3>
25 <ul class="dispatch-time clearfix"> 25 <ul class="dispatch-time clearfix">
26 {{#each dispatchTime}} 26 {{#each dispatchTime}}
27 - <li {{#if @first}}class="chosed"{{/if}} data-id="{{id}}">{{name}}</li> 27 + <li {{#if isSelected}}class="chosed"{{/if}} data-id="{{id}}">{{name}}</li>
28 {{/each}} 28 {{/each}}
29 </ul> 29 </ul>
30 </div> 30 </div>
@@ -52,14 +52,14 @@ @@ -52,14 +52,14 @@
52 </span> 52 </span>
53 {{/if}} 53 {{/if}}
54 54
55 - {{#if notUsed}}  
56 - <span class="not-used coupon-use">  
57 - 未使用 55 + {{#if value}}
  56 + <span class="used coupon-use">
  57 + {{value}}
58 <i class="iconfont">&#xe614;</i> 58 <i class="iconfont">&#xe614;</i>
59 </span> 59 </span>
60 {{^}} 60 {{^}}
61 - <span class="used coupon-use">  
62 - {{value}} 61 + <span class="not-used coupon-use">
  62 + 未使用
63 <i class="iconfont">&#xe614;</i> 63 <i class="iconfont">&#xe614;</i>
64 </span> 64 </span>
65 {{/if}} 65 {{/if}}
@@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
68 {{/ coupon}} 68 {{/ coupon}}
69 69
70 {{# yohoCoin}} 70 {{# yohoCoin}}
71 - <li class="coin"> 71 + <li class="coin" data-yoho-coin="{{.}}">
72 <span class="title">YOHO币</span> 72 <span class="title">YOHO币</span>
73 <span class="desc">可抵用¥{{.}}</span> 73 <span class="desc">可抵用¥{{.}}</span>
74 <span class="coin-check"> 74 <span class="coin-check">
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div class="my-address-page select-address-page yoho-page"> 2 <div class="my-address-page select-address-page yoho-page">
3 <div class="page-wrap"> 3 <div class="page-wrap">
4 {{# address}} 4 {{# address}}
5 - <a class="address-item" data-address-id="{{address_id}}" href="/shoppingCart/orderEnsure?address_id={{address_id}}"> 5 + <a class="address-item" data-address-id="{{address_id}}" href="/shoppingCart/orderEnsure">
6 <span class="name">{{consignee}}</span> 6 <span class="name">{{consignee}}</span>
7 <span class="tel">{{mobile}}</span> 7 <span class="tel">{{mobile}}</span>
8 <p class="address-info">{{area}} {{address}}</p> 8 <p class="address-info">{{area}} {{address}}</p>
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="yoho-page select-coupon-page my-coupon-page"> 2 <div class="yoho-page select-coupon-page my-coupon-page">
3 - <form id="search-coupon" method="POST" action=""> 3 + <form id="new-coupon" method="POST" action="">
4 <input type="text" name="couponCode" value="" placeholder="输入优惠券码"> 4 <input type="text" name="couponCode" value="" placeholder="输入优惠券码">
5 <button type="submit" class="submit">确定</button> 5 <button type="submit" class="submit">确定</button>
6 </form> 6 </form>
@@ -11,9 +11,9 @@ @@ -11,9 +11,9 @@
11 <script id="tmpl-coupon" type="text/tmpl"> 11 <script id="tmpl-coupon" type="text/tmpl">
12 \{{#coupons}} 12 \{{#coupons}}
13 \{{^ notAvailable}} 13 \{{^ notAvailable}}
14 - <a class="employ-main" data-coupon-code="{{ coupon_code}}" href="/shoppingCart/orderEnsure?coupon_code={{ coupon_code}}">  
15 - <span>\{{ money}}</span>  
16 - <p class="coupon-name">\{{ coupon_name}}</p> 14 + <a class="employ-main" data-coupon-code="\{{ couponCode}}" data-coupon-value="\{{ couponValue}}" href="/shoppingCart/orderEnsure">
  15 + <span>\{{ couponValue}}</span>
  16 + <p class="coupon-name">\{{ couponDetailInfomation}}</p>
17 <p>有效期:\{{ couponValidity}}</p> 17 <p>有效期:\{{ couponValidity}}</p>
18 </a> 18 </a>
19 \{{/ notAvailable}} 19 \{{/ notAvailable}}
@@ -22,8 +22,8 @@ @@ -22,8 +22,8 @@
22 <script id="tmpl-coupon-not-avaliable" type="text/tmpl"> 22 <script id="tmpl-coupon-not-avaliable" type="text/tmpl">
23 \{{# notAvailableCoupons}} 23 \{{# notAvailableCoupons}}
24 <div class="employ-main not-avaliable"> 24 <div class="employ-main not-avaliable">
25 - <span>\{{ money}}</span>  
26 - <p class="coupon-name">\{{ coupon_name}}</p> 25 + <span>\{{ couponValue}}</span>
  26 + <p class="coupon-name">\{{ couponDetailInfomation}}</p>
27 <p>有效期:\{{ couponValidity}}</p> 27 <p>有效期:\{{ couponValidity}}</p>
28 </div> 28 </div>
29 \{{/ notAvailableCoupons}} 29 \{{/ notAvailableCoupons}}
@@ -149,7 +149,7 @@ class ShoppingCartController extends AbstractAction @@ -149,7 +149,7 @@ class ShoppingCartController extends AbstractAction
149 $this->setNavHeader('购物车'); 149 $this->setNavHeader('购物车');
150 150
151 $cartType = $this->post('cartType', 'ordinary'); 151 $cartType = $this->post('cartType', 'ordinary');
152 - $cookieData = $this->getCookie('orderInfo', null); 152 + $cookieData = $this->getCookie('order-info', null);
153 $uid = $this->getUid(true); 153 $uid = $this->getUid(true);
154 $data = array( 154 $data = array(
155 'orderEnsurePage' => true, 155 'orderEnsurePage' => true,
@@ -319,7 +319,8 @@ class CartModel @@ -319,7 +319,8 @@ class CartModel
319 $result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id']; 319 $result['addressId'] = isset($address['address_id']) ? $address['address_id'] : $payReturn['delivery_address']['address_id'];
320 $result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee']; 320 $result['name'] = isset($address['consignee']) ? $address['consignee'] : $payReturn['delivery_address']['consignee'];
321 $result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile']; 321 $result['phoneNum'] = isset($address['mobile']) ? $address['mobile'] : $payReturn['delivery_address']['mobile'];
322 - $result['address'] = isset($address['address']) ? $address['address'] : $payReturn['delivery_address']['address']; 322 + $result['area'] = isset($address['area']) ? $address['area'] : $payReturn['delivery_address']['area'];
  323 + $result['address'] = isset($address['address']) ? $address['address'] : $payReturn['delivery_address']['address'];
323 $result['isSupport'] = ($payReturn['delivery_address']['is_support'] === 'Y'); 324 $result['isSupport'] = ($payReturn['delivery_address']['is_support'] === 'Y');
324 } 325 }
325 326
@@ -330,9 +331,11 @@ class CartModel @@ -330,9 +331,11 @@ class CartModel
330 $oneDeliv = array(); 331 $oneDeliv = array();
331 $oneDeliv['id'] = $val['delivery_way_id']; 332 $oneDeliv['id'] = $val['delivery_way_id'];
332 $oneDeliv['name'] = $val['delivery_way_name']; 333 $oneDeliv['name'] = $val['delivery_way_name'];
333 - $oneDeliv['default'] = ($val['default'] === 'Y'); 334 +
334 isset($orderInfo['deliveryId']) && $orderInfo['deliveryId'] === $oneDeliv['id'] && $oneDeliv['isSelected'] = true; 335 isset($orderInfo['deliveryId']) && $orderInfo['deliveryId'] === $oneDeliv['id'] && $oneDeliv['isSelected'] = true;
335 336
  337 + !isset($oneDeliv['isSelected']) && $oneDeliv['isSelected'] = ($val['default'] === 'Y');
  338 +
336 $result['dispatchMode'][] = $oneDeliv; 339 $result['dispatchMode'][] = $oneDeliv;
337 } 340 }
338 } 341 }
@@ -411,7 +414,7 @@ class CartModel @@ -411,7 +414,7 @@ class CartModel
411 414
412 // 优惠券数据 415 // 优惠券数据
413 $coupons = array('notUsed' => true); 416 $coupons = array('notUsed' => true);
414 - !empty($orderCompute['coupon_amount']) && $coupons['notUsed'] = $orderInfo['couponName']; 417 + !empty($orderCompute['coupon_amount']) && $coupons['value'] = $orderInfo['couponValue'];
415 $coupons += self::getCouponList($uid, 0, 1, true); 418 $coupons += self::getCouponList($uid, 0, 1, true);
416 $result['coupon'] = $coupons; 419 $result['coupon'] = $coupons;
417 } 420 }
@@ -491,7 +494,7 @@ class CartModel @@ -491,7 +494,7 @@ class CartModel
491 $val['notAvailable'] = true; 494 $val['notAvailable'] = true;
492 } 495 }
493 } 496 }
494 - !empty($couponArr) && $result['coupons'] = $couponArr; 497 + !empty($couponArr) && $result = $couponArr;
495 } 498 }
496 } 499 }
497 500