Authored by 郭成尧

Merge branch 'feature/cart' of git.yoho.cn:fe/yohobuywap-node into feature/cart

... ... @@ -321,7 +321,7 @@ const modify = (req, res, next) => {
data ? res.json(data) : res.status(400).json({
message: '操作失败'
});
});
}).catch(next);
};
/**
... ... @@ -351,7 +351,7 @@ const modifyPriceGift = (req, res, next) => {
data ? res.json(data) : res.status(400).json({
message: '操作失败'
});
});
}).catch(next);
};
/**
... ... @@ -457,7 +457,7 @@ const giftinfo = (req, res, next) => {
}) : res.status(400).json({
message: '操作失败'
});
});
}).catch(next);
};
module.exports = {
... ...
... ... @@ -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;
});
};
... ...
... ... @@ -11,7 +11,6 @@
overflow: hidden;
text-align: center;
}
.search-input {
position: relative;
padding: 14px 30px;
... ... @@ -39,19 +38,10 @@
border: none;
}
.btn-intro,
.btn-col {
.clear-input {
position: absolute;
display: block;
width: 124px;
height: 48px;
line-height: 48px;
font-size: 12PX;
text-align: center;
border: 1px solid #fff;
color: #fff;
top: 50%;
margin-top: -24px;
top: 10px;
right: 100px;
}
.search {
... ... @@ -85,11 +75,11 @@
overflow: hidden;
}
.btn-col {
right: 30px;
.iconfont {
font-size: 12PX;
span {
font-size: 28px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.brand-name {
... ... @@ -133,6 +123,7 @@
width: 124px;
height: 48px;
line-height: 48px;
font-size: 12PX;
text-align: center;
border: 1px solid #fff;
color: #fff;
... ... @@ -148,7 +139,7 @@
right: 30px;
.iconfont {
font-size: 24px;
font-size: 12PX;
}
&.coled {
... ... @@ -190,17 +181,13 @@
line-height: 80px;
}
.list-nav {
border-top: 2px solid #fff;
.con {
font-size: 24px;
line-height: 32px;
padding: 40px 0;
border-top: 1px solid #e6e6e6;
border-bottom: 1px solid #e6e6e6;
> li {
float: left;
width: 25%;
height: 33PX;
line-height: 33PX;
text-align: center;
font-size: 14PX;
overflow-x: hidden;
}
.fo {
... ... @@ -228,10 +215,10 @@
> li {
float: left;
width: 25%;
height: 66px;
line-height: 66px;
height: 33PX;
line-height: 33PX;
text-align: center;
font-size: 28px;
font-size: 14PX;
}
.bytouch {
... ... @@ -252,16 +239,11 @@
box-sizing: border-box;
}
.new .iconfont {
transform: scale(0.8);
font-weight: bold;
font-size: 12PX;
}
.active > a {
color: #000;
.filter .iconfont {
font-size: 12PX;
transition: transform 0.1 ease-in;
}
.iconfont {
color: #999;
&.cur {
color: #000;
... ... @@ -269,27 +251,14 @@
}
}
.icon {
position: relative;
i {
position: absolute;
.new .iconfont {
transform: scale(0.8);
font-weight: bold;
}
.up {
top: -11PX;
}
.down {
top: -4PX;
}
}
font-size: 12PX;
}
.filter .iconfont {
font-size: 24px;
font-size: 12PX;
transition: transform 0.1 ease-in;
}
... ... @@ -307,31 +276,31 @@
}
.up {
top: -22px;
top: -11PX;
}
.down {
top: -8px;
top: -4PX;
}
}
}
}
.no-result {
.no-result {
text-align: center;
vertical-align: middle;
color: #ccc;
font-size: 1.2em;
margin-top: 440px;
}
}
.goods-container {
.goods-container {
position: relative;
min-height: 880px;
padding-left: 0.375rem;
padding-top: 0.2rem;
}
}
.new-list {
.new-list {
width: 100%;
background-color: #fff;
font-size: 28px;
... ... @@ -351,22 +320,23 @@
}
&.active {
background: resolve("product/shop/check.png") no-repeat 94% center;
background: resolve('product/shop/check.png') no-repeat 94% center;
background-size: 36px 26px;
}
}
}
}
.suspend-home {
.suspend-home {
bottom: 258px;
}
}
/* 搜索分割 */
.search-divide {
/*搜索分割*/
.search-divide {
float: left;
height: 50px;
width: 100%;
padding: 10px 0;
color: #ccc;
text-align: center;
}
}
\ No newline at end of file
... ...
... ... @@ -6,6 +6,7 @@
const helpers = global.yoho.helpers;
const _ = require('lodash');
const productProcess = require('./product-process');
const regPromoTitle = /^【[^]+】(.*)/;
... ... @@ -203,8 +204,9 @@ const formatPromotion = (promo) => {
*/
const procGoodsDetail = (productData, num) => {
let data = {};
let sizeInfo = productProcess.processSizeInfo(productData);
data.name = productData.product_name;
Object.assign(data, sizeInfo);
data.productSkn = productData.product_skn;
if (_.has(productData, 'special_price')) { // 加价购或者赠品的销售价字段
data.price = productData.format_market_price;
... ... @@ -222,145 +224,8 @@ const procGoodsDetail = (productData, num) => {
if (num) {
data.num = _.parseInt(num);
}
// 商品选择
if (_.has(productData, 'goods_list')) {
let goodsList = productData.goods_list;
let sizeName = '',
colors = [],
colorList = [],
sizes = [],
sizeList = {},
allSizeList = {}, // 所有尺码列表
thumbImageList = [],
colorNum = 0,
totalStorageNum = 0, // 总库存数
colorStorageGroup = {}; // 颜色分组的库存总数集合, 多个之间用/分隔
goodsList.forEach(val => {
// 商品的尺码列表
if (!colorStorageGroup[val.product_skc]) {
colorStorageGroup[val.product_skc] = {};
}
if (_.has(val, 'size_list')) {
// 尺码
if (!sizeList[val.product_skc]) {
sizeList[val.product_skc] = [];
}
val.size_list.forEach(one => {
sizeName = one.size_name;
sizeList[val.product_skc].push({
id: one.size_id,
skuId: one.product_sku,
goodsId: val.goods_id,
colorId: val.color_id,
name: one.size_name,
sizeNum: _.parseInt(one.storage_number, 10),
sizeInfo: one.size_info ? one.size_info : ''
});
// 所有尺码列表,赋值用于前端展示默认尺码的时候 判断出没有库存则显示灰色
allSizeList[sizeName] = !_.has(allSizeList, sizeName) ? {
id: one.size_id,
storage: one.storage_number,
sizeInfo: one.size_info ? one.size_info : ''
} : allSizeList[sizeName];
colorNum += _.parseInt(one.storage_number, 10);
colorStorageGroup[val.product_skc][sizeName] = _.parseInt(one.storage_number, 10);
});
// 颜色分组
colorList.push({
id: val.color_id,
skcId: val.product_skc,
name: val.factory_goods_name || val.color_name,
colorNum: colorNum,
goodsName: productData.product_name
});
}
// 缩略图
thumbImageList.push({
img: helpers.image(val.color_image, 300, 395)
});
// 商品库存总数
totalStorageNum += colorNum;
});
// 遍历所有尺码,构建颜色显示数据
let i = 1;
if (!sizes[0]) {
sizes[0] = {
size: []
};
}
if (!colors[0]) {
colors[0] = {
color: []
};
}
_.forEach(allSizeList, (value, sName) => {
// 默认尺码
sizes[0].size.push({
name: sName,
sizeNum: _.toNumber(value.storage) > 0 ? true : false,
id: value.id,
sizeInfo: value.sizeInfo
});
// 各个颜色的尺码, 每行显示一个尺码对应的颜色
if (!colors[i]) {
colors[i] = {
color: []
};
}
colorList.forEach(colorArr => {
colors[i].color.push({
id: colorArr.id,
skcId: colorArr.skcId,
name: colorArr.name,
colorNum: _.has(colorStorageGroup, `${colorArr.skcId}.${sName}`) ? _.parseInt(colorStorageGroup[colorArr.skcId][sName], 10) : 0,
goodsName: colorArr.goodsName
});
});
colors[i].id = value.id;
++i;
});
// 遍历所有颜色, 构建尺码显示数据
i = 1;
if (!sizes[i]) {
sizes[i] = {
color: []
};
}
colorList.forEach(value => {
// 各个尺码的颜色,每行显示一个颜色的对应尺码
sizes[i] = {
size: sizeList[value.skcId],
colorId: value.skcId
};
// 默认颜色
colors[0].color.push(value);
++i;
});
data.thumbs = thumbImageList;
data.colors = colors;
data.sizes = sizes;
data.totalNum = totalStorageNum;
data.colorName = '颜色';
data.sizeName = '尺码';
}
return data;
};
... ...
... ... @@ -344,3 +344,158 @@ exports.processFilter = (list, options) => {
return filters;
};
/**
* 解析尺码弹出框数据
*/
exports.processSizeInfo = (origin) => {
let cartInfo = {},
thumbImageList = [],
colorGroup = {},
sizeGroup = [],
totalStorageNum = 0;
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;
});
_.orderBy(colorGroup);
Object.assign(cartInfo, {
productId: origin.product_id,
thumbs: thumbImageList,
name: origin.product_name || '',
totalNum: totalStorageNum,
colors: _.toArray(colorGroup),
sizes: sizeGroup
});
}
return cartInfo;
};
... ...