...
|
...
|
@@ -18,9 +18,9 @@ var panelTmpl, |
|
|
$chosePanel = $('#chose-panel'),
|
|
|
$num,
|
|
|
$chosed,
|
|
|
re = /\d+/,
|
|
|
|
|
|
// re = /\d+/,
|
|
|
leftNum,
|
|
|
$sizeList,
|
|
|
confirming,
|
|
|
hasChooseColor = false,
|
|
|
hasChooseSize = false,
|
...
|
...
|
@@ -61,6 +61,20 @@ function init() { |
|
|
$curSizeRow = $firstRow;
|
|
|
}
|
|
|
|
|
|
function checkColorSizeNum() {
|
|
|
if (!hasChooseColor && !hasChooseSize) {
|
|
|
tip.show('请选择颜色和尺码~');
|
|
|
return false;
|
|
|
} else if (!hasChooseColor) {
|
|
|
tip.show('请选择颜色~');
|
|
|
return false;
|
|
|
} else if (!hasChooseSize) {
|
|
|
tip.show('请选择尺码~');
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
init();
|
|
|
|
|
|
function show(data) {
|
...
|
...
|
@@ -118,6 +132,7 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
|
|
|
|
//颜色原来已经是勾选时,要清空剩余件数的提示
|
|
|
$that.find('.num .left-num').html('');
|
|
|
$('#left-num').val(0);
|
|
|
hasChooseColor = false;
|
|
|
|
|
|
// 当前颜色不是选中状态,选中时
|
...
|
...
|
@@ -131,15 +146,15 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
|
|
|
|
//把当前选中颜色对应的尺码那一行显示出来
|
|
|
$sizeRowList.addClass('hide');
|
|
|
$curSizeRow.toggleClass('hide');
|
|
|
$curSizeRow.removeClass('hide').addClass('show');
|
|
|
|
|
|
// 之前选中的尺码去掉勾选样式
|
|
|
if ($sizeChosed) {
|
|
|
if ($sizeChosed.length > 0) {
|
|
|
$sizeChosed.removeClass('chosed');
|
|
|
curSelectedSizeBlock = $curSizeRow.children().get(scindex);
|
|
|
}
|
|
|
|
|
|
// 当前选中颜色对应的尺码行,其对应的尺码加上勾选样式 (前提是要判断下这个尺码是否存在)
|
|
|
curSelectedSizeBlock = $curSizeRow.children().get(scindex);
|
|
|
if (curSelectedSizeBlock) {
|
|
|
curGoodNum = $(curSelectedSizeBlock).data('num');
|
|
|
$(curSelectedSizeBlock).addClass('chosed');
|
...
|
...
|
@@ -147,9 +162,11 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
|
//如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式
|
|
|
if (curGoodNum > 0) {
|
|
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
$('#left-num').val(curGoodNum);
|
|
|
} else {
|
|
|
$(curSelectedSizeBlock).removeClass('zero-stock').addClass('zero-stock');
|
|
|
$that.find('.num .left-num').html('');
|
|
|
$('#left-num').val(0);
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -236,7 +253,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
$that = $(e.target).closest('.chose-items'),
|
|
|
index,
|
|
|
$colorChosed,
|
|
|
selectedColorindex,
|
|
|
curGoodNum;
|
|
|
|
|
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
...
|
...
|
@@ -245,7 +261,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
index = $this.index();
|
|
|
|
|
|
$colorChosed = $siblingBlock.find('.chosed');
|
|
|
selectedColorindex = $colorChosed.index();
|
|
|
$curSizeRow = $sizeRowList.eq(index);
|
|
|
|
|
|
// 当前尺码已经是选中状态,再点击时
|
...
|
...
|
@@ -253,10 +268,11 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
|
|
|
//尺码原来已经是勾选时,要清空剩余件数的提示
|
|
|
$that.find('.num .left-num').html('');
|
|
|
$('#left-num').val(0);
|
|
|
hasChooseSize = false;
|
|
|
|
|
|
// 去掉已经选中颜色的 数量为0的样式
|
|
|
if ($colorChosed) {
|
|
|
if ($colorChosed.length > 0) {
|
|
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
}
|
|
|
|
...
|
...
|
@@ -272,11 +288,13 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
}
|
|
|
|
|
|
// 如果当前有尺码被选中,且数量等于0,则颜色块添加数量为0的样式, 否则显示剩余件数
|
|
|
if (curGoodNum > 0) {
|
|
|
if (curGoodNum > 0 && hasChooseColor) {
|
|
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
$('#left-num').val(curGoodNum);
|
|
|
} else {
|
|
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
$that.find('.num .left-num').html('');
|
|
|
$('#left-num').val(0);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -361,12 +379,11 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
});
|
|
|
|
|
|
$('.btn-minus').on('touchstart', function() {
|
|
|
var num = $num.val(),
|
|
|
$chosed = $('.block-list>ul>li.chosed'),
|
|
|
leftNum = re.exec($('.num .left-num').html());
|
|
|
var num = $num.val();
|
|
|
|
|
|
leftNum = $('#left-num').val();
|
|
|
|
|
|
//若颜色和尺码没有被同时选中,则不能点击
|
|
|
if ($chosed.length < 2) {
|
|
|
if (!checkColorSizeNum()) {
|
|
|
return;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -380,13 +397,14 @@ $('.btn-minus').on('touchstart', function() { |
|
|
$('.btn-plus').on('touchstart', function() {
|
|
|
var num = $num.val();
|
|
|
|
|
|
//若颜色和尺码没有被同时选中,则不能点击
|
|
|
if ($('.block-list>ul>li.chosed').length < 2) {
|
|
|
tip.show('请选择颜色和尺码~');
|
|
|
leftNum = $('#left-num').val();
|
|
|
|
|
|
if (!checkColorSizeNum()) {
|
|
|
return;
|
|
|
}
|
|
|
leftNum = re.exec($('.num .left-num').html());
|
|
|
if (num - 0 === leftNum - 0 || 0 === leftNum - 0) {
|
|
|
|
|
|
|
|
|
if (num - 0 === leftNum || 0 === leftNum) {
|
|
|
return;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -394,22 +412,35 @@ $('.btn-plus').on('touchstart', function() { |
|
|
$num.val(num + 1);
|
|
|
});
|
|
|
|
|
|
$('#chose-btn-sure').on('touchend', function() {
|
|
|
$('#chose-btn-sure').on('touchstart', function() {
|
|
|
|
|
|
var productSku,
|
|
|
buyNumber = $('#good-num').val() - 0,
|
|
|
|
|
|
promotionId,
|
|
|
isEdit = 0,
|
|
|
numInCart = $('.num-tag').html() - 0;
|
|
|
numInCart = $('.num-tag').html() - 0,
|
|
|
num = $num.val();
|
|
|
|
|
|
if (!checkColorSizeNum()) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($('#chose-btn-sure').html() === '已售罄') {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
leftNum = $('#left-num').val();
|
|
|
|
|
|
// goodsType,
|
|
|
// isEdit;
|
|
|
if (num > leftNum) {
|
|
|
tip.show('您选择的数量超过了最大库存量~');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$chosed = $('.block-list>ul>li.chosed');
|
|
|
|
|
|
if (2 === $chosed.length && 0 === $chosed.closest('.zero-stock').length) {
|
|
|
productSku = $sizeList.closest('.chosed').data('skuid');
|
|
|
productSku = $curSizeBlock.data('skuid');
|
|
|
promotionId = $('[data-id="' + productSku + '"]').closest('.advance-block').data('promotion-id');
|
|
|
if (confirming) {
|
|
|
return false;
|
...
|
...
|
|