Authored by 陈峰

解决结算时提示还有赠品逻辑

... ... @@ -55,28 +55,38 @@ let cartObj = {
}
},
promoItemClick(e) {
let cartType = window.cookie('cartType') || 'ordinary';
let self = this;
let promotionId = $(e.currentTarget).data('id');
let promotionType = $(e.currentTarget).data('type');
let promotionTitle = encodeURIComponent($(e.currentTarget).data('title'));
self.toPromotionPage({
promotionType,
promotionId,
promotionTitle,
status: $(e.currentTarget).data('status')
});
},
toPromotionPage(opts) {
let cartType = window.cookie('cartType') || 'ordinary';
let title = '促销商品';
if (promotionType === 'Gift') {
if ($(e.currentTarget).data('status') === 30) {
window.location.href = `/cart/index/new/gift?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}&edit=1`;
if (opts.promotionType === 'Gift') {
if (opts.status === 30) {
window.location.href = `/cart/index/new/gift?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}&edit=1`;
} else {
window.location.href = `/cart/index/new/gift?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
window.location.href = `/cart/index/new/gift?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
}
} else if (promotionType === 'Needpaygift') {
if ($(e.currentTarget).data('status') === 30) {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}&edit=1`;
} else if (opts.promotionType === 'Needpaygift') {
if (opts.status === 30) {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}&edit=1`;
} else {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
}
} else {
window.location.href = `/product/index/index?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
window.location.href = `/product/index/index?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
}
},
allGiftBoxClick(e) {
... ... @@ -89,6 +99,7 @@ let cartObj = {
}
},
balanceClick() {
let self = this;
let cartType = window.cookie('cartType') || 'ordinary';
if (window._yas && window._yas.sendCustomInfo) {
... ... @@ -112,7 +123,11 @@ let cartObj = {
tip.show(`所选商品中有${lowStocks}种库存不足的商品`);
return false;
}
if ($('.all-gift-box>.freebie').length) {
if (!$('.good-item.is-checked').length) {
tip.show('请先勾选商品');
return false;
}
if ($('.all-gift-box>.freebie').length || $('.promo-item[data-type="Gift"][data-status="10"]').length) {
dialog.showDialog({
dialogText: '您还未选择赠品,是否去选择赠品',
hasFooter: {
... ... @@ -120,17 +135,33 @@ let cartObj = {
rightBtnText: '去选择'
}
}, function() {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
self.toGiftPromotion(cartType);
}, function() {
window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
self.toOrderEnsure(cartType);
});
return false;
}
if (!$('.good-item.is-checked').length) {
tip.show('请先勾选商品');
return false;
}
self.toOrderEnsure(cartType);
},
toOrderEnsure(cartType) {
window.location.href = '/cart/index/new/orderEnsure?cartType=' + cartType;
},
toGiftPromotion(cartType) {
let self = this;
let promotionEles = $('.promo-item[data-type="Gift"][data-status="10"]');
if (promotionEles.length) {
let promotionEle = promotionEles.eq(0);
self.toPromotionPage({
promotionType: $(promotionEle).data('type'),
promotionId: $(promotionEle).data('id'),
promotionTitle: encodeURIComponent($(promotionEle).data('title')),
status: $(promotionEle).data('status')
});
} else if ($('.all-gift-box>.freebie').length) {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
}
}
};
... ...
... ... @@ -346,12 +346,12 @@ let goodObj = {
if (goodNum <= minNumber) {
$(minusEl).addClass('disabled');
} else if ($(minusEl).hasClass('disabled')) {
} else if (minNumber < oldGoodNum && $(minusEl).hasClass('disabled')) {
$(minusEl).removeClass('disabled');
}
if (goodNum >= maxNumber) {
$(plusEl).addClass('disabled');
} else if ($(plusEl).hasClass('disabled')) {
} else if (maxNumber > oldGoodNum && $(plusEl).hasClass('disabled')) {
$(plusEl).removeClass('disabled');
}
... ... @@ -381,16 +381,14 @@ let goodObj = {
},
success: (data) => {
if (data.code !== 200) {
self.handle.posting = false;
tip.show('网络异常');
} else {
goodNum = parseInt($(e.delegateTarget).find('.good-num').val(), 10);
let max = parseInt($(e.delegateTarget).find('.good-num').data('max'), 10);
if (!$(e.delegateTarget).find('.chk.select').hasClass('checked') && goodNum <= max) {
self.selectGood($(e.delegateTarget).find('.chk.select')).then(() => {
self.handle.posting = false;
});
self.handle.posting = false;
self.selectGood($(e.delegateTarget).find('.chk.select'));
} else {
self.handle.refreshPage().then(() => {
self.handle.posting = false;
... ... @@ -432,7 +430,7 @@ let goodObj = {
data: {
skn: skn,
buy_num: count,
mnum: minNum,
mnum: minNum > 1 ? minNum : undefined,
promotion_id: promotionId
},
type: 'POST',
... ...
... ... @@ -98,17 +98,20 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid = true, inValidLow = f
count: goodData.buy_number,
promotion_id: _.toNumber(goodData.promotion_id) === 0 ? '' : goodData.promotion_id
};
goodData.storage_number = _.parseInt(goodData.storage_number);
goodData.min_buy_number = _.parseInt(goodData.min_buy_number);
goodData.buy_number = _.parseInt(goodData.buy_number);
if (goodData.min_buy_number && goodData.min_buy_number > 1) {
result.minNumber = parseInt(goodData.min_buy_number, 10);
if (goodData.min_buy_number && goodData.min_buy_number > 0) {
result.minNumber = goodData.min_buy_number;
}
result.maxNumber = parseInt(goodData.storage_number, 10);
result.minSelectNum = parseInt(goodData.buy_number, 10) <= parseInt(goodData.min_buy_number, 10) || parseInt(goodData.buy_number, 10) === 1;
result.maxSelectNum = parseInt(goodData.buy_number, 10) >= parseInt(goodData.storage_number, 10) && goodData.goods_type === 'ordinary';
result.maxNumber = goodData.storage_number;
result.minSelectNum = goodData.buy_number <= goodData.min_buy_number || goodData.buy_number === 1;
result.maxSelectNum = goodData.buy_number >= goodData.storage_number && goodData.goods_type === 'ordinary';
if (isValid) {
// 库存不足
result.lowStocks = (goodData.buy_number > goodData.storage_number);
result.lowStocks = goodData.buy_number > goodData.storage_number;
} else { // 失效商品
result.inValid = true;
result.inValidLow = inValidLow;
... ... @@ -217,7 +220,7 @@ const procGoodsDetail = (productData, num) => {
}
data.num = 1;
if (num) {
data.num = parseInt(num, 10);
data.num = _.parseInt(num);
}
// 商品选择
... ... @@ -252,7 +255,7 @@ const procGoodsDetail = (productData, num) => {
goodsId: val.goods_id,
colorId: val.color_id,
name: one.size_name,
sizeNum: parseInt(one.storage_number, 10),
sizeNum: _.parseInt(one.storage_number, 10),
sizeInfo: one.size_info ? one.size_info : ''
});
... ... @@ -263,9 +266,9 @@ const procGoodsDetail = (productData, num) => {
sizeInfo: one.size_info ? one.size_info : ''
} : allSizeList[sizeName];
colorNum += parseInt(one.storage_number, 10);
colorNum += _.parseInt(one.storage_number, 10);
colorStorageGroup[val.product_skc][sizeName] = parseInt(one.storage_number, 10);
colorStorageGroup[val.product_skc][sizeName] = _.parseInt(one.storage_number, 10);
});
// 颜色分组
... ... @@ -320,7 +323,7 @@ const procGoodsDetail = (productData, num) => {
id: colorArr.id,
skcId: colorArr.skcId,
name: colorArr.name,
colorNum: _.has(colorStorageGroup, `${colorArr.skcId}.${sName}`) ? parseInt(colorStorageGroup[colorArr.skcId][sName], 10) : 0,
colorNum: _.has(colorStorageGroup, `${colorArr.skcId}.${sName}`) ? _.parseInt(colorStorageGroup[colorArr.skcId][sName], 10) : 0,
goodsName: colorArr.goodsName
});
});
... ... @@ -454,7 +457,7 @@ const procCartData = (data, onlyGift = false, onlyAdvanceBuy = false, isAdvanceC
let goodCount = _.sum(result.goods
.filter(good => good.lowStocks === false)
.map(good => {
return parseInt(good.count, 10);
return _.parseInt(good.count, 10);
})) + // 普通商品
_.sum(result.goodPools
... ... @@ -464,13 +467,13 @@ const procCartData = (data, onlyGift = false, onlyAdvanceBuy = false, isAdvanceC
return _.sum(_.get(subPool, 'goods', [])// 子促销池中的商品
.filter(good => good.lowStocks === false)
.map(good => {
return parseInt(good.count, 10);
return _.parseInt(good.count, 10);
}));
})) +
_.sum(_.get(goodPool, 'goods', []) // 大促销池中的商品
.filter(good => good.lowStocks === false)
.map(good => {
return parseInt(good.count, 10);
return _.parseInt(good.count, 10);
}));
}));
... ...