...
|
...
|
@@ -34,6 +34,11 @@ var $chosePanel = $('#chose-panel'), |
|
|
$soonSoldOut = $('.soonSoldOut-tag'),
|
|
|
$yohoPage = $('.yoho-page');
|
|
|
|
|
|
//购物车编辑标相关变量
|
|
|
var isEdit,
|
|
|
isSelected,
|
|
|
oldSknId;
|
|
|
|
|
|
//初始化购物车面板显示
|
|
|
function init() {
|
|
|
hasChooseColor = false;
|
...
|
...
|
@@ -47,6 +52,37 @@ function init() { |
|
|
$leftNum = $('#left-num');
|
|
|
curColorIndex = 0;
|
|
|
curSizeIndex = 0;
|
|
|
isEdit = 0;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 设置当前面板为编辑模式
|
|
|
*
|
|
|
* @param {String} sknId. 当前编辑商品的sknId
|
|
|
*
|
|
|
* @param {Bool} isThisGoodSelected. 当前编辑商品的在购物车中是否被选中
|
|
|
*
|
|
|
* @return {undefined}
|
|
|
*/
|
|
|
function setEditModeWithSknId(sknId, isThisGoodSelected) {
|
|
|
$('#chose-btn-sure').html('确认');
|
|
|
isEdit = 1;
|
|
|
oldSknId = sknId;
|
|
|
isSelected = isThisGoodSelected;
|
|
|
}
|
|
|
|
|
|
//删除面板
|
|
|
function removePannel() {
|
|
|
var $pannel = $('.chose-panel'),
|
|
|
$promotionId = $('#promotionId');
|
|
|
|
|
|
if ($pannel) {
|
|
|
$pannel.remove();
|
|
|
}
|
|
|
|
|
|
if ($promotionId) {
|
|
|
$promotionId.remove();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function checkColorSizeNum() {
|
...
|
...
|
@@ -108,7 +144,7 @@ function updateConformButtonClassAndText() { |
|
|
if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313').html('加入购物车');
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车');
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -355,7 +391,8 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
buyNumber = $('#good-num').val() - 0,
|
|
|
|
|
|
promotionId,
|
|
|
isEdit = 0,
|
|
|
cartGoodData,
|
|
|
url,
|
|
|
num = parseInt($num.val(), 10);
|
|
|
|
|
|
//颜色尺码没有选择
|
...
|
...
|
@@ -389,21 +426,39 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
|
|
|
confirming = true;
|
|
|
loading.showLoadingMask();
|
|
|
$.ajax({
|
|
|
method: 'POST',
|
|
|
url: '/cart/index/add',
|
|
|
data: {
|
|
|
|
|
|
//针对是否处于编辑模式设置不同的url和需要post的数据
|
|
|
if (isEdit) {
|
|
|
cartGoodData = {
|
|
|
new_product_sku: productSku,
|
|
|
old_product_sku: oldSknId,
|
|
|
buy_number: buyNumber,
|
|
|
selected: isSelected
|
|
|
};
|
|
|
|
|
|
url = '/cart/index/modify';
|
|
|
|
|
|
} else {
|
|
|
cartGoodData = {
|
|
|
productSku: productSku,
|
|
|
buyNumber: buyNumber,
|
|
|
promotionId: promotionId,
|
|
|
isEdit: isEdit,
|
|
|
cartType: queryString.cartType
|
|
|
}
|
|
|
};
|
|
|
|
|
|
url = '/cart/index/add';
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
|
method: 'POST',
|
|
|
url: url,
|
|
|
data: cartGoodData
|
|
|
}).done(function(res) {
|
|
|
var cartNum;
|
|
|
|
|
|
loading.hideLoadingMask();
|
|
|
if (res.code === 200) {
|
|
|
if (res.code === 200 && !isEdit) {
|
|
|
cartNum = res.data.goods_count;
|
|
|
if (cartNum > 99) {
|
|
|
cartNum = '99+';
|
...
|
...
|
@@ -415,11 +470,20 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
cbFn();
|
|
|
}
|
|
|
}
|
|
|
if (res.message) {
|
|
|
if (res.message && !isEdit) {
|
|
|
tip.show(res.message);
|
|
|
}
|
|
|
|
|
|
hide();
|
|
|
|
|
|
if (isEdit) {
|
|
|
loading.showLoadingMask();
|
|
|
|
|
|
//延迟刷新,否则面板可能无法隐藏
|
|
|
setTimeout(function() {
|
|
|
window.location.reload();
|
|
|
}, 1);
|
|
|
}
|
|
|
}).fail(function() {
|
|
|
tip.show('网络出了点问题~');
|
|
|
}).always(function() {
|
...
|
...
|
@@ -430,4 +494,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
});
|
|
|
|
|
|
exports.init = init;
|
|
|
exports.show = show; |
|
|
\ No newline at end of file |
|
|
exports.show = show;
|
|
|
exports.remove = removePannel;
|
|
|
exports.setEditModeWithSknId = setEditModeWithSknId;
|
|
|
|
...
|
...
|
|