...
|
...
|
@@ -588,11 +588,7 @@ let getProductAsyncData = (data) => { |
|
|
* [商品信息格式化异步接口]
|
|
|
*/
|
|
|
let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => {
|
|
|
let dest = {}, // 结果输出
|
|
|
thumbImageList = [],
|
|
|
colorGroup = {},
|
|
|
sizeGroup = [],
|
|
|
totalStorageNum = 0;
|
|
|
let dest = {}; // 结果输出
|
|
|
|
|
|
// 用户未登录时
|
|
|
if (!uid) {
|
...
|
...
|
@@ -679,141 +675,8 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { |
|
|
}
|
|
|
|
|
|
// 商品信息
|
|
|
if (origin.goods_list.length) {
|
|
|
let goodsGroup = [],
|
|
|
sizeName = '',
|
|
|
colorList = [],
|
|
|
sizeList = {},
|
|
|
allSizeList = {},
|
|
|
colorStorageGroup = {},
|
|
|
colorStorageNum = 0;
|
|
|
|
|
|
_.forEach(origin.goods_list, function(value) {
|
|
|
// 未上架也显示
|
|
|
// if (value.status === 0) {
|
|
|
// return;
|
|
|
// }
|
|
|
|
|
|
colorStorageNum = 0;
|
|
|
|
|
|
// 商品分组
|
|
|
if (value.images_list) {
|
|
|
_.forEach(value.images_list, function(good) {
|
|
|
goodsGroup.push({
|
|
|
goodsId: value.goods_id,
|
|
|
img: good.image_url
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 商品的尺码列表
|
|
|
colorStorageGroup[value.product_skc] = {};
|
|
|
if (value.size_list) {
|
|
|
sizeList[value.product_skc] = [];
|
|
|
_.forEach(value.size_list, function(size) {
|
|
|
sizeList[value.product_skc].push({
|
|
|
id: size.size_id,
|
|
|
skuId: size.product_sku,
|
|
|
goodsId: value.goods_id,
|
|
|
colorId: value.color_id,
|
|
|
name: size.size_name,
|
|
|
sizeNum: size.storage_number,
|
|
|
sizeInfo: size.size_info ? size.size_info : ''
|
|
|
});
|
|
|
|
|
|
sizeName = size.size_name;
|
|
|
|
|
|
// 所有尺码列表,赋值用于前端展示默认尺码的时候
|
|
|
// 判断出没有库存则显示灰色
|
|
|
let build = {
|
|
|
id: size.size_id,
|
|
|
storage: size.storage_number,
|
|
|
sizeInfo: size.size_info ? size.size_info : ''
|
|
|
};
|
|
|
|
|
|
allSizeList[sizeName] = (allSizeList[sizeName] === null ||
|
|
|
typeof allSizeList[sizeName] === 'undefined') ? build : allSizeList[sizeName];
|
|
|
colorStorageNum += parseInt(size.storage_number, 10);
|
|
|
colorStorageGroup[value.product_skc][sizeName] = parseInt(size.storage_number, 10);
|
|
|
});
|
|
|
|
|
|
|
|
|
// 颜色分组
|
|
|
colorList.push({
|
|
|
id: value.color_id,
|
|
|
skcId: value.product_skc,
|
|
|
name: value.factory_goods_name || value.color_name,
|
|
|
colorNum: colorStorageNum
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 缩略图
|
|
|
thumbImageList.push({
|
|
|
img: helpers.image(value.color_image, 300, 395)
|
|
|
});
|
|
|
|
|
|
// 商品库存总数
|
|
|
totalStorageNum += _.toNumber(colorStorageNum);
|
|
|
});
|
|
|
|
|
|
// 遍历所有尺码,构建颜色显示数据
|
|
|
let i = 1;
|
|
|
|
|
|
sizeGroup[0] = {
|
|
|
size: []
|
|
|
};
|
|
|
_.forEach(allSizeList, (value, key) => {
|
|
|
|
|
|
// 默认尺码
|
|
|
sizeGroup[0].size.push({
|
|
|
name: key,
|
|
|
sizeNum: _.toNumber(value.storage) > 0 ? true : false,
|
|
|
id: value.id,
|
|
|
sizeInfo: value.sizeInfo
|
|
|
});
|
|
|
|
|
|
colorGroup[i] = {
|
|
|
color: []
|
|
|
};
|
|
|
|
|
|
// 各个颜色的尺码, 每行显示一个尺码对应的颜色
|
|
|
_.forEach(colorList, (colorArr) => {
|
|
|
let tempColorArr = _.cloneDeep(colorArr);
|
|
|
|
|
|
if (colorStorageGroup[tempColorArr.skcId] &&
|
|
|
colorStorageGroup[tempColorArr.skcId][key]) {
|
|
|
tempColorArr.colorNum = colorStorageGroup[tempColorArr.skcId][key];
|
|
|
} else {
|
|
|
tempColorArr.colorNum = 0;
|
|
|
}
|
|
|
colorGroup[i].color.push(Object.assign({}, tempColorArr));
|
|
|
});
|
|
|
colorGroup[i].id = value.id;
|
|
|
|
|
|
++i;
|
|
|
});
|
|
|
|
|
|
colorGroup[0] = {
|
|
|
color: []
|
|
|
};
|
|
|
|
|
|
// 遍历所有颜色, 构建尺码显示数据
|
|
|
i = 1;
|
|
|
_.forEach(colorList, function(value) {
|
|
|
|
|
|
// 各个尺码的颜色, 每行显示一个颜色的对应尺码
|
|
|
sizeGroup[i] = {
|
|
|
size: sizeList[value.skcId],
|
|
|
colorId: value.skcId
|
|
|
};
|
|
|
|
|
|
// 默认颜色
|
|
|
colorGroup[0].color.push(value);
|
|
|
++i;
|
|
|
});
|
|
|
|
|
|
}
|
|
|
let soldOut = (origin.storage_sum === 0) || (totalStorageNum === 0); // status
|
|
|
let cartInfo = productProcess.processSizeInfo(origin);
|
|
|
let soldOut = (origin.storage_sum === 0) || (cartInfo.totalStorageNum === 0); // status
|
|
|
let notForSale = origin.attribute === 2;
|
|
|
let preSale = (origin.status === 0 && origin.advance_shelve_time > 0);
|
|
|
|
...
|
...
|
@@ -827,16 +690,9 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { |
|
|
|
|
|
// 显示加入购物车链接
|
|
|
if (!soldOut && !notForSale && !preSale || origin.isLimitBuy) {
|
|
|
_.orderBy(colorGroup);
|
|
|
Object.assign(dest.cartInfo, {
|
|
|
productId: origin.product_id,
|
|
|
thumbs: thumbImageList,
|
|
|
name: dest.goodsName || '',
|
|
|
Object.assign(dest.cartInfo, cartInfo, {
|
|
|
price: dest.goodsPrice.previousPrice ? dest.goodsPrice.previousPrice : '',
|
|
|
salePrice: dest.goodsPrice.currentPrice ? dest.goodsPrice.currentPrice : '',
|
|
|
totalNum: totalStorageNum,
|
|
|
colors: _.toArray(colorGroup),
|
|
|
sizes: sizeGroup
|
|
|
});
|
|
|
|
|
|
// 限购商品
|
...
|
...
|
@@ -889,33 +745,33 @@ let _detailDataPkgAsync = (origin, uid, vipLevel, ua) => { |
|
|
dest.cartInfo.preSale = true;
|
|
|
}
|
|
|
return resolve(dest);
|
|
|
}).then(dest => {
|
|
|
}).then(result => {
|
|
|
// 虚拟商品(门票)
|
|
|
if (origin.attribute * 1 === 3) {
|
|
|
dest.tickets = true;
|
|
|
dest.ticketsConfirm = helpers.urlFormat('/cart/index/ticketsConfirm');
|
|
|
result.tickets = true;
|
|
|
result.ticketsConfirm = helpers.urlFormat('/cart/index/ticketsConfirm');
|
|
|
|
|
|
// 展览票
|
|
|
if (origin.product_skn * 1 === SINGLE_TICKETS_SKN) {
|
|
|
dest.single = true;
|
|
|
result.single = true;
|
|
|
} else {
|
|
|
// 套票
|
|
|
dest.package = true;
|
|
|
result.package = true;
|
|
|
}
|
|
|
|
|
|
// 购票限制
|
|
|
dest.cartInfo.limit = 4;
|
|
|
result.cartInfo.limit = 4;
|
|
|
|
|
|
// 清空活动
|
|
|
dest.goodsDiscount = [];
|
|
|
result.goodsDiscount = [];
|
|
|
}
|
|
|
dest.id = origin.product_id;
|
|
|
dest.goodsId = origin.goods_id;
|
|
|
if (dest.isSecKill === 'Y' && dest.cartInfo.totalNum > 0) {
|
|
|
dest.totalNum = 1;
|
|
|
result.id = origin.product_id;
|
|
|
result.goodsId = origin.goods_id;
|
|
|
if (result.isSecKill === 'Y' && result.cartInfo.totalNum > 0) {
|
|
|
result.totalNum = 1;
|
|
|
}
|
|
|
return dest;
|
|
|
})
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
|