Authored by 梁志锋

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

@@ -216,9 +216,9 @@ $yohoPage.on('touchstart', '.tap-hightlight', function() { @@ -216,9 +216,9 @@ $yohoPage.on('touchstart', '.tap-hightlight', function() {
216 $(this).removeClass('highlight'); 216 $(this).removeClass('highlight');
217 }); 217 });
218 218
219 -$('.nav-home').on('touchstart', function() {  
220 - $('.homebuttom').toggleClass('none');  
221 -}); 219 +// $('.nav-home').on('touchstart', function() {
  220 +// $('.homebuttom').toggleClass('none');
  221 +// });
222 222
223 (function() { 223 (function() {
224 var lastTime = 0, 224 var lastTime = 0,
@@ -5145,6 +5145,8 @@ function request() { @@ -5145,6 +5145,8 @@ function request() {
5145 requesting = false; 5145 requesting = false;
5146 end = true; 5146 end = true;
5147 5147
  5148 + window.rePosFooter();
  5149 +
5148 }).fail(function() { 5150 }).fail(function() {
5149 $recommendForYou.hide(); 5151 $recommendForYou.hide();
5150 }); 5152 });
@@ -5152,7 +5154,7 @@ function request() { @@ -5152,7 +5154,7 @@ function request() {
5152 } 5154 }
5153 5155
5154 function scrollHandler() { 5156 function scrollHandler() {
5155 - if (!end || $(window).scrollTop() + winH >= $(document).height() - 50) { 5157 + if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
5156 request(); 5158 request();
5157 } 5159 }
5158 } 5160 }
@@ -5173,7 +5175,7 @@ define("js/product/detail/like", ["jquery","hammer"], function(require, exports, @@ -5173,7 +5175,7 @@ define("js/product/detail/like", ["jquery","hammer"], function(require, exports,
5173 var $ = require("jquery"), 5175 var $ = require("jquery"),
5174 Hammer = require("hammer"), 5176 Hammer = require("hammer"),
5175 tip = require("js/plugin/tip"), 5177 tip = require("js/plugin/tip"),
5176 - chosePanel = require("js/shopping-cart/chose-panel"); 5178 + chosePanel = require("js/cart/chose-panel");
5177 5179
5178 var likeEle = document.getElementById('likeBtn'), 5180 var likeEle = document.getElementById('likeBtn'),
5179 likeHammer = likeEle && new Hammer(likeEle); 5181 likeHammer = likeEle && new Hammer(likeEle);
@@ -5249,11 +5251,8 @@ if (addToCartHammer) { @@ -5249,11 +5251,8 @@ if (addToCartHammer) {
5249 }); 5251 });
5250 } 5252 }
5251 5253
5252 -  
5253 -  
5254 -  
5255 }); 5254 });
5256 -define("js/shopping-cart/chose-panel", ["jquery"], function(require, exports, module){ 5255 +define("js/cart/chose-panel", ["jquery"], function(require, exports, module){
5257 /** 5256 /**
5258 * 购物车选择尺寸、颜色和数量面板 5257 * 购物车选择尺寸、颜色和数量面板
5259 * 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML 5258 * 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML
@@ -5261,14 +5260,34 @@ define("js/shopping-cart/chose-panel", ["jquery"], function(require, exports, mo @@ -5261,14 +5260,34 @@ define("js/shopping-cart/chose-panel", ["jquery"], function(require, exports, mo
5261 * @date: 2015/10/21 5260 * @date: 2015/10/21
5262 */ 5261 */
5263 5262
5264 -var $ = require("jquery"); 5263 +var $ = require("jquery"),
  5264 + tip = require("js/plugin/tip"),
  5265 + loading = require("js/plugin/loading");
5265 5266
5266 // Handlebars = require('yoho.handlebars'); 5267 // Handlebars = require('yoho.handlebars');
5267 5268
5268 // var $page = $('.yoho-page'); 5269 // var $page = $('.yoho-page');
5269 5270
5270 var $num, 5271 var $num,
5271 - $chosed; 5272 + $chosed,
  5273 + re = /\d+/,
  5274 + leftNum,
  5275 + $colorList = $('.color-list ul>li'),
  5276 + $sizeList = $('.size-list ul>li'),
  5277 + firstColorId = $colorList.eq(0).data('id'),
  5278 + colorIndex,
  5279 + confirming;
  5280 +
  5281 +//初始化购物车面板显示
  5282 +$sizeList.each(function() {
  5283 + colorIndex = $(this).data('colorid');
  5284 +
  5285 + if (colorIndex === firstColorId) {
  5286 + $(this).removeClass('hide');
  5287 + }
  5288 +});
  5289 +
  5290 +
5272 5291
5273 // var tpl; 5292 // var tpl;
5274 5293
@@ -5291,8 +5310,11 @@ var $num, @@ -5291,8 +5310,11 @@ var $num,
5291 // $num = $('#good-num'); 5310 // $num = $('#good-num');
5292 // } 5311 // }
5293 5312
  5313 +
  5314 +
5294 function show() { 5315 function show() {
5295 $('.chose-panel').show(); 5316 $('.chose-panel').show();
  5317 +
5296 $('body').css('overflow', 'hidden'); 5318 $('body').css('overflow', 'hidden');
5297 $num = $('#good-num'); 5319 $num = $('#good-num');
5298 } 5320 }
@@ -5314,10 +5336,52 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -5314,10 +5336,52 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
5314 remove(); 5336 remove();
5315 }).on('touchstart', '#chose-btn-sure', function() { 5337 }).on('touchstart', '#chose-btn-sure', function() {
5316 5338
5317 - //确定  
5318 -}).on('touchstart', '.block', function(e) { 5339 + var productSku,
  5340 + buyNumber = $('#good-num').val() - 0,
  5341 +
  5342 + promotionId,
  5343 + isEdit = 0,
  5344 + numInCart = $('.num-tag').html() - 0;
  5345 +
  5346 + // goodsType,
  5347 + // isEdit;
5319 5348
5320 - //尺寸颜色点选 5349 + $chosed = $('.block-list>ul>li.chosed');
  5350 +
  5351 + if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {
  5352 + productSku = $sizeList.closest('.chosed').data('skuid');
  5353 + promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');
  5354 + if (confirming) {
  5355 + return false;
  5356 + }
  5357 +
  5358 + confirming = true;
  5359 + loading.showLoadingMask();
  5360 + $.ajax({
  5361 + method: 'POST',
  5362 + url: '/cart/index/add',
  5363 + data: {
  5364 + productSku: productSku,
  5365 + buyNumber: buyNumber,
  5366 + promotionId: promotionId,
  5367 + isEdit: isEdit
  5368 + }
  5369 + }).done(function(res) {
  5370 + if (res.code === 200) {
  5371 + loading.hideLoadingMask();
  5372 + $('.num-tag').html(numInCart + buyNumber);
  5373 + $('.num-tag').removeClass('hide');
  5374 + confirming = false;
  5375 + remove();
  5376 + }
  5377 + }).fail(function() {
  5378 + tip.show('网络出了点问题~');
  5379 +
  5380 + confirming = false;
  5381 + });
  5382 + }
  5383 +
  5384 +}).on('touchstart', '.block', function(e) {
5321 var $this = $(this), 5385 var $this = $(this),
5322 $that = $(e.target).closest('.chose-items'), 5386 $that = $(e.target).closest('.chose-items'),
5323 numArray, 5387 numArray,
@@ -5325,7 +5389,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -5325,7 +5389,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
5325 i; 5389 i;
5326 5390
5327 var $siblingBlock = $this.closest('.block-list').siblings(':first'), 5391 var $siblingBlock = $this.closest('.block-list').siblings(':first'),
5328 - currentNumArray = $this.data('numstr').split('/'); 5392 + currentNumArray = ($this.data('numstr') + '').split('/');
5329 5393
5330 $this.siblings('.chosed').removeClass('chosed'); 5394 $this.siblings('.chosed').removeClass('chosed');
5331 $this.toggleClass('chosed'); 5395 $this.toggleClass('chosed');
@@ -5352,7 +5416,20 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -5352,7 +5416,20 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
5352 } 5416 }
5353 }); 5417 });
5354 } else if ($chosed.length === 1 && $this.hasClass('chosed')) { 5418 } else if ($chosed.length === 1 && $this.hasClass('chosed')) {
5355 - numArray = $chosed.data('numstr').split('/'); 5419 + if ($this.closest('.block-list').hasClass('color-list')) {
  5420 +
  5421 + $sizeList.addClass('hide');
  5422 +
  5423 + //切换尺码信息
  5424 + $sizeList.each(function() {
  5425 + colorIndex = $(this).data('colorid');
  5426 + if (colorIndex === $this.data('id')) {
  5427 + $(this).removeClass('hide');
  5428 + }
  5429 + });
  5430 + }
  5431 +
  5432 + numArray = ($chosed.data('numstr') + '').split('/');
5356 $siblingBlock.find('.block').removeClass('zero-stock'); 5433 $siblingBlock.find('.block').removeClass('zero-stock');
5357 for (i = 0; i < numArray.length; i++) { 5434 for (i = 0; i < numArray.length; i++) {
5358 if (0 === numArray[i] - 0) { 5435 if (0 === numArray[i] - 0) {
@@ -5360,6 +5437,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -5360,6 +5437,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
5360 } 5437 }
5361 } 5438 }
5362 } else if ($chosed.length === 1 && !$this.hasClass('chosed')) { 5439 } else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
  5440 + $('#chose-btn-sure').css('background-color', '#eb0313');
  5441 + $('#chose-btn-sure').html('确定');
  5442 +
