Authored by 毕凯

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -20,11 +20,15 @@ var panelTmpl, @@ -20,11 +20,15 @@ var panelTmpl,
20 $chosed, 20 $chosed,
21 re = /\d+/, 21 re = /\d+/,
22 leftNum, 22 leftNum,
23 - $colorList,  
24 $sizeList, 23 $sizeList,
25 - firstColorId,  
26 colorIndex, 24 colorIndex,
27 - confirming; 25 + confirming,
  26 + hasChooseColor = false,
  27 + hasChooseSize = false,
  28 + curColorIndex,
  29 + curSizeIndex,
  30 + $curSizeRow,
  31 + $sizeRowList = $('.size-list ul');
28 32
29 // 读取模板 33 // 读取模板
30 $.get('/cart/index/giftinfoTpl', function(html) { 34 $.get('/cart/index/giftinfoTpl', function(html) {
@@ -39,45 +43,43 @@ $.get('/cart/index/giftinfoTpl', function(html) { @@ -39,45 +43,43 @@ $.get('/cart/index/giftinfoTpl', function(html) {
39 43
40 //初始化购物车面板显示 44 //初始化购物车面板显示
41 function init() { 45 function init() {
42 - $colorList = $('.chose-panel .color-list ul>li');  
43 - $sizeList = $('.chose-panel .size-list ul>li');  
44 - firstColorId = $colorList.eq(0).data('id');  
45 - $sizeList.each(function() {  
46 - colorIndex = $(this).data('colorid');  
47 46
48 - if (colorIndex === firstColorId) {  
49 - $(this).removeClass('hide');  
50 - }  
51 - }); 47 + //$colorList = $('.chose-panel .color-list ul>li');
  48 + //$sizeList = $('.chose-panel .size-list ul>li');
  49 + //firstColorId = $colorList.eq(0).data('id');
  50 + //$sizeList.each(function() {
  51 + // colorIndex = $(this).data('colorid');
  52 + //
  53 + // if (colorIndex === firstColorId) {
  54 + // $(this).removeClass('hide');
  55 + // }
  56 + //});
  57 +
  58 + var $firstRow = $sizeRowList.eq(0);
  59 +
  60 + $firstRow.toggleClass('hide');
  61 + $curSizeRow = $firstRow;
52 } 62 }
53 63
54 init(); 64 init();
55 65
56 -//显示  
57 -// function show(data) {  
58 -// // var html = tpl(data);  
59 -// $('.chose-panel').show();  
60 -// // $page.append(html);  
61 -// $('.chose-panel')  
62 -// $num = $('#good-num');  
63 -// }  
64 -  
65 -  
66 -  
67 function show(data) { 66 function show(data) {
68 if (data) { 67 if (data) {
69 $chosePanel.html(panelTmpl(data)); 68 $chosePanel.html(panelTmpl(data));
70 init(); 69 init();
71 } 70 }
  71 +}
72 72
  73 +//显示当前Panel
  74 +function show() {
73 $('.chose-panel').show(); 75 $('.chose-panel').show();
74 76
75 $('body').css('overflow', 'hidden'); 77 $('body').css('overflow', 'hidden');
76 $num = $('#good-num'); 78 $num = $('#good-num');
77 } 79 }
78 80
79 -//移除当前Panel  
80 -function remove() { 81 +//隐藏当前Panel
  82 +function hide() {
81 $('.chose-panel').hide(); 83 $('.chose-panel').hide();
82 $('body').css('overflow', 'auto'); 84 $('body').css('overflow', 'auto');
83 } 85 }
@@ -90,57 +92,129 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -90,57 +92,129 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
90 } 92 }
91 93
92 //点击蒙版消失 94 //点击蒙版消失
93 - remove();  
94 -}).on('touchstart', '#chose-btn-sure', function() { 95 + hide();
  96 +});
95 97
96 - var productSku,  
97 - buyNumber = $('#good-num').val() - 0, 98 +$('.color-list').on('touchstart', '.block', function(e) {
  99 + var $this = $(this),
  100 + $that = $(e.target).closest('.chose-items'),
  101 + numArray,
  102 + index,
  103 + curSelectedSizeBlock,
  104 + $sizeChosed,
  105 + scindex,
  106 + i;
98 107
99 - promotionId,  
100 - isEdit = 0,  
101 - numInCart = $('.num-tag').html() - 0; 108 + var $siblingBlock = $this.closest('.block-list').siblings(':first'),
  109 + currentNumArray = ($this.data('numstr') + '').split('/');
102 110
103 - // goodsType,  
104 - // isEdit; 111 + $this.siblings('.chosed').removeClass('chosed');
  112 + index = $this.index();
105 113
106 - $chosed = $('.block-list>ul>li.chosed'); 114 + $sizeChosed = $siblingBlock.find('.chosed');
  115 + scindex = $sizeChosed.index();
  116 + $curSizeRow = $sizeRowList.eq(index);
107 117
108 - if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {  
109 - productSku = $sizeList.closest('.chosed').data('skuid');  
110 - promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');  
111 - if (confirming) {  
112 - return false; 118 + // 当前颜色已经是选中状态,再点击时
  119 + if ($this.hasClass('chosed')) {
  120 +
  121 + //颜色原来已经是勾选时,要清空剩余件数的提示
  122 + $that.find('.num .left-num').html('');
  123 + hasChooseColor = false;
  124 +
  125 + // 当前颜色不是选中状态,选中时
  126 + } else {
  127 + hasChooseColor = true;
  128 +
  129 + //根据颜色切换图片
  130 + if ($this.closest('.block-list').hasClass('color-list')) {
  131 + $('.chose-panel').find('.thumb').addClass('hide').eq(index).removeClass('hide');
113 } 132 }
114 133
115 - confirming = true;  
116 - loading.showLoadingMask();  
117 - $.ajax({  
118 - method: 'POST',  
119 - url: '/cart/index/add',  
120 - data: {  
121 - productSku: productSku,  
122 - buyNumber: buyNumber,  
123 - promotionId: promotionId,  
124 - isEdit: isEdit 134 + //把当前选中颜色对应的尺码那一行显示出来
  135 + //$sizeRowList.addClass('hide');
  136 + //$curSizeRow.toggleClass('hide');
  137 +
  138 + //之前选中行 对应的尺码去掉勾选样式
  139 + $sizeChosed.removeClass('chosed');
  140 +
  141 + // 当前选中颜色对应的尺码行,其对应的尺码加上 (前提是要判断下这个尺码是否存在)
  142 + curSelectedSizeBlock = $curSizeRow.children().get(scindex);
  143 + if (curSelectedSizeBlock) {
  144 + $(curSelectedSizeBlock).addClass('chosed');
125 } 145 }
126 - }).done(function(res) {  
127 - loading.hideLoadingMask();  
128 - if (res.code === 200) {  
129 - $('.num-tag').html(numInCart + buyNumber);  
130 - $('.num-tag').removeClass('hide');  
131 - remove();  
132 } 146 }
133 - if (res.message) {  
134 - tip.show(res.message); 147 +
  148 + $this.toggleClass('chosed');
  149 + curColorIndex = index;
  150 +
  151 + $chosed = $('.chose-items').find('.chosed');
  152 +
  153 +
  154 + if ($chosed.length === 0) {
  155 + $this.closest('ul>li').each(function() {
  156 + $(this).removeClass('zero-stock');
  157 + if ('0' === $(this).data('num')) {
  158 + $(this).addClass('zero-stock');
135 } 159 }
136 - }).fail(function() {  
137 - tip.show('网络出了点问题~');  
138 - }).always(function() {  
139 - confirming = false;  
140 }); 160 });
  161 +
  162 + $siblingBlock.find('ul>li').each(function() {
  163 + $(this).removeClass('zero-stock');
  164 + if ('0' === $(this).data('num')) {
  165 + $(this).addClass('zero-stock');
141 } 166 }
  167 + });
  168 + } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
  169 + $sizeList.addClass('hide');
142 170
143 -}).on('touchstart', '.block', function(e) { 171 + //切换尺码信息
  172 + $sizeList.each(function() {
  173 + colorIndex = $(this).data('colorid');
  174 + if (colorIndex === $this.data('id')) {
  175 + $(this).removeClass('hide');
  176 + }
  177 + });
  178 +
  179 + numArray = ($chosed.data('numstr') + '').split('/');
  180 + $siblingBlock.find('.block').removeClass('zero-stock');
  181 + for (i = 0; i < numArray.length; i++) {
  182 + if ('0' === numArray[i]) {
  183 + $siblingBlock.find('.block').eq(i).addClass('zero-stock');
  184 + }
  185 + }
  186 + } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
  187 + $('#chose-btn-sure').css('background-color', '#eb0313');
  188 + $('#chose-btn-sure').html('确定');
  189 +
  190 + $siblingBlock.find('ul>li').each(function() {
  191 + $(this).removeClass('zero-stock');
  192 + if ('0' === $(this).data('num')) {
  193 + $(this).addClass('zero-stock');
  194 + }
  195 + });
  196 + $that.find('.num .left-num').html('');
  197 + } else if ($chosed.length === 2) {
  198 + $siblingBlock.find('.block').removeClass('zero-stock');
  199 + for (i = 0; i < currentNumArray.length; i++) {
  200 + if ('0' === currentNumArray[i]) {
  201 + $siblingBlock.find('.block').eq(i).addClass('zero-stock');
  202 + }
  203 + }
  204 + numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
  205 + $that.find('.num .left-num').html('剩余' + numArray[index] + '件');
  206 + if (2 === $chosed.closest('.zero-stock').length) {
  207 + $('#chose-btn-sure').css('background-color', '#c0c0c0');
  208 + $('#chose-btn-sure').html('已售罄');
  209 + } else {
  210 + $('#chose-btn-sure').css('background-color', '#eb0313');
  211 + $('#chose-btn-sure').html('确定');
  212 + }
  213 + }
  214 +
  215 +});
  216 +
  217 +$('.size-list').on('touchstart', '.block', function(e) {
144 var $this = $(this), 218 var $this = $(this),
145 $that = $(e.target).closest('.chose-items'), 219 $that = $(e.target).closest('.chose-items'),
146 numArray, 220 numArray,
@@ -151,26 +225,33 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -151,26 +225,33 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
151 currentNumArray = ($this.data('numstr') + '').split('/'); 225 currentNumArray = ($this.data('numstr') + '').split('/');
152 226
153 $this.siblings('.chosed').removeClass('chosed'); 227 $this.siblings('.chosed').removeClass('chosed');
154 - $this.toggleClass('chosed');  
155 index = $this.index(); 228 index = $this.index();
156 - $chosed = $('.block-list>ul>li.chosed');  
157 229
158 - //根据颜色切换图片  
159 - if ($this.closest('.block-list').hasClass('color-list')) {  
160 - $('.chose-panel').find('.thumb').addClass('hide').eq(index).removeClass('hide'); 230 + if ($this.hasClass('chosed')) {
  231 +
  232 + //尺码原来已经是勾选时,要清空剩余件数的提示
  233 + $that.find('.num .left-num').html('');
  234 + hasChooseSize = false;
  235 + } else {
  236 + hasChooseSize = true;
161 } 237 }
162 238
  239 + $this.toggleClass('chosed');
  240 + curSizeIndex = index;
  241 +
  242 + $chosed = $('.chose-items').find('.chosed');
  243 +
163 if ($chosed.length === 0) { 244 if ($chosed.length === 0) {
164 $this.closest('ul>li').each(function() { 245 $this.closest('ul>li').each(function() {
165 $(this).removeClass('zero-stock'); 246 $(this).removeClass('zero-stock');
166 - if (0 === $(this).data('num') - 0) { 247 + if ('0' === $(this).data('num')) {
167 $(this).addClass('zero-stock'); 248 $(this).addClass('zero-stock');
168 } 249 }
169 }); 250 });
170 251
171 $siblingBlock.find('ul>li').each(function() { 252 $siblingBlock.find('ul>li').each(function() {
172 $(this).removeClass('zero-stock'); 253 $(this).removeClass('zero-stock');
173 - if (0 === $(this).data('num') - 0) { 254 + if ('0' === $(this).data('num')) {
174 $(this).addClass('zero-stock'); 255 $(this).addClass('zero-stock');
175 } 256 }
176 }); 257 });
@@ -191,7 +272,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -191,7 +272,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
191 numArray = ($chosed.data('numstr') + '').split('/'); 272 numArray = ($chosed.data('numstr') + '').split('/');
192 $siblingBlock.find('.block').removeClass('zero-stock'); 273 $siblingBlock.find('.block').removeClass('zero-stock');
193 for (i = 0; i < numArray.length; i++) { 274 for (i = 0; i < numArray.length; i++) {
194 - if (0 === numArray[i] - 0) { 275 + if ('0' === numArray[i]) {
195 $siblingBlock.find('.block').eq(i).addClass('zero-stock'); 276 $siblingBlock.find('.block').eq(i).addClass('zero-stock');
196 } 277 }
197 } 278 }
@@ -199,17 +280,17 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -199,17 +280,17 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
199 $('#chose-btn-sure').css('background-color', '#eb0313'); 280 $('#chose-btn-sure').css('background-color', '#eb0313');
200 $('#chose-btn-sure').html('确定'); 281 $('#chose-btn-sure').html('确定');
201 282
202 - $siblingBlock.find('ul>li').each(function() { 283 + /**$siblingBlock.find('ul>li').each(function() {
203 $(this).removeClass('zero-stock'); 284 $(this).removeClass('zero-stock');
204 - if (0 === $(this).data('num') - 0) { 285 + if ('0' === $(this).data('num')) {
205 $(this).addClass('zero-stock'); 286 $(this).addClass('zero-stock');
206 } 287 }
207 }); 288 });
208 - $that.find('.num .left-num').html(''); 289 + $that.find('.num .left-num').html('');*/
209 } else if ($chosed.length === 2) { 290 } else if ($chosed.length === 2) {
210 $siblingBlock.find('.block').removeClass('zero-stock'); 291 $siblingBlock.find('.block').removeClass('zero-stock');
211 for (i = 0; i < currentNumArray.length; i++) { 292 for (i = 0; i < currentNumArray.length; i++) {
212 - if (0 === currentNumArray[i] - 0) { 293 + if ('0' === currentNumArray[i]) {
213 $siblingBlock.find('.block').eq(i).addClass('zero-stock'); 294 $siblingBlock.find('.block').eq(i).addClass('zero-stock');
214 } 295 }
215 } 296 }
@@ -224,8 +305,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -224,8 +305,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
224 } 305 }
225 } 306 }
226 307
227 -}).on('touchstart', '.btn-minus', function() {  
228 - var num = +$num.val(), 308 +});
  309 +
  310 +$('.btn-minus').on('touchstart', function() {
  311 + var num = $num.val(),
229 $chosed = $('.block-list>ul>li.chosed'), 312 $chosed = $('.block-list>ul>li.chosed'),
230 leftNum = re.exec($('.num .left-num').html()); 313 leftNum = re.exec($('.num .left-num').html());
231 314
@@ -239,11 +322,14 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -239,11 +322,14 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
239 } 322 }
240 323
241 $num.val(num - 1); 324 $num.val(num - 1);
242 -}).on('touchstart', '.btn-plus', function() {  
243 - var num = +$num.val(); 325 +});
  326 +
  327 +$('.btn-plus').on('touchstart', function() {
  328 + var num = $num.val();
244 329
245 //若颜色和尺码没有被同时选中,则不能点击 330 //若颜色和尺码没有被同时选中,则不能点击
246 if ($('.block-list>ul>li.chosed').length < 2) { 331 if ($('.block-list>ul>li.chosed').length < 2) {
  332 + tip.show('请选择颜色和尺码~');
247 return; 333 return;
248 } 334 }
249 leftNum = re.exec($('.num .left-num').html()); 335 leftNum = re.exec($('.num .left-num').html());
@@ -255,5 +341,57 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -255,5 +341,57 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
255 $num.val(num + 1); 341 $num.val(num + 1);
256 }); 342 });
257 343
  344 +$('#chose-btn-sure').on('touchend', function() {
  345 +
  346 + var productSku,
  347 + buyNumber = $('#good-num').val() - 0,
  348 +
  349 + promotionId,
  350 + isEdit = 0,
  351 + numInCart = $('.num-tag').html() - 0;
  352 +
  353 + // goodsType,
  354 + // isEdit;
  355 +
  356 + $chosed = $('.block-list>ul>li.chosed');
  357 +
  358 + if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {
  359 + productSku = $sizeList.closest('.chosed').data('skuid');
  360 + promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');
  361 + if (confirming) {
  362 + return false;
  363 + }
  364 +
  365 + confirming = true;
  366 + loading.showLoadingMask();
  367 + $.ajax({
  368 + method: 'POST',
  369 + url: '/cart/index/add',
  370 + data: {
  371 + productSku: productSku,
  372 + buyNumber: buyNumber,
  373 + promotionId: promotionId,
  374 + isEdit: isEdit
  375 + }
  376 + }).done(function(res) {
  377 + loading.hideLoadingMask();
  378 + if (res.code === 200) {
  379 + $('.num-tag').html(numInCart + buyNumber);
  380 + $('.num-tag').removeClass('hide');
  381 + confirming = false;
  382 + hide();
  383 + }
  384 + if (res.message) {
  385 + tip.show(res.message);
  386 + }
  387 + }).fail(function() {
  388 + tip.show('网络出了点问题~');
  389 + }).always(function() {
  390 + confirming = false;
  391 + });
  392 + }
  393 +
  394 +});
  395 +
