Authored by 梁志锋

购物车功能开发

framework @ 75bbc3b0
1 -Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec 1 +Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
@@ -11,7 +11,8 @@ var $ = require('jquery'); @@ -11,7 +11,8 @@ var $ = require('jquery');
11 11
12 // var $page = $('.yoho-page'); 12 // var $page = $('.yoho-page');
13 13
14 -var $num; 14 +var $num,
  15 + $chosed;
15 16
16 // var tpl; 17 // var tpl;
17 18
@@ -64,41 +65,69 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -64,41 +65,69 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
64 var $this = $(this), 65 var $this = $(this),
65 $that = $(e.target).closest('.chose-items'), 66 $that = $(e.target).closest('.chose-items'),
66 numArray, 67 numArray,
67 - index; 68 + index,
  69 + i;
68 70
69 - if ($this.hasClass('chosed')) {  
70 - $this.parent().find('.block').removeClass('chosed');  
71 - $that.find('.num .left-num').html('');  
72 - } else if ($this.hasClass('disable')) {  
73 - $this.css('background-color', '#000');  
74 - return;  
75 - } else if (!$this.hasClass('chosed')) {  
76 - $this.siblings('.chosed').removeClass('chosed');  
77 - $this.addClass('chosed');  
78 - index = $this.index(); 71 + var $siblingBlock = $this.closest('.block-list').siblings(':first'),
  72 + currentNumArray = $this.data('numstr').split('/');
79 73
  74 + $this.siblings('.chosed').removeClass('chosed');
  75 + $this.toggleClass('chosed');
  76 + index = $this.index();
  77 + $chosed = $('.block-list>ul>li.chosed');
80 78
81 - //根据颜色切换图片  
82 - if ($this.closest('.block-list').hasClass('color-list')) {  
83 - $('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');  
84 - } 79 + //根据颜色切换图片
  80 + if ($this.closest('.block-list').hasClass('color-list')) {
  81 + $('.chose-panel .basic-info').find('.thumb').addClass('hide').eq(index).removeClass('hide');
  82 + }
85 83
86 - //剩余的商品数  
87 - if ($that.find('.color-list ul>li').hasClass('chosed') && $that.find('.size-list ul>li').hasClass('chosed')) {  
88 - numArray = $this.closest('.block-list').siblings(':first').find('.chosed').data('numstr').split('/');  
89 - $that.find('.num .left-num').html('剩余' + numArray[index] + '件');  
90 - } else {  
91 - $that.find('.num .left-num').html(''); 84 + if ($chosed.length === 0) {
  85 + $this.closest('ul>li').each(function() {
  86 + $(this).removeClass('zero-stock');
  87 + if (0 === $(this).data('num') - 0) {
  88 + $(this).addClass('zero-stock');
  89 + }
  90 + });
  91 +
  92 + $siblingBlock.find('ul>li').each(function() {
  93 + $(this).removeClass('zero-stock');
  94 + if (0 === $(this).data('num') - 0) {
  95 + $(this).addClass('zero-stock');
  96 + }
  97 + });
  98 + } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
  99 + numArray = $chosed.data('numstr').split('/');
  100 + $siblingBlock.find('.block').removeClass('zero-stock');
  101 + for (i = 0; i < numArray.length; i++) {
  102 + if (0 === numArray[i] - 0) {
  103 + $siblingBlock.find('.block').eq(i).addClass('zero-stock');
  104 + }
92 } 105 }
93 -  
94 - //点击切换 106 + } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
  107 + $siblingBlock.find('ul>li').each(function() {
  108 + $(this).removeClass('zero-stock');
  109 + if (0 === $(this).data('num') - 0) {
  110 + $(this).addClass('zero-stock');
  111 + }
  112 + });
  113 + $that.find('.num .left-num').html('');
  114 + } else if ($chosed.length === 2) {
  115 + $siblingBlock.find('.block').removeClass('zero-stock');
  116 + for (i = 0; i < currentNumArray.length; i++) {
  117 + if (0 === currentNumArray[i] - 0) {
  118 + $siblingBlock.find('.block').eq(i).addClass('zero-stock');
  119 + }
  120 + }
  121 + numArray = $siblingBlock.find('.chosed').data('numstr').split('/');
  122 + $that.find('.num .left-num').html('剩余' + numArray[index] + '件');
95 } 123 }
96 124
97 }).on('touchstart', '.btn-minus', function() { 125 }).on('touchstart', '.btn-minus', function() {
98 - var num = +$num.val(); 126 + var num = +$num.val(),
  127 + $chosed = $('.block-list>ul>li.chosed');
99 128
100 //若颜色和尺码没有被同时选中,则不能点击 129 //若颜色和尺码没有被同时选中,则不能点击
101 - if ($('.block-list>ul>li.chosed').length < 2) { 130 + if ($chosed.length < 2) {
102 return; 131 return;
103 } 132 }
104 133
@@ -33,6 +33,7 @@ lazyLoad({ @@ -33,6 +33,7 @@ lazyLoad({
33 try_again_css: 'order-failure' 33 try_again_css: 'order-failure'
34 }); 34 });
35 35
  36 +
36 $names = $('.name'); 37 $names = $('.name');
37 if ($names.length > 0) { 38 if ($names.length > 0) {
38 $names[0].mlellipsis(2); 39 $names[0].mlellipsis(2);
@@ -98,8 +98,8 @@ function submitOrder() { @@ -98,8 +98,8 @@ function submitOrder() {
98 data: { 98 data: {
99 addressId: orderInfo('addressId'), 99 addressId: orderInfo('addressId'),
100 cartType: orderInfo('cartType'), 100 cartType: orderInfo('cartType'),
101 - deliveryId: orderInfo('deliveryId'),  
102 - deliveryTimeId: orderInfo('deliveryTimeId'), 101 + deliveryId: orderInfo('deliveryId') || 1,
  102 + deliveryTimeId: orderInfo('deliveryTimeId') || 1,
103 invoiceText: orderInfo('invoiceText'), 103 invoiceText: orderInfo('invoiceText'),
104 invoiceType: orderInfo('invoiceType'), 104 invoiceType: orderInfo('invoiceType'),
105 msg: orderInfo('msg'), 105 msg: orderInfo('msg'),
@@ -109,13 +109,24 @@ function submitOrder() { @@ -109,13 +109,24 @@ function submitOrder() {
109 yohoCoin: orderInfo('yohoCoin') 109 yohoCoin: orderInfo('yohoCoin')
110 } 110 }
111 }).then(function(res) { 111 }).then(function(res) {
112 - console.log(res); 112 + if (!res) {
  113 + tip.show('网络出错');
  114 + }
  115 + if (res.code !== 200) {
  116 + tip.show(res.message || '网络出错');
  117 + } else {
  118 + console.log(1);
  119 + }
113 }).fail(function() { 120 }).fail(function() {
114 tip.show('网络出错'); 121 tip.show('网络出错');
115 }); 122 });
116 } 123 }
117 124
118 // 界面点击,状态存 cookie 125 // 界面点击,状态存 cookie
  126 +if (!orderInfo('addressId')) {
  127 + orderInfo('addressId', $('.address-wrap').data('address-id'));
  128 +}
  129 +
119 $('.dispatch-mode').on('touchend', 'li', function() { 130 $('.dispatch-mode').on('touchend', 'li', function() {
120 orderInfo('deliveryId', $(this).data('id')); 131 orderInfo('deliveryId', $(this).data('id'));
121 orderCompute(); 132 orderCompute();
@@ -22,6 +22,7 @@ try { @@ -22,6 +22,7 @@ try {
22 invoiceType: null, 22 invoiceType: null,
23 msg: null 23 msg: null
24 }; 24 };
  25 + window.setCookie('order-info', JSON.stringify(info));
25 } 26 }
26 27
27 exports.orderInfo = function(key, value) { 28 exports.orderInfo = function(key, value) {
@@ -105,10 +105,16 @@ @@ -105,10 +105,16 @@
105 color: #e10; 105 color: #e10;
106 } 106 }
107 107
108 - &.disable { 108 + &.zero-stock {
109 color: #e0e0e0; 109 color: #e0e0e0;
110 border-color: #e0e0e0; 110 border-color: #e0e0e0;
111 } 111 }
  112 + &.zero-stock.chosed {
  113 + border-color: #e0e0e0;
  114 + background: none;
  115 + color: #e0e0e0;
  116 + background-color: #f0f0f0;
  117 + }
112 } 118 }
113 119
114 .num { 120 .num {
@@ -289,3 +289,36 @@ @@ -289,3 +289,36 @@
289 } 289 }
290 } 290 }
291 } 291 }
  292 +.shopping-cart-zero{
  293 + .cart-zero{
  294 + width: 100%;
  295 + height: auto;
  296 + padding-top:2rem;
  297 + padding-bottom:20%;
  298 + i{
  299 + font-size: 6em;
  300 + display: block;
  301 + margin: 0 auto;
  302 + text-align: center;
  303 + color: #505050;
  304 + }
  305 + p{
  306 + display: block;
  307 + text-align: center;
  308 + font-size: 1.2em;
  309 + color: #505050;
  310 + padding:.6rem 0;
  311 + }
  312 + a{
  313 + width: 27%;
  314 + height: 1.2rem;
  315 + overflow: hidden;
  316 + line-height: 1.2rem;
  317 + border:1px solid #505050;
  318 + border-radius:.2rem;
  319 + display: block;
  320 + margin: 0 auto;
  321 + text-align: center;
  322 + }
  323 + }
  324 +}
