Authored by 郭成尧

bundle-to-cart

... ... @@ -306,6 +306,7 @@ const modify = (req, res, next) => {
let oldProductSku = req.body.old_product_sku || 0,
newProductSku = req.body.new_product_sku || 0,
buyNumber = req.body.buy_number || 0,
activity_id = req.body.activity_id,
selected = req.body.selected;
if (!oldProductSku || !newProductSku) {
... ... @@ -321,7 +322,8 @@ const modify = (req, res, next) => {
old_product_sku: oldProductSku,
new_product_sku: newProductSku,
buy_number: buyNumber,
selected: selected
selected: selected,
activity_id: activity_id
}], shoppingKey).then(data => {
data ? res.json(data) : res.status(400).json({
message: '操作失败'
... ... @@ -449,6 +451,49 @@ const giftinfo = (req, res, next) => {
}).catch(next);
};
/**
* 增加套餐的数量
* @param {*} req
* @param {*} res
* @param {*} next
*/
const incrBundle = (req, res, next) => {
let uid = req.user.uid;
let shoppingKey = req.cookies._SPK || '';
return indexModel.incrBundle({
uid: uid,
shopping_key: shoppingKey,
activity_id: req.body.activity_id,
sku_ids: req.body.sku_ids,
batch_no: req.body.batch_no,
}).then(result => {
res.json(result);
}).catch(next);
};
/**
* 增加套餐的数量
* @param {*} req
* @param {*} res
* @param {*} next
*/
const decrBundle = (req, res, next) => {
let uid = req.user.uid;
let shoppingKey = req.cookies._SPK || '';
return indexModel.decrBundle({
uid: uid,
shopping_key: shoppingKey,
activity_id: req.body.activity_id,
sku_ids: req.body.sku_ids,
batch_no: req.body.batch_no,
}).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
indexData,
... ... @@ -462,5 +507,7 @@ module.exports = {
gift,
giftinfo,
advanceBuy,
modifyPriceGift
modifyPriceGift,
incrBundle,
decrBundle
};
... ...
... ... @@ -245,6 +245,38 @@ const getPriceGiftList = (promotionIds, promotionType) => {
});
};
/**
* 增加套餐数量
* @param {*} params
*/
const incrBundle = (params) => {
return api.post('', {
method: 'app.Shopping.incrBundle',
uid: params.uid,
shopping_key: params.shopping_key,
increase_number: params.increase_number || '1',
activity_id: params.activity_id,
sku_ids: params.sku_ids,
batch_no: params.batch_no
});
};
/**
* 减少套餐数量
* @param {*} params
*/
const decrBundle = (params) => {
return api.post('', {
method: 'app.Shopping.decrBundle',
uid: params.uid,
shopping_key: params.shopping_key,
decrease_number: params.decrease_number || '1',
activity_id: params.activity_id,
sku_ids: params.sku_ids,
batch_no: params.batch_no
});
};
module.exports = {
indexData,
selectGood,
... ... @@ -258,5 +290,7 @@ module.exports = {
modifyCartProduct,
giftProductData,
getPriceGiftList,
modifyCartPriceGiftProduct
modifyCartPriceGiftProduct,
incrBundle,
decrBundle
};
... ...
... ... @@ -58,6 +58,8 @@ router.post('/index/new/modifyPriceGift', indexController.modifyPriceGift); //
router.get('/index/new/gift', indexController.gift); // 获取购物车赠品
router.get('/index/new/advanceBuy', indexController.advanceBuy); // 获取购物车加价购
router.post('/index/new/giftinfo', indexController.giftinfo); // 获取购物车加价购商品数据,chosepanel
router.post('/index/new/incrbundle', indexController.incrBundle); // 购物车增加套餐数量
router.post('/index/new/decrbundle', indexController.decrBundle); // 购物车减少加套餐数量
// 支付中心 URL,由于微信安全限制,在现有 URL 后追加 new ,通过 subDomain 中间件转发到此
... ...
... ... @@ -31,3 +31,18 @@ exports.detail = (req, res, next) => {
}, result));
}).catch(next);
};
/**
* 套餐加入购物车
*/
exports.addToCart = (req, res, next) => {
bundleModel.addToCart({
uid: req.user.uid,
activity_id: req.body.activity_id,
product_sku_list: req.body.product_sku_list,
shopping_key: req.cookies._SPK || '',
userAgent: req.get('User-Agent')
}).then(result => {
return res.json(result);
}).catch(next);
};
... ...
... ... @@ -65,7 +65,34 @@ const detail = (params, isApp) => {
});
};
/**
* 套餐加入购物车
* @param {*} params
*/
const addToCart = (params) => {
let skuList = params.product_sku_list;
let finalParams = {
method: 'app.Shopping.addBundle',
shopping_key: params.shopping_key,
activity_id: params.activity_id,
product_sku_list: skuList
};
if (params.uid) {
Object.assign(finalParams, {
uid: params.uid
});
}
return api.post('', finalParams, {
headers: {
'User-Agent': params.userAgent
}
});
};
module.exports = {
getBundleBySkn,
detail
detail,
addToCart
};
... ...
... ... @@ -194,6 +194,7 @@ router.get('/newsale/hotrank', newsale.index); // 热销排行榜
router.get('/newsale/selectHotrank', newsale.selectHotrank); // 热销排行榜
router.get('/bundle/detail', bundle.detail); // 套装详情页
router.post('/bundle/cart/add', bundle.addToCart); // 套装加入购物车
router.post('/opt/favoriteProduct', newDetail.favoriteProduct); // 商品收藏、取消收藏
router.get('/detail/limitHelp', newDetail.limitHelp);
... ...
... ... @@ -39,10 +39,8 @@
</div>
<div class="sale-price">销售价: {{salesPriceStr}}</div>
</div>
<button id="bundle-buy-now" class="bundle-buy-btn">立即购买</button>
<button id="bundle-buy-now" class="bundle-buy-btn">加入购物车</button>
{{/if}}
</div>
<input type="hidden" id="activityId" value="{{bundleId}}">
{{/ bundleInfo}}
... ...
<div class="bundle" data-activityid="{{poolId}}" data-poolbatchno="{{poolBatchNo}}" data-maxnum="{{poolStorageNumber}}" data-buynum="{{poolBuyNumber}}">
<div class="bundle-title">
<div class="opt">
{{#unless goods.0.inValid}}
<i class="iconfont chk select{{#if selected}} checked{{/if}}"></i>
{{/unless}}
<i class="iconfont chk edit"></i>
{{#if goods.0.inValid}}
<span class="disable fill-text">失效</span>
{{/if}}
</div>
<div class="title">
<span>优惠套装</span>{{poolTitle}}
</div>
</div>
<div class="bundle-nums clearfix">
<div class="label">
<span>套餐数量</span>
</div>
<div class="num-opt">
<a href="javascript:;" class="btn btn-opt-minus{{#ifor minSelectNum isGift isAdvanceBuy}} disabled{{/ifor}}"><span class="iconfont"></span></a>
<input type="text" class="good-num" disabled="true" value="{{poolBuyNumber}}" >
<a href="javascript:;" class="btn btn-opt-plus{{#ifor maxSelectNum isGift isAdvanceBuy}} disabled{{/ifor}}"><span class="iconfont"></span></a>
</div>
<div class="count pull-right">x{{poolBuyNumber}}</div>
</div>
<div class="good-list">
{{#goods}}
{{> cart-good parent=..}}
{{/goods}}
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -45,6 +45,9 @@
{{/goods}}
</div>
{{/if}}
{{#if isBundle}}
{{> cart-bundle}}
{{/if}}
</div>
{{/goodPools}}
{{#goods}}
... ... @@ -90,6 +93,9 @@
{{#notValidGoods}}
{{> cart-good}}
{{/notValidGoods}}
{{#notValidPool}}
{{> cart-bundle}}
{{/notValidPool}}
{{#offShelveGoods}}
{{> cart-good}}
{{/offShelveGoods}}
... ...
<div class="good-item{{#if lowStocks}} low-stocks{{/if}}{{#if isStudents}} is-students{{/if}}{{#if isVipPrice}} is-vip-price{{/if}}{{#ifand checked showCheckbox}} is-checked{{/ifand}}{{#if noEdit}} no-edit{{/if}}{{#if inValid}} in-valid{{/if}}{{#if inValidLow}} in-valid-low{{/if}}{{#ifor isGift isAdvanceBuy}} is-gift{{/ifor}}" data-promotion="{{promotion_id}}" data-id="{{id}}" data-skn="{{skn}}" data-mnum="{{minNumber}}" data-link="{{link}}">
<div class="good-item{{#if lowStocks}} low-stocks{{/if}}{{#if isStudents}} is-students{{/if}}{{#if isVipPrice}} is-vip-price{{/if}}{{#ifand checked showCheckbox}} is-checked{{/ifand}}{{#if noEdit}} no-edit{{/if}}{{#if inValid}} in-valid{{/if}}{{#if inValidLow}} in-valid-low{{/if}}{{#ifor isGift isAdvanceBuy}} is-gift{{/ifor}}" data-promotion="{{promotion_id}}" data-id="{{id}}" data-skn="{{skn}}" data-mnum="{{minNumber}}" data-link="{{link}}" data-activityid="{{parent.poolId}}" data-poolbatchno="{{parent.poolBatchNo}}">
<div class="opt">
{{#if showCheckbox}}
<i class="iconfont chk select{{#if checked}} checked{{/if}}"></i>
... ... @@ -18,6 +18,9 @@
{{#isAdvanceBuy}}
<div class="flag price-gift"><div class="text">加价购</div></div>
{{/isAdvanceBuy}}
{{#if parent.isBundle}}
<div class="flag bundle"></div>
{{/if}}
</div>
</a>
<div class="info">
... ... @@ -33,12 +36,16 @@
{{#ifnot noEdit}}
<div class="intro intro-edit">
<div class="edit-box">
<div class="num-opt">
<a href="javascript:;" class="btn btn-opt-minus{{#ifor minSelectNum isGift isAdvanceBuy}} disabled{{/ifor}}"><span class="iconfont"></span></a>
<input type="text" class="good-num" disabled="true" value="{{count}}" data-min="{{minNumber}}" data-max="{{maxNumber}}">
<a href="javascript:;" class="btn btn-opt-plus{{#ifor maxSelectNum isGift isAdvanceBuy}} disabled{{/ifor}}"><span class="iconfont"></span></a>
</div>
<div class="edit-size-info">
{{#unless parent.isBundle}}
<div class="num-opt">
<a href="javascript:;" class="btn btn-opt-minus{{#ifor minSelectNum isGift isAdvanceBuy}} disabled{{/ifor}}"><span class="iconfont"></span></a>
<input type="text" class="good-num" disabled="true" value="{{count}}" data-min="{{minNumber}}" data-max="{{maxNumber}}">
<a href="javascript:;" class="btn btn-opt-plus{{#ifor maxSelectNum isGift isAdvanceBuy}} disabled{{/ifor}}"><span class="iconfont"></span></a>
</div>
{{^}}
<input type="hidden" class="good-num" value="{{count}}" data-min="{{minNumber}}" data-max="{{maxNumber}}">
{{/unless}}
<div class="edit-size-info {{#ifnot parent.isBundle}} edit-size-info-notop {{/ifnot}}">
<div class="txt">颜色:{{color}} 尺码:{{size}}</div>
<div class="down">
<i class="iconfont"></i>
... ... @@ -51,14 +58,22 @@
{{/ifnot}}
<div class="count">x{{count}}</div>
</div>
<p class="price">
<span class="market-price">¥{{price}}</span>
{{#if isStudents}}<span class="vip fill-text"></span>{{/if}}
{{#if isVipPrice}}<span class="vip fill-text">VIP</span>{{/if}}
</p>
<div class="tags">
{{#if lowStocks}}<span class="low-stocks fill-text">库存不足</span>{{/if}}
{{#appearDate}}<span class="appear-date">上市期:{{.}}</span>{{/appearDate}}
<div class="bottom">
<div class="price{{#if reAddToCart}} pull-left{{/if}}">
<span class="market-price">¥{{price}}</span>
{{#if isStudents}}<span class="vip fill-text"></span>{{/if}}
{{#if isVipPrice}}<span class="vip fill-text">VIP</span>{{/if}}
</div>
{{#if reAddToCart}}
<div class="re-add pull-right">
<span>重新加入购物车</span>
</div>
{{^}}
<div class="tags">
{{#if lowStocks}}<span class="low-stocks fill-text">库存不足</span>{{/if}}
{{#appearDate}}<span class="appear-date">上市期:{{.}}</span>{{/appearDate}}
</div>
{{/if}}
</div>
</div>
</div>
... ...
... ... @@ -126,6 +126,7 @@ let indexObj = {
$('.cart-box').html(hbsTemplate(data));
require('./index/cart').init(self);
require('./index/good').init(self);
require('./index/bundle').init(self);
$('.btn-edit').on('click', () => {
self.navBtnClick();
});
... ...
/*
* @Author: Targaryen
* @Date: 2017-04-06 16:51:52
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-12 14:01:07
*/
const $ = require('yoho-jquery');
let tip = require('plugin/tip');
let loading = require('plugin/loading');
let bundle = {
init(handle) {
let self = this;
let $bundle = $('.bundle'); // 限定作用域
let activityId = $bundle.data('activityid');
let batchNo = $bundle.data('poolbatchno');
self.handle = handle;
/**
* 减少套餐数量
*/
$bundle.on('click', '.bundle-nums .num-opt .btn-opt-minus', function(e) {
let skuIdsArray = [];
$(e.delegateTarget).find('.good-item').each(function() {
skuIdsArray.push($(this).data('id'));
});
self.decrBundle({
activity_id: activityId,
batch_no: batchNo,
sku_ids: skuIdsArray.join(',')
}, e);
});
/**
* 增加套餐数量
*/
$bundle.on('click', '.bundle-nums .num-opt .btn-opt-plus', function(e) {
let skuIdsArray = [];
$(e.delegateTarget).find('.good-item').each(function() {
skuIdsArray.push($(this).data('id'));
});
self.incrBundle({
activity_id: activityId,
batch_no: batchNo,
sku_ids: skuIdsArray.join(',')
}, e);
});
/**
* 套餐选中/取消
*/
$bundle.on('click', '.bundle-title .opt .select', function(e) {
self.bundleCheckHandle(e);
});
/**
* 编辑状态下套餐选中/取消
*/
$bundle.on('click', '.bundle-title .opt .edit', function(e) {
self.bundleEditCheckHandle(e);
});
},
/**
* 增加套餐数量
* @param {*} params
*/
incrBundle(params, e) {
let self = this;
$.post('/cart/index/new/incrbundle', params, function(result) {
let bundleNum = $(e.delegateTarget).find('.good-num');
let defaultValue = parseInt(bundleNum.val(), 10);
if (result.code === 200) {
bundleNum.val(defaultValue + 1);
self.handle.refreshPage();
} else {
tip.show(result.message);
}
});
},
/**
* 减少套餐数量
* @param {*} params
*/
decrBundle(params, e) {
let self = this;
$.post('/cart/index/new/decrbundle', params, function(result) {
let bundleNum = $(e.delegateTarget).find('.good-num');
let defaultValue = parseInt(bundleNum.val(), 10);
if (result.code === 200) {
bundleNum.val(defaultValue - 1);
self.handle.refreshPage();
} else {
tip.show(result.message);
}
});
},
/**
* 套餐选中
* @param {*} e
*/
bundleCheckHandle(e) {
let selectCheck = $(e.delegateTarget).find('.select');
let goodItem = $(e.delegateTarget).find('.good-item');
let skuData = [];
let selected = 'Y';
if (selectCheck.hasClass('checked')) {
selected = 'N';
}
goodItem.each(function(index, element) {
skuData.push({
product_sku: $(element).data('id'),
buy_number: $(e.delegateTarget).data('buynum'),
activity_id: $(e.delegateTarget).data('activityid'),
batch_no: $(e.delegateTarget).data('poolbatchno'),
selected: selected
});
});
loading.showLoading();
$.ajax({
type: 'post',
url: '/cart/index/new/select',
data: {
skuList: JSON.stringify(skuData)
},
success: function(result) {
if (result.code === 200) {
selectCheck.toggleClass('checked');
}
loading.hideLoading();
}
});
},
/**
* 编辑状态下套餐选中/取消
* @param {*} e
*/
bundleEditCheckHandle(e) {
let editCheck = $(e.delegateTarget).find('.edit');
let goodItem = $(e.delegateTarget).find('.good-item');
if (editCheck.hasClass('checked')) {
editCheck.removeClass('checked');
goodItem.find('.opt .edit').removeClass('checked');
} else {
editCheck.addClass('checked');
goodItem.find('.opt .edit').addClass('checked');
}
},
};
module.exports = bundle;
... ...
... ... @@ -35,6 +35,9 @@ let goodObj = {
$('.good-item').on('click', '.name,.color-size-row,.img', function(e) {
self.goodClick(e);
});
$('.good-item').on('click', '.bottom .re-add', function(e) {
self.reAddGood(e);
});
$('.check-all').on('click', function(e) {
self.checkedAllClick(e);
});
... ... @@ -151,8 +154,10 @@ let goodObj = {
if (self.handle.editMode) {
$(e.currentTarget).find('.chk.edit').toggleClass('checked');
if ($(e.currentTarget).find('.chk.edit').hasClass('checked')) {
$('.bundle-title .chk.edit').addClass('checked');
$('.good-item .chk.edit').addClass('checked');
} else {
$('.bundle-title .chk.edit').removeClass('checked');
$('.good-item .chk.edit').removeClass('checked');
}
} else {
... ... @@ -213,6 +218,32 @@ let goodObj = {
});
},
reAddGood(eles) {
let self = this;
loading.showLoading();
$.ajax({
type: 'post',
url: '/cart/index/add',
data: {
productSku: $(eles.delegateTarget).data('id')
},
dataType: 'json',
complete: () => {
loading.hideLoading();
},
success: function(result) {
if (result.code === 200) {
self.handle.refreshPage();
} else {
tip.show(result.message);
}
},
error: function() {
tip.show('网络异常');
}
});
},
delGood(eles) {
let self = this;
let skuData = self.getSelectGoodData(eles).map(ele => {
... ... @@ -286,7 +317,9 @@ let goodObj = {
let $this = $(ele),
$good = $this.closest('.good-item'),
id = $good.data('id'),
promotion = $good.data('promotion');
promotion = $good.data('promotion'),
batch_no = $good.data('poolbatchno'),
activity_id = $good.data('activityid');
let goodInfo = {};
... ... @@ -299,6 +332,16 @@ let goodObj = {
goodInfo.product_sku = id;
goodInfo.promotion_id = promotion;
goodInfo.buy_number = $good.find('.good-num').val();
// 套餐活动 ID
if (activity_id) {
goodInfo.activity_id = activity_id;
}
// 套餐活动批次
if (batch_no) {
goodInfo.batch_no = batch_no;
}
return goodInfo;
}));
... ... @@ -323,6 +366,11 @@ let goodObj = {
},
url;
// 套餐需要 activity_id
if (data.activity_id) {
Object.assign(goodData, {activity_id: data.activity_id});
}
if (promotionId) {
url = '/cart/index/new/modifyPriceGift';
} else {
... ... @@ -443,15 +491,17 @@ let goodObj = {
minNum,
promotionId;
let isSelected = $(e.delegateTarget).find('.chk.select').hasClass('checked');
let activityId = $(e.delegateTarget).data('activityid');
id = $(e.delegateTarget).data('id');
count = $(e.delegateTarget).find('.good-num').val();
minNum = $(e.delegateTarget).data('mnum');
promotionId = $(e.delegateTarget).data('promotion');
// 加价购或者赠品不能编辑数量
// 加价购或者赠品不能编辑数量,套餐不能编辑数量
canEditNum = $(e.delegateTarget).find('.flag.gift').length ||
$(e.delegateTarget).find('.flag.price-gift').length ? false : true;
$(e.delegateTarget).find('.flag.price-gift').length ||
$(e.delegateTarget).find('.flag.bundle').length ? false : true;
e.stopPropagation();
loading.showLoading();
$.ajax({
... ... @@ -464,6 +514,11 @@ let goodObj = {
},
type: 'POST',
success: function(data) {
// 套餐需要传 activityId
if (activityId) {
Object.assign(data, {activity_id: activityId});
}
self.showEditPannelWithSku(data, id, isSelected, canEditNum, promotionId, e);
},
error: function(err) {
... ...
... ... @@ -112,7 +112,8 @@ class ChosePanel {
return '加入购物车';
}
_defaultBuyNum() {
return this.modes.discount && this.data.discountBuy.num || 1;
return (this.modes.discount && this.data.discountBuy.num) ||
(this.data.cartInfo && this.data.cartInfo.num) || 1;
}
/**
... ...
... ... @@ -152,13 +152,31 @@ $buyNowBtn.on('touchstart', function() {
}
if (gsknSelected) {
window.setCookie('_cartType', 'bundle', actCkOpthn);
window.setCookie('activity-info', JSON.stringify({
product_sku_list: bundleGoods,
activity_id: bundleId
}), actCkOpthn);
window.location.href = '/cart/index/new/orderEnsure?cartType=bundle&activityType=bundle&productId=' +
window.queryString.productId;
// window.setCookie('_cartType', 'bundle', actCkOpthn);
// window.setCookie('activity-info', JSON.stringify({
// product_sku_list: bundleGoods,
// activity_id: bundleId
// }), actCkOpthn);
$.ajax({
method: 'post',
url: '/product/bundle/cart/add',
data: {
product_sku_list: JSON.stringify(bundleGoods),
activity_id: bundleId
},
success: function(result) {
tip.show(result.message);
if (result.code === 200) {
setTimeout(function() {
window.location.href = '/cart/index/index?cartType=ordinary';
}, 500);
}
},
error: function() {
tip.show('请求失败,请重试!');
}
});
}
});
... ...
.bundle > .bundle-title {
height: 80px;
display: flex;
overflow: hidden;
.opt {
width: 100px;
display: flex;
align-items: center;
justify-content: center;
.select {
display: block;
}
.edit {
display: none;
}
.disable {
background-color: #7f7f7f;
}
}
.title {
display: flex;
align-items: center;
span {
height: 40px;
margin-right: 30px;
padding: 4px;
font-size: 16px;
background-color: #d1021c;
color: #fff;
border-radius: 5px;
}
}
}
.bundle > .bundle-nums {
height: 80px;
display: none;
overflow: hidden;
.label {
width: 284px;
height: 80px;
display: flex;
align-items: center;
span {
padding-left: 100px;
}
}
.num-opt {
border: solid 1PX #dfdfdf;
border-radius: 5px;
display: flex;
align-items: center;
overflow: hidden;
.btn {
width: 78px;
display: block;
height: 100%;
text-align: center;
line-height: 74px;
.iconfont {
color: #444;
}
&.disabled {
.iconfont {
color: #b0b0b0;
}
}
&.btn-opt-minus {
border-right: 1PX solid #dfdfdf;
.iconfont:before {
content: "\e625";
}
}
&.btn-opt-plus {
border-left: 1px solid #dfdfdf;
.iconfont:before {
content: "\e624";
}
}
}
.good-num {
width: 120px;
text-align: center;
color: #444;
font-size: 32px;
background-color: #fff;
border: none;
line-height: 74px;
height: 74px;
&:disabled {
color: initial;
}
}
}
.count {
width: 155px;
text-align: right;
margin-right: 30px;
line-height: 80px;
color: #999;
}
}
.edit {
.bundle-title {
.opt {
.select {
display: none;
}
.edit {
display: block;
}
.disable {
display: none;
}
}
}
.bundle-nums {
display: flex;
}
}
.bundle > .good-list > .good-item {
.opt {
.chk {
visibility: hidden;
}
.disable {
visibility: hidden;
}
}
}
... ...
... ... @@ -196,6 +196,14 @@
}
}
.bottom > .re-add > span {
border: 1px solid #d0253b;
padding: 4px;
border-radius: 5px;
color: #d0253b;
font-size: 16px;
}
.name-row {
display: flex;
... ... @@ -266,8 +274,7 @@
line-height: 74px;
padding-left: 14px;
border: solid 1PX #dfdfdf;
border-top: none;
border-radius: 0 0 5px 5px;
border-radius: 5px;
display: flex;
color: #444;
... ... @@ -292,6 +299,11 @@
}
}
}
.edit-size-info-notop {
border-top: none;
border-radius: 0 0 5px 5px;
}
}
.num-opt {
... ...
... ... @@ -4,3 +4,4 @@
@import "common/good";
@import "layout/loading";
@import "chose-panel";
@import "bundle";
... ...
... ... @@ -139,7 +139,7 @@
}
.bundle-bar-md {
width: 400px;
width: 360px;
display: inline-block;
text-align: right;
... ...
... ... @@ -129,6 +129,10 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => {
result.inValidLow = inValidLow;
}
if (inValidLow && goodData.storage_number > 0) {
result.reAddToCart = true;
}
// gift=>是否赠品,advanceBuy=>是否加价购,soldOut=>失效商品;
if (!goodData.goods_type) {
result.inValid = true;
... ... @@ -156,6 +160,29 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => {
result.link = helpers.urlFormat(`/product/${goodData.product_skn}.html`); // 商品url改版
return result;
};
/**
* 失效商品池数据处理
* @param {*} pool
*/
const formatValidPool = (pool) => {
let poolTemp = {
poolBuyNumber: pool.pool_buy_number,
poolId: pool.pool_id,
poolStorageNumber: pool.pool_storage_number,
poolTitle: pool.pool_title,
selected: pool.selected,
showCheckbox: false,
isBundle: true
};
poolTemp.goods = _.get(pool, 'goods_list', []).map(good => {
return formatCartGoods(good, false, false, true);
});
return poolTemp;
};
const procPriceGiftData = (data, promotionType) => {
let result = {};
let arrays = _.get(data, 'arrays', []);
... ... @@ -256,7 +283,13 @@ const procCartData = (data, isAdvanceCart) => {
return {
isBrand: pool.pool_type <= 1,
isPromotion: pool.pool_type === 2,
isBundle: pool.pool_type === 3,
poolTitle: pool.pool_title,
poolBuyNumber: pool.pool_buy_number,
poolId: pool.pool_id, // 套餐 activity_id
poolBatchNo: pool.pool_batch_no, // 套餐批次
selected: pool.selected === 'Y', // 套餐是否选中
poolStorageNumber: pool.pool_storage_number, // 库存数量
goods: _.get(pool, 'goods_list', []).map(good => {
return formatCartGoods(good, isAdvanceCart);
}),
... ... @@ -285,6 +318,11 @@ const procCartData = (data, isAdvanceCart) => {
return formatCartGoods(good, isAdvanceCart, false, true);
});
// 失效的商品池
result.notValidPool = _.get(data, 'sold_out_goods_pool', []).map(pool => {
return formatValidPool(pool);
});
// 下架的商品列表
result.offShelveGoods = _.get(data, 'off_shelves_goods_list', []).map(good => {
return formatCartGoods(good, isAdvanceCart, false);
... ... @@ -347,7 +385,9 @@ const procCartData = (data, isAdvanceCart) => {
result.count = data.shopping_cart_data.selected_goods_count;
result.isAllSelected = (goodCount <= data.shopping_cart_data.selected_goods_count) && (data.shopping_cart_data.selected_goods_count > 0);// eslint-disable-line
result.sumPrice = transPrice(data.shopping_cart_data.last_order_amount);
result.hasNoSaleGoods = result.notValidGoods.length || result.offShelveGoods.length;
result.hasNoSaleGoods = result.notValidGoods.length ||
result.offShelveGoods.length ||
result.notValidPool.length;
return result;
};
... ...