5363 $siblingBlock.find('ul>li').each(function() { 5443 $siblingBlock.find('ul>li').each(function() {
5364 $(this).removeClass('zero-stock'); 5444 $(this).removeClass('zero-stock');
5365 if (0 === $(this).data('num') - 0) { 5445 if (0 === $(this).data('num') - 0) {
@@ -5379,19 +5459,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -5379,19 +5459,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
5379 if (2 === $chosed.closest('.zero-stock').length) { 5459 if (2 === $chosed.closest('.zero-stock').length) {
5380 $('#chose-btn-sure').css('background-color', '#c0c0c0'); 5460 $('#chose-btn-sure').css('background-color', '#c0c0c0');
5381 $('#chose-btn-sure').html('已售罄'); 5461 $('#chose-btn-sure').html('已售罄');
  5462 + } else {
  5463 + $('#chose-btn-sure').css('background-color', '#eb0313');
  5464 + $('#chose-btn-sure').html('确定');
5382 } 5465 }
5383 } 5466 }
5384 5467
5385 }).on('touchstart', '.btn-minus', function() { 5468 }).on('touchstart', '.btn-minus', function() {
5386 var num = +$num.val(), 5469 var num = +$num.val(),
5387 - $chosed = $('.block-list>ul>li.chosed'); 5470 + $chosed = $('.block-list>ul>li.chosed'),
  5471 + leftNum = re.exec($('.num .left-num').html());
5388 5472
5389 //若颜色和尺码没有被同时选中,则不能点击 5473 //若颜色和尺码没有被同时选中,则不能点击
5390 if ($chosed.length < 2) { 5474 if ($chosed.length < 2) {
5391 return; 5475 return;
5392 } 5476 }
5393 5477
5394 - if (num === 0) { 5478 + if (num === 1 || 0 === leftNum - 0) {
5395 return; 5479 return;
5396 } 5480 }
5397 5481
@@ -5403,6 +5487,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) { @@ -5403,6 +5487,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
5403 if ($('.block-list>ul>li.chosed').length < 2) { 5487 if ($('.block-list>ul>li.chosed').length < 2) {
5404 return; 5488 return;
5405 } 5489 }
  5490 + leftNum = re.exec($('.num .left-num').html());
  5491 + if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
  5492 + return;
  5493 + }
5406 5494
5407 //TODO:库存数验证 5495 //TODO:库存数验证
5408 $num.val(num + 1); 5496 $num.val(num + 1);
@@ -6021,7 +6109,7 @@ optHammer.on('tap', function(e) { @@ -6021,7 +6109,7 @@ optHammer.on('tap', function(e) {
6021 } else { 6109 } else {
6022 tip.show(res.message || '网络错误'); 6110 tip.show(res.message || '网络错误');
6023 } 6111 }
6024 - window.location.reload(); 6112 + window.location.href = '/home/orders';
6025 }).fail(function() { 6113 }).fail(function() {
6026 tip.show('网络错误'); 6114 tip.show('网络错误');
6027 }); 6115 });
This diff could not be displayed because it is too large.