1 {{> layout/header}} 1 {{> layout/header}}
2 -<div id="mainCart" class="shopping-cart-page yoho-page"> 2 +<div id="mainCart" class="shopping-cart-page yoho-page" style="display: none;">
  3 +
3 {{# shoppingCart}} 4 {{# shoppingCart}}
4 {{#if cartNav}} 5 {{#if cartNav}}
5 <ul class="cart-nav clearfix"> 6 <ul class="cart-nav clearfix">
@@ -45,7 +46,6 @@ @@ -45,7 +46,6 @@
45 {{/ shoppingCart}} 46 {{/ shoppingCart}}
46 </div> 47 </div>
47 48
48 -  
49 <div id="advanceBuy" class="shopping-cart-page yoho-page hide"> 49 <div id="advanceBuy" class="shopping-cart-page yoho-page hide">
50 {{# shoppingCart}} 50 {{# shoppingCart}}
51 {{# commonCart}} 51 {{# commonCart}}
@@ -61,4 +61,13 @@ @@ -61,4 +61,13 @@
61 {{/ shoppingCart}} 61 {{/ shoppingCart}}
62 </div> 62 </div>
63 63
  64 +<div class="shopping-cart-zero yoho-page">
  65 + <div class="cart-zero">
  66 + <i class="iconfont">&#xe62c</i>
  67 + <p>您的购物车暂无商品</p>
  68 + <a href="">随便逛逛</a>
  69 + </div>
  70 + {{> product/recommend-for-you}}
  71 +</div>
  72 +
64 {{> layout/footer}} 73 {{> layout/footer}}
1 {{> layout/header}} 1 {{> layout/header}}
2 <div class="order-ensure-page yoho-page"> 2 <div class="order-ensure-page yoho-page">
3 {{# orderEnsure}} 3 {{# orderEnsure}}
4 - <a class="address-wrap block" href="/shoppingCart/selectAddress"> 4 + <a class="address-wrap block" href="/shoppingCart/selectAddress" data-address-id="{{addressId}}">
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>
@@ -206,6 +206,7 @@ @@ -206,6 +206,7 @@
206 {{#if shoppingCartPage}} 206 {{#if shoppingCartPage}}
207 <script> 207 <script>
208 seajs.use('js/shopping-cart/cart'); 208 seajs.use('js/shopping-cart/cart');
  209 + seajs.use('js/product/recommend-for-you');
209 </script> 210 </script>
210 {{/if}} 211 {{/if}}
211 {{#if giftAdvancePage}} 212 {{#if giftAdvancePage}}
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 <span>颜色</span> 25 <span>颜色</span>
26 <ul class="clearfix" data-type="color"> 26 <ul class="clearfix" data-type="color">
27 {{# colors}} 27 {{# colors}}
28 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{sizeNumStr}}"> 28 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless colorNum}}zero-stock{{/unless}}" data-num="{{colorNum}}" data-numstr="{{sizeNumStr}}">
29 {{name}} 29 {{name}}
30 </li> 30 </li>
31 {{/ colors}} 31 {{/ colors}}
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
35 <span>尺码</span> 35 <span>尺码</span>
36 <ul class="clearfix" data-type="size" > 36 <ul class="clearfix" data-type="size" >
37 {{# sizes}} 37 {{# sizes}}
38 - <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}disable{{/unless}}" data-id={{id}} data-numstr="{{colorNumStr}}"> 38 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}">
39 {{name}} 39 {{name}}
40 </li> 40 </li>
41 {{/ sizes}} 41 {{/ sizes}}
@@ -195,7 +195,7 @@ class ShoppingCartController extends AbstractAction @@ -195,7 +195,7 @@ class ShoppingCartController extends AbstractAction
195 'orderEnsurePage' => true, 195 'orderEnsurePage' => true,
196 'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData) 196 'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData)
197 ); 197 );
198 - 198 + // var_dump($data);
199 $this->_view->display('order-ensure', $data); 199 $this->_view->display('order-ensure', $data);
200 } 200 }
201 201