Authored by 毕凯

code review by liangzhifeng

@@ -231,6 +231,23 @@ $('.nav-home').on('touchstart', function() { @@ -231,6 +231,23 @@ $('.nav-home').on('touchstart', function() {
231 window.cancelAnimationFrame = cancelAnimationFrame; 231 window.cancelAnimationFrame = cancelAnimationFrame;
232 }()); 232 }());
233 233
  234 +// 给jQuery 扩展 queryString函数
  235 +$.extend({
  236 + queryString: function() {
  237 + var vars = [],
  238 + hash,
  239 + i;
  240 + var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  241 +
  242 + for (i = 0; i < hashes.length; i++) {
  243 + hash = hashes[i].split('=');
  244 + vars.push(hash[0]);
  245 + vars[hash[0]] = hash[1];
  246 + }
  247 + return vars;
  248 + }
  249 +});
  250 +
234 //暴露公共接口 251 //暴露公共接口
235 window.cookie = cookie; 252 window.cookie = cookie;
236 253
@@ -20,7 +20,8 @@ var $addressForm = $('.edit-address'), @@ -20,7 +20,8 @@ var $addressForm = $('.edit-address'),
20 $area = $('.area'), 20 $area = $('.area'),
21 isSubmiting, 21 isSubmiting,
22 currentPage = 'edit', 22 currentPage = 'edit',
23 - newArea = []; 23 + newArea = [],
  24 + queryString = $.queryString();
24 25
25 $($editAddressPage, $addressListPage).css('min-height', function() { 26 $($editAddressPage, $addressListPage).css('min-height', function() {
26 return $(window).height() - $('#yoho-header').height(); 27 return $(window).height() - $('#yoho-header').height();
@@ -91,7 +92,11 @@ $addressForm.on('submit', function() { @@ -91,7 +92,11 @@ $addressForm.on('submit', function() {
91 isSubmiting = false; 92 isSubmiting = false;
92 loading.hideLoadingMask(); 93 loading.hideLoadingMask();
93 } else { 94 } else {
94 - window.location.href = '/home/address'; 95 + if (queryString.refer === 'shopping') {
  96 + window.location.href = '/shoppingCart/selectAddress';
  97 + } else {
  98 + window.location.href = '/home/address';
  99 + }
95 } 100 }
96 }).fail(function() { 101 }).fail(function() {
97 tip.show('网络出了点问题~'); 102 tip.show('网络出了点问题~');
@@ -69,4 +69,5 @@ $addAddress.on('touchend', function() { @@ -69,4 +69,5 @@ $addAddress.on('touchend', function() {
69 $action.on('touchend', '.del', function() { 69 $action.on('touchend', '.del', function() {
70 deleteId = $(this).data('id'); 70 deleteId = $(this).data('id');
71 $confim.fadeIn(); 71 $confim.fadeIn();
  72 + return false;
72 }); 73 });
@@ -6,4 +6,6 @@ @@ -6,4 +6,6 @@
6 6
7 require('./cart'); 7 require('./cart');
8 require('./gift-advance'); 8 require('./gift-advance');
9 -require('./order-ensure');  
  9 +require('./order-ensure');
  10 +require('./select-coupon');
  11 +require('./select-address');
  1 +/**
  2 + * 购物车 地址选择
  3 + * @author: bikai<kai.bi@yoho.cn>
  4 + * @date: 2015/12/14
  5 + */
  6 +
  7 +var $ = require('jquery'),
  8 + orderInfo = require('./order-info');
  9 +
  10 +$('.address-item').on('touchend', function() {
  11 + orderInfo('addressId', $(this).data('address_id'));
  12 +}).on('touchend', '.edit', function() {
  13 + window.location.href = $(this).data('href');
  14 + return false;
  15 +});
1 -@import "good", "chose-panel", "gift-advance-good", "order-ensure", "select-coupon"; 1 +@import "good", "chose-panel", "gift-advance-good", "order-ensure", "select-coupon", "select-address";
2 2
3 3
4 .icon-checkbox:before { content: "\e61c"; } 4 .icon-checkbox:before { content: "\e61c"; }
  1 +.select-address-page {
  2 + padding-bottom: pxToRem(20px);
  3 +
  4 + .add-address {
  5 + margin-bottom: 0;
  6 + }
  7 +
  8 +}
@@ -2,12 +2,36 @@ @@ -2,12 +2,36 @@
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" href="/shoppingCart/orderEnsure?address_id={{address_id}}"> 5 + <a class="address-item" data-address-id="{{address_id}}" href="/shoppingCart/orderEnsure?address_id={{address_id}}">
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>
  9 + <div class="action iconfont">
  10 + <span class="edit" data-href="/home/addressAct?id={{address_id}}&refer=shopping">&#xe61e;</span>
  11 + <span class="del" data-id="{{address_id}}">&#xe621;</span>
  12 + </div>
9 </a> 13 </a>
10 {{/ address}} 14 {{/ address}}
  15 +
  16 + <a class="add-address" data-href="/home/addressAct?refer=shopping">
  17 + 添加新地址
  18 + </a>
  19 +
  20 + <div class="confim-mask hide">
  21 + <div class="confim-box">
  22 + <div class="content">
  23 + 您确定要删除地址?
  24 + </div>
  25 + <div class="action">
  26 + <span class="cancel">
  27 + 取消
  28 + </span>
  29 + <span class="confim">
  30 + 确认
  31 + </span>
  32 + </div>
  33 + </div>
  34 + </div>
11 </div> 35 </div>
12 </div> 36 </div>
13 {{> layout/footer}} 37 {{> layout/footer}}
@@ -218,6 +218,12 @@ @@ -218,6 +218,12 @@
218 seajs.use('js/shopping-cart/order-ensure'); 218 seajs.use('js/shopping-cart/order-ensure');
219 </script> 219 </script>
220 {{/if}} 220 {{/if}}
  221 +{{#if selectAddressPage}}
  222 +<script>
  223 + seajs.use('js/me/address');
  224 + seajs.use('js/shopping-cart/select-address');
  225 +</script>
  226 +{{/if}}
221 {{#if selectCouponPage}} 227 {{#if selectCouponPage}}
222 <script> 228 <script>
223 seajs.use('js/shopping-cart/select-coupon'); 229 seajs.use('js/shopping-cart/select-coupon');
@@ -386,7 +386,7 @@ class ShoppingCartController extends AbstractAction @@ -386,7 +386,7 @@ class ShoppingCartController extends AbstractAction
386 $this->setTitle('选择地址'); 386 $this->setTitle('选择地址');
387 $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure')); 387 $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure'));
388 388
389 - $uid = $this->_uid; 389 + $uid = $this->getUid(true);
390 $address = UserModel::getAddressData($uid); 390 $address = UserModel::getAddressData($uid);
391 391
392 $this->_view->display('select-address', array( 392 $this->_view->display('select-address', array(
@@ -405,7 +405,7 @@ class ShoppingCartController extends AbstractAction @@ -405,7 +405,7 @@ class ShoppingCartController extends AbstractAction
405 $this->setTitle('选择优惠券'); 405 $this->setTitle('选择优惠券');
406 $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure')); 406 $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure'));
407 407
408 - $uid = $this->_uid; 408 + $uid = $this->getUid(true);
409 $address = UserModel::getAddressData($uid); 409 $address = UserModel::getAddressData($uid);
410 410
411 $this->_view->display('select-coupon', array( 411 $this->_view->display('select-coupon', array(