Authored by yyq

商品详情调整

... ... @@ -55,7 +55,8 @@ exports.intro = (req, res) => {
productskn: req.params.productskn
}).then((result) => {
res.render('detail/intro', {
result: result
result: result,
layout: false
});
});
};
... ... @@ -74,7 +75,7 @@ exports.preference = (req, res) => {
}).then((result) => {
res.render('detail/preference', {
result: result,
devEnv: true
layout: false
});
});
};
... ...
... ... @@ -19,24 +19,23 @@ const api = new API();
* @return {array}
*/
const getShopsInfo = (data) => {
let enterStore = {};
let enterStore = [];
_.forEach(data, function(value, key) {
enterStore[key] = {
_.forEach(data, function(value) {
let shopInfo = {
img: value.brand_ico,
storeName: value.brand_name
};
if (value.shop_id !== null && typeof value.shop_id !== 'undefined') {
let params = {};
params.shop_id = value.shop_id;
enterStore[key].url =
helpers.urlFormat('/product/index/brand', params);
if (value.shop_id) {
shopInfo.url = helpers.urlFormat('/product/index/brand', {
shop_id: value.shop_id
});
} else {
enterStore[key].url =
helpers.urlFormat('', null, value.brand_domain);
shopInfo.url = helpers.urlFormat('', null, value.brand_domain);
}
enterStore.push(shopInfo);
});
return enterStore;
};
... ... @@ -120,9 +119,9 @@ const getLimitCodeUrl = (productCode, skn, ua) => {
*/
const detailDataPkg = (origin, uid, vipLevel, ua) => {
let dest = {}, // 结果输出
thumbImageList = [],
colorGroup = {},
thumbImageList = {},
sizeGroup = {},
sizeGroup = [],
totalStorageNum = 0;
// 商品名称
... ... @@ -141,92 +140,110 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
}
// 商品促销短语
if (origin.salesPhrase !== null && typeof origin.salesPhrase !== 'undefined') {
if (origin.salesPhrase) {
dest.goodsSubtitle = origin.salesPhrase;
}
// 商品标签
if (origin.productTagBoList !== null && typeof origin.productTagBoList !== 'undefined') {
if (origin.productTagBoList) {
let productTags = {};
_.forEach(origin.productTagBoList, function(value) {
switch (value.tagLabel) {
case 'is_soon_sold_out':
dest.tags.is_soon_sold_out = true;
productTags.is_soon_sold_out = true;
break;
case 'is_new':
dest.tags.is_new = true;
productTags.is_new = true;
break;
case 'is_discount':
dest.tags.is_discount = true;
productTags.is_discount = true;
break;
case 'is_limited':
dest.tags.is_limited = true;
productTags.is_limited = true;
break;
case 'is_yohood':
dest.tags.is_yohood = true;
productTags.is_yohood = true;
break;
case 'is_advance':
dest.tags.is_advance = true;
productTags.is_advance = true;
break;
default:
break;
}
});
dest.tags = productTags;
}
// 商品价格
dest.goodsPrice = {};
if (origin.productPriceBo) {
let originPrice = origin.productPriceBo;
let goodsPrice = {
currentPrice: originPrice.formatSalesPrice
};
if (origin.productPriceBo !== null && typeof origin.productPriceBo !== 'undefined') {
dest.goodsPrice.currentPrice = origin.productPriceBo.formatSalesPrice;
if (origin.productPriceBo.formatMarketPrice !== origin.productPriceBo.formatSalesPrice) {
dest.goodsPrice.previousPrice = origin.productPriceBo.formatMarketPrice;
if (originPrice.formatMarketPrice !== originPrice.formatSalesPrice) {
goodsPrice.previousPrice = originPrice.formatMarketPrice;
}
dest.goodsPrice = goodsPrice;
// 商品返回 YOHO 币
if (origin.productPriceBo.yohoCoinNum !== null && origin.productPriceBo.yohoCoinNum !== 0) {
dest.commodityReturn = origin.productPriceBo.yohoCoinNum;
if (originPrice.yohoCoinNum) {
dest.commodityReturn = originPrice.yohoCoinNum;
}
}
// VIP 商品价格
dest.vipLevel = {};
dest.vipLevel.list = [];
if (origin.productPriceBo.vipPrices) {
let vipList = [];
if (origin.productPriceBo.vipPrices !== null && typeof origin.productPriceBo.vipPrices !== 'undefined') {
_.forEach(origin.productPriceBo.vipPrices, function(value) {
dest.vipLevel.list.push({
vipList.push({
level: value.vipLevel,
text: value.vipPrice,
currentLevel: (value.vipLevel === vipLevel)
});
});
if (vipList.length) {
dest.vipLevel = {
list: vipList
};
}
}
// 上市期
if (origin.expectArrivalTime !== null && typeof origin.expectArrivalTime !== 'undefined') {
dest.periodOfMarket = origin.expectArrivalTime + '月';
if (origin.expectArrivalTime) {
dest.periodOfMarket = `${origin.expectArrivalTime}月`;
}
// 促销信息
dest.goodsDiscount = {};
dest.goodsDiscount.list = [];
if (origin.promotionBoList) {
let discountList = [];
if (origin.promotionBoList !== null && typeof origin.promotionBoList !== 'undefined') {
_.forEach(origin.promotionBoList, function(value) {
let temp = {};
temp.text = '【' + value.promotionType + '】' +
value.promotionTitle;
dest.goodsDiscount.list.push(temp);
discountList.push({
text: `【${value.promotionType}${value.promotionTitle}`
});
});
if (discountList.length) {
dest.goodsDiscount = {
list: discountList
};
}
}
// 商品咨询
dest.feedbacks = {};
dest.feedbacks.consults = [];
dest.feedbacks.consultsNum = 0;
dest.feedbacks = {
consults: [],
consultsNum: 0
};
if (origin.consultBoWrapper !== null && typeof origin.consultBoWrapper !== 'undefined') {
if (origin.consultBoWrapper) {
dest.feedbacks.consultsNum = origin.consultBoWrapper.consultTotal;
_.forEach(origin.consultBoWrapper.consultBoList, function(value) {
dest.feedbacks.consults.push({
... ... @@ -235,62 +252,57 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
answer: value.answer
});
});
}
let params = {};
params.product_id = origin.id;
params.total = dest.feedbacks.consultsNum;
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', params);
} else { // 暂无咨询
let consultParams = {
product_id: origin.id
};
let params = {};
if (_.has(dest, 'feedbacks.consultsNum')) {
consultParams.total = dest.feedbacks.consultsNum;
}
params.product_id = origin.id;
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', consultParams);
dest.feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', params);
}
// 商品评价
dest.feedbacks.commentsNum = 0;
if (origin.commentBoWrapper !== null && typeof origin.commentBoWrapper !== 'undefined') {
if (origin.commentBoWrapper) {
dest.feedbacks.commentsNum = origin.commentBoWrapper.commentTotal;
dest.feedbacks.comments = [];
let commentList = [];
_.forEach(origin.commentBoWrapper.commentBoList, function(value) {
dest.feedbacks.comments.push({
commentList.push({
userName: value.nickName,
desc: value.colorName + '/' + value.sizeName,
desc: `${value.colorName}/${value.sizeName}`,
content: value.content ? value.content : '',
time: value.createTime
});
});
let params = {};
params.product_id = origin.id;
params.total = dest.feedbacks.commentsNum;
dest.feedbacks.comments = commentList;
dest.feedbacks.commentsUrl = helpers.urlFormat('/product/detail/comments', params);
dest.feedbacks.commentsUrl = helpers.urlFormat('/product/detail/comments', {
product_id: origin.id,
total: dest.feedbacks.commentsNum
});
}
// 品牌信息
if (origin.brand !== null && typeof origin.brand !== 'undefined') {
if (origin.brand) {
// 为你优选的链接
let params = {};
params.productSkn = origin.erpProductId;
params.brandId = origin.brand.id;
dest.preferenceUrl = helpers.urlFormat('/product/detail/preference', params, '');
dest.preferenceUrl = helpers.urlFormat('/product/detail/preference', {
productSkn: origin.erpProductId,
brandId: origin.brand.id
});
}
dest.productSkn = origin.erpProductId;
// 商品信息
if (origin.goodsList !== null && typeof origin.goodsList !== 'undefined') {
let goodsGroup = {},
if (origin.goodsList) {
let goodsGroup = [],
sizeName = '',
colorList = {},
sizeList = {},
... ... @@ -300,42 +312,44 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
_.forEach(origin.goodsList, function(value, key) {
if (value.status === 0) {
return true;
return;
}
colorStorageNum = 0;
// 商品分组
if (value.goodsImagesList !== null && typeof value.goodsImagesList !== 'undefined') {
_.forEach(value.goodsImagesList, function(good, keyForGood) {
goodsGroup[keyForGood] = {};
goodsGroup[keyForGood].goodsId = good.goodsId;
goodsGroup[keyForGood].img = good.imageUrl;
if (value.goodsImagesList) {
_.forEach(value.goodsImagesList, function(good) {
goodsGroup.push({
goodsId: good.goodsId,
img: good.imageUrl
});
});
}
// 商品的尺码列表
colorStorageGroup[value.productSkc] = {};
if (value.goodsSizeBoList !== null && typeof value.goodsSizeBoList !== 'undefined') {
_.forEach(value.goodsSizeBoList, function(size, keyForSize) {
sizeList[value.productSkc] = {};
sizeList[value.productSkc][keyForSize] = {};
sizeList[value.productSkc][keyForSize].id = size.id;
sizeList[value.productSkc][keyForSize].skuId = size.goodsSizeSkuId;
sizeList[value.productSkc][keyForSize].goodsId = size.goodsId;
sizeList[value.productSkc][keyForSize].colorId = size.colorId;
sizeList[value.productSkc][keyForSize].name = size.sizeName;
sizeList[value.productSkc][keyForSize].sizeNum = size.goodsSizeStorageNum;
if (value.goodsSizeBoList) {
sizeList[value.productSkc] = [];
_.forEach(value.goodsSizeBoList, function(size) {
sizeList[value.productSkc].push({
id: size.id,
skuId: size.goodsSizeSkuId,
goodsId: size.goodsId,
colorId: size.colorId,
name: size.sizeName,
sizeNum: size.goodsSizeStorageNum
});
sizeName = size.sizeName;
// 所有尺码列表,赋值用于前端展示默认尺码的时候
// 判断出没有库存则显示灰色
let build = {};
let build = {
id: size.id,
storage: size.goodsSizeStorageNum
};
build.storage = size.goodsSizeStorageNum;
build.id = size.id;
allSizeList[sizeName] = (allSizeList[sizeName] === null ||
typeof allSizeList[sizeName] === 'undefined') ? build :
allSizeList[sizeName];
... ... @@ -345,94 +359,100 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
});
// 颜色分组
colorList[key] = {};
colorList[key].id = value.colorId;
colorList[key].skcId = value.productSkc;
colorList[key].name = value.colorName;
colorList[key].goodsName = value.goodsName;
colorList[key].colorNum = colorStorageNum;
colorList[key] = {
id: value.colorId,
skcId: value.productSkc,
name: value.colorName,
goodsName: value.goodsName,
colorNum: colorStorageNum
};
}
// 缩略图
let params = {};
params.img = value.colorImage;
thumbImageList[key] = params;
thumbImageList.push({
img: value.colorImage
});
// 商品库存总数
totalStorageNum += colorStorageNum;
totalStorageNum += _.toNumber(colorStorageNum);
});
// 遍历所有尺码,构建颜色显示数据
let i = 1;
_.forEach(allSizeList, function(value, key) {
sizeGroup[0] = {
size: []
};
_.forEach(allSizeList, function(value) {
// 默认尺码
sizeGroup[0] = {};
sizeGroup[0].size.push({
name: sizeName,
sizeNum: _.toNumber(value.storage) > 0 ? true : false,
id: value.id
});
sizeGroup[0].size = {};
sizeGroup[0].size[key] = {};
sizeGroup[0].size[key].name = sizeName;
sizeGroup[0].size[key].sizeNum = (typeof value.storage === 'undefined' ||
value.storage === null) ? false : true;
sizeGroup[0].size[key].id = value.id;
colorGroup[i] = {
color: []
};
// 各个颜色的尺码, 每行显示一个尺码对应的颜色
_.forEach(colorList, function(colorArr, keyForColorArr) {
colorGroup[i] = {};
colorGroup[i].color = {};
colorGroup[i].color[keyForColorArr] = {};
colorGroup[i].color[keyForColorArr].colorNum =
(colorStorageGroup[colorArr.skcId][sizeName] !== null &&
typeof colorStorageGroup[colorArr.skcId][sizeName] !== 'undefined') ?
colorStorageGroup[colorArr.skcId][sizeName] : 0;
_.forEach(colorList, function(colorArr) {
colorArr.colorNum = 0;
if (colorStorageGroup[colorArr.skcId] &&
colorStorageGroup[colorArr.skcId][sizeName]) {
colorArr.colorNum = colorStorageGroup[colorArr.skcId][sizeName];
}
colorGroup[i].color.push(colorArr);
});
colorGroup[i].id = value.id;
++i;
});
// 遍历所有颜色, 构建尺码显示数据
colorGroup[0] = {
color: []
};
// 遍历所有颜色, 构建尺码显示数据
i = 1;
_.forEach(colorList, function(value, key) {
_.forEach(colorList, function(value) {
// 各个尺码的颜色, 每行显示一个颜色的对应尺码
sizeGroup[i] = {};
sizeGroup[i].size = sizeList[value.skcId];
sizeGroup[i].colorId = value.skcId;
sizeGroup[i] = {
size: sizeList[value.skcId],
colorId: value.skcId
};
// 默认颜色
colorGroup[0] = {};
colorGroup[0].color = {};
colorGroup[0].color[key] = value;
colorGroup[0].color.push(value);
++i;
});
// 商品图:多个
if (goodsGroup[1] !== null && typeof goodsGroup[1] !== 'undefined') {
dest.bannerTop = {};
dest.bannerTop.list = [];
if (goodsGroup.length > 1) {
let bannerList = [];
_.forEach(goodsGroup, function(value) {
let params = {};
params.img = value.img;
dest.bannerTop.list.push(params);
bannerList.push({
img: value.img
});
});
dest.bannerTop = {
list: bannerList
};
} else if (goodsGroup[0] !== null && typeof goodsGroup[0] !== 'undefined') {
dest.bannerTop = {};
dest.bannerTop.img = goodsGroup[0].img;
dest.bannerTop = {
img: goodsGroup[0].img
};
}
}
// 悬浮的购物车信息
dest.cartInfo = {};
dest.cartInfo.cartUrl = helpers.urlFormat('/cart/index/index', null);
dest.cartInfo.numInCart = 0;
dest.cartInfo.goodsInstore = origin.storage;
dest.cartInfo = {
cartUrl: helpers.urlFormat('/cart/index/index'),
numInCart: 0,
goodsInstore: origin.storage
};
let soldOut = (origin.storage === 0) || (origin.status === 0 || totalStorageNum === 0);
let notForSale = origin.attribute === 2;
... ... @@ -441,17 +461,16 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
if (!soldOut && !notForSale) {
_.orderBy(colorGroup);
dest.cartInfo = {};
dest.cartInfo.productId = origin.id;
dest.cartInfo.thumbs = thumbImageList;
dest.cartInfo.name = (dest.goodsName !== null && typeof dest.goodsName !== 'undefined') ? dest.goodsName : '';
dest.cartInfo.price = (dest.goodsPrice.previousPrice !== null &&
typeof dest.goodsPrice.previousPrice !== 'undefined') ? dest.goodsPrice.previousPrice : '';
dest.cartInfo.salePrice = (dest.goodsPrice.currentPrice !== null &&
typeof dest.goodsPrice.currentPrice !== 'undefined') ? dest.goodsPrice.currentPrice : '';
dest.cartInfo.totalNum = totalStorageNum;
dest.cartInfo.colors = colorGroup;
dest.cartInfo.sizes = sizeGroup;
Object.assign(dest.cartInfo, {
productId: origin.id,
thumbs: thumbImageList,
name: dest.goodsName ? dest.goodsName : '',
price: dest.goodsPrice.previousPrice ? dest.goodsPrice.previousPrice : '',
salePrice: dest.goodsPrice.currentPrice ? dest.goodsPrice.currentPrice : '',
totalNum: totalStorageNum,
colors: _.toArray(colorGroup),
sizes: sizeGroup
});
// 限购商品
if (origin.isLimitBuy === 'Y') {
... ... @@ -468,6 +487,7 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
// 处理限购商品有关的按钮状态
dest = procShowStatus(dest, showStatus, isBeginSale);
Object.assign;
dest.cartInfo.limitProductCode = origin.limitProductCode;
dest.cartInfo.limitCodeUrl = getLimitCodeUrl(origin.limitProductCode, origin.erpProductId, ua);
dest.cartInfo.limitProductPay = helpers.urlFormat('/cart/index/orderEnsure'); // 待处理 相关处理逻辑还不存在
... ... @@ -488,11 +508,8 @@ const detailDataPkg = (origin, uid, vipLevel, ua) => {
dest.isCollect = true;
}
// 底部简介的URL链接 待处理
// dest.introUrl = helpers.urlFormat('/product/intro_' + origin.erpProductId +
// '/' + origin.cnAlphabet + '.html', null, '');
dest.introUrl = 'http://localhost:6001/product/detail/intro/' + origin.erpProductId;
// 底部简介URL链接
dest.introUrl = '/product/detail/intro/' + origin.erpProductId;
dest.id = origin.id;
return dest;
... ...
... ... @@ -10,20 +10,19 @@
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const _ = require('lodash');
const productProcess = require(`${utils}/product-process`);
var api = new API();
const api = new API();
module.exports = (data) => {
var finalResult;
let finalResult;
return api.get('', sign.apiSign({
return api.get('', {
method: 'h5.preference.Search',
productskn: data.productskn,
yhchannel: data.yhchannel,
brandId: data.brandId
})).then(result => {
}).then(result => {
if (!_.isEmpty(result) && result.code === 200) {
// 为你优选数据处理,接口没有数据,待处理,待验证
finalResult = productProcess.processProductList(result.data);
... ...
... ... @@ -23,7 +23,7 @@ const outlet = require(`${cRoot}/outlet`);
// /pro_136349_455445/HEARTSOFARMianMaShuJiaoXiuXianKuPS1684.html
router.get(/\/pro_([\d]+)_([\d]+)\/(.*)/, detail.index);
router.get('/detail/intro/:productskn', detail.intro);
router.get('/detail/preference/:productskn/:yhchannel/:brandId', detail.preference);
router.get('/detail/preference', detail.preference);
router.get('/sale', sale.index);
router.get('/sale/discount', sale.discount);
... ...
... ... @@ -75,7 +75,7 @@
</li>
{{/ list}}
</ul>
{{/vipLevel}}
{{/ vipLevel}}
{{# goodsDiscount}}
<div class="goods-discount" id="goodsDiscount">
... ... @@ -119,7 +119,7 @@
{{# enterStore}}
<div id="enter-store" class="enter-store page-block tap-hightlight">
<a class="store-logo" href="{{url}}" style="">
<img class="lazy" data-original="{{img}}" alt="{{storeName}}">
<img class="lazy" data-original="{{image img 47 47}}" alt="{{storeName}}">
</a>
<a class="store-name" href="{{url}}">{{storeName}}</a>
<a class="store-link" href="{{url}}">进入店铺<span class="iconfont">&#xe604;</span></a>
... ...
{{> product/recommend-content}}
\ No newline at end of file
{{> product/detail/recommend-for-you}}
\ No newline at end of file
... ...
... ... @@ -4,7 +4,7 @@
<div class="infos">
<div class="basic-info" >
{{#thumbs}}
<img class="thumb {{#unless @first}}hide{{/unless}}" src={{img}}>
<img class="thumb {{#unless @first}}hide{{/unless}}" src={{image img 60 60}}>
{{/thumbs}}
<div class="text-info">
<p class="name">{{name}}</p>
... ...
... ... @@ -272,7 +272,6 @@
.nav-tab {
padding: 10px 0;
width: 100%;
height: 60px;
border-top: 1px solid $borderC;
border-bottom: 1px solid $borderC;
background-color: #fff;
... ...
... ... @@ -569,6 +569,3 @@ $basicBtnC: #eb0313;
top: 40%;
}
}
@import "comments-consults";
@import "product-description";
... ...
@import "detail";
@import "comments-consults";
@import "comments-consults";
@import "product-description";
@import "recommend-for-you";
... ...