258 exports.init = init; 396 exports.init = init;
259 exports.show = show; 397 exports.show = show;
@@ -124,6 +124,7 @@ $loginBtn.on('touchstart', function() { @@ -124,6 +124,7 @@ $loginBtn.on('touchstart', function() {
124 }); 124 });
125 } else { 125 } else {
126 showErrTip('账号或密码有错误,请重新输入'); 126 showErrTip('账号或密码有错误,请重新输入');
  127 + $loginBtn.text('登录').removeClass('disable');
127 } 128 }
128 }); 129 });
129 130
@@ -126,6 +126,7 @@ $loginBtn.on('touchstart', function() { @@ -126,6 +126,7 @@ $loginBtn.on('touchstart', function() {
126 }); 126 });
127 } else { 127 } else {
128 showErrTip('账号或密码有错误,请重新输入'); 128 showErrTip('账号或密码有错误,请重新输入');
  129 + $loginBtn.text('登录').removeClass('disable');
129 } 130 }
130 }); 131 });
131 132
@@ -33,14 +33,15 @@ @@ -33,14 +33,15 @@
33 </div> 33 </div>
34 <div class="size-list block-list"> 34 <div class="size-list block-list">
35 <span>尺码</span> 35 <span>尺码</span>
36 -  
37 - <ul class="clearfix" data-type="size" >  
38 {{# sizes}} 36 {{# sizes}}
39 - <li class="block hide {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}"> 37 + {{# size}}
  38 + <ul class="size-row clearfix" data-type="size" >
  39 + <li class="block {{#if chosed}}chosed{{/if}} {{#unless sizeNum}}zero-stock{{/unless}}" data-id={{id}} data-colorid="{{colorId}}" data-num="{{sizeNum}}" data-numstr="{{colorNumStr}}" data-skuid="{{skuId}}" data-goodid="{{goodsId}}">
40 {{name}} 40 {{name}}
41 </li> 41 </li>
42 - {{/ sizes}}  
43 </ul> 42 </ul>
  43 + {{/ size}}
  44 + {{/ sizes}}
44 </div> 45 </div>
45 <div class="num"> 46 <div class="num">
46 <span>数量</span> 47 <span>数量</span>
@@ -60,6 +61,6 @@ @@ -60,6 +61,6 @@
60 <div class="btn-wrap"> 61 <div class="btn-wrap">
61 <button id="chose-btn-sure" class="btn btn-sure">确定</button> 62 <button id="chose-btn-sure" class="btn btn-sure">确定</button>
62 </div> 63 </div>
63 - </div>  
64 </div> 64 </div>
65 -{{/cartInfo}}  
  65 + </div>
  66 + {{/cartInfo}}
@@ -44,7 +44,6 @@ class DetailController extends AbstractAction @@ -44,7 +44,6 @@ class DetailController extends AbstractAction
44 $this->setTitle($data['goodsName']); 44 $this->setTitle($data['goodsName']);
45 } 45 }
46 $this->setNavHeader('商品详情'); 46 $this->setNavHeader('商品详情');
47 -  
48 // 渲染模板 47 // 渲染模板
49 $this->_view->display('index', $data); 48 $this->_view->display('index', $data);
50 } 49 }