Authored by hf

do merge shopping cart code

... ... @@ -216,9 +216,9 @@ $yohoPage.on('touchstart', '.tap-hightlight', function() {
$(this).removeClass('highlight');
});
$('.nav-home').on('touchstart', function() {
$('.homebuttom').toggleClass('none');
});
// $('.nav-home').on('touchstart', function() {
// $('.homebuttom').toggleClass('none');
// });
(function() {
var lastTime = 0,
... ... @@ -5145,6 +5145,8 @@ function request() {
requesting = false;
end = true;
window.rePosFooter();
}).fail(function() {
$recommendForYou.hide();
});
... ... @@ -5152,7 +5154,7 @@ function request() {
}
function scrollHandler() {
if (!end || $(window).scrollTop() + winH >= $(document).height() - 50) {
if (!end || $(window).scrollTop() + winH >= $(document).height() - 200) {
request();
}
}
... ... @@ -5173,7 +5175,7 @@ define("js/product/detail/like", ["jquery","hammer"], function(require, exports,
var $ = require("jquery"),
Hammer = require("hammer"),
tip = require("js/plugin/tip"),
chosePanel = require("js/shopping-cart/chose-panel");
chosePanel = require("js/cart/chose-panel");
var likeEle = document.getElementById('likeBtn'),
likeHammer = likeEle && new Hammer(likeEle);
... ... @@ -5249,11 +5251,8 @@ if (addToCartHammer) {
});
}
});
define("js/shopping-cart/chose-panel", ["jquery"], function(require, exports, module){
define("js/cart/chose-panel", ["jquery"], function(require, exports, module){
/**
* 购物车选择尺寸、颜色和数量面板
* 显示时构造当前商品信息的HTML插入yoho-page;消失则是直接清除HTML
... ... @@ -5261,14 +5260,34 @@ define("js/shopping-cart/chose-panel", ["jquery"], function(require, exports, mo
* @date: 2015/10/21
*/
var $ = require("jquery");
var $ = require("jquery"),
tip = require("js/plugin/tip"),
loading = require("js/plugin/loading");
// Handlebars = require('yoho.handlebars');
// var $page = $('.yoho-page');
var $num,
$chosed;
$chosed,
re = /\d+/,
leftNum,
$colorList = $('.color-list ul>li'),
$sizeList = $('.size-list ul>li'),
firstColorId = $colorList.eq(0).data('id'),
colorIndex,
confirming;
//初始化购物车面板显示
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === firstColorId) {
$(this).removeClass('hide');
}
});
// var tpl;
... ... @@ -5291,8 +5310,11 @@ var $num,
// $num = $('#good-num');
// }
function show() {
$('.chose-panel').show();
$('body').css('overflow', 'hidden');
$num = $('#good-num');
}
... ... @@ -5314,10 +5336,52 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
remove();
}).on('touchstart', '#chose-btn-sure', function() {
//确定
}).on('touchstart', '.block', function(e) {
var productSku,
buyNumber = $('#good-num').val() - 0,
promotionId,
isEdit = 0,
numInCart = $('.num-tag').html() - 0;
// goodsType,
// isEdit;
//尺寸颜色点选
$chosed = $('.block-list>ul>li.chosed');
if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {
productSku = $sizeList.closest('.chosed').data('skuid');
promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');
if (confirming) {
return false;
}
confirming = true;
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/cart/index/add',
data: {
productSku: productSku,
buyNumber: buyNumber,
promotionId: promotionId,
isEdit: isEdit
}
}).done(function(res) {
if (res.code === 200) {
loading.hideLoadingMask();
$('.num-tag').html(numInCart + buyNumber);
$('.num-tag').removeClass('hide');
confirming = false;
remove();
}
}).fail(function() {
tip.show('网络出了点问题~');
confirming = false;
});
}
}).on('touchstart', '.block', function(e) {
var $this = $(this),
$that = $(e.target).closest('.chose-items'),
numArray,
... ... @@ -5325,7 +5389,7 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
i;
var $siblingBlock = $this.closest('.block-list').siblings(':first'),
currentNumArray = $this.data('numstr').split('/');
currentNumArray = ($this.data('numstr') + '').split('/');
$this.siblings('.chosed').removeClass('chosed');
$this.toggleClass('chosed');
... ... @@ -5352,7 +5416,20 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}
});
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
numArray = $chosed.data('numstr').split('/');
if ($this.closest('.block-list').hasClass('color-list')) {
$sizeList.addClass('hide');
//切换尺码信息
$sizeList.each(function() {
colorIndex = $(this).data('colorid');
if (colorIndex === $this.data('id')) {
$(this).removeClass('hide');
}
});
}
numArray = ($chosed.data('numstr') + '').split('/');
$siblingBlock.find('.block').removeClass('zero-stock');
for (i = 0; i < numArray.length; i++) {
if (0 === numArray[i] - 0) {
... ... @@ -5360,6 +5437,9 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
}
}
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
$siblingBlock.find('ul>li').each(function() {
$(this).removeClass('zero-stock');
if (0 === $(this).data('num') - 0) {
... ... @@ -5379,19 +5459,23 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
if (2 === $chosed.closest('.zero-stock').length) {
$('#chose-btn-sure').css('background-color', '#c0c0c0');
$('#chose-btn-sure').html('已售罄');
} else {
$('#chose-btn-sure').css('background-color', '#eb0313');
$('#chose-btn-sure').html('确定');
}
}
}).on('touchstart', '.btn-minus', function() {
var num = +$num.val(),
$chosed = $('.block-list>ul>li.chosed');
$chosed = $('.block-list>ul>li.chosed'),
leftNum = re.exec($('.num .left-num').html());
//若颜色和尺码没有被同时选中,则不能点击
if ($chosed.length < 2) {
return;
}
if (num === 0) {
if (num === 1 || 0 === leftNum - 0) {
return;
}
... ... @@ -5403,6 +5487,10 @@ $('.yoho-page').on('touchstart', '.chose-panel', function(e) {
if ($('.block-list>ul>li.chosed').length < 2) {
return;
}
leftNum = re.exec($('.num .left-num').html());
if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
return;
}
//TODO:库存数验证
$num.val(num + 1);
... ... @@ -6021,7 +6109,7 @@ optHammer.on('tap', function(e) {
} else {
tip.show(res.message || '网络错误');
}
window.location.reload();
window.location.href = '/home/orders';
}).fail(function() {
tip.show('网络错误');
});
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.