...
|
...
|
@@ -9,13 +9,91 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
/**
|
|
|
* 使sizeBoList id以 sizeAttributeBos id顺序一样
|
|
|
* @param sizeInfoBo
|
|
|
*/
|
|
|
const _sizeInfoBoSort = sizeInfoBo => {
|
|
|
if (!sizeInfoBo.sizeBoList || !sizeInfoBo.sizeAttributeBos) {
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
// TODO: 这里的排序代码很乱
|
|
|
|
|
|
_.forEach(sizeInfoBo.sizeBoList, (sizeBoList, sizek)=> {
|
|
|
let sortAttr = {};
|
|
|
|
|
|
_.forEach(sizeBoList.sortAttributes, sortAttributes => {
|
|
|
sortAttr[sortAttributes.id] = sortAttributes;
|
|
|
});
|
|
|
|
|
|
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
|
|
|
});
|
|
|
|
|
|
|
|
|
_.forEach(sizeInfoBo.sizeBoList, (sizeBoList, sizek)=> {
|
|
|
let sortAttr = [];
|
|
|
|
|
|
_.forEach(sizeInfoBo.sizeAttributeBos, val => {
|
|
|
sortAttr.push(sizeBoList.sortAttributes[val.id]);
|
|
|
});
|
|
|
|
|
|
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
|
|
|
|
|
|
});
|
|
|
|
|
|
return sizeInfoBo;
|
|
|
};
|
|
|
|
|
|
const setPathNav = (data, name) => {
|
|
|
let resData = {};
|
|
|
|
|
|
if (!_.isEmpty(data)) {
|
|
|
let navs = [];
|
|
|
let sort = data.sort[0];
|
|
|
|
|
|
navs.push({
|
|
|
link: helpers.urlFormat('/list', {
|
|
|
msort: sort.sort_id
|
|
|
|
|
|
// gender: '' // 待处理
|
|
|
}),
|
|
|
name: sort.sort_name,
|
|
|
pathTitle: sort.sort_name
|
|
|
});
|
|
|
|
|
|
// 二级分类
|
|
|
if (!_.isEmpty(sort.sub)) {
|
|
|
navs.push({
|
|
|
link: helpers.urlFormat('/list', {
|
|
|
msort: sort.sort_id,
|
|
|
misort: sort.sub.sort_id
|
|
|
|
|
|
// gender: '' // 待处理
|
|
|
}),
|
|
|
name: sort.sub[0].sort_name,
|
|
|
pathTitle: sort.sub[0].sort_name
|
|
|
});
|
|
|
}
|
|
|
|
|
|
navs.push({
|
|
|
name: name,
|
|
|
pathTitle: name
|
|
|
});
|
|
|
|
|
|
resData.nav = navs;
|
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置品牌banner数据
|
|
|
* @param brand 品牌相关数据
|
|
|
* @return Object
|
|
|
*/
|
|
|
const setBrandBanner = brand => {
|
|
|
let data = {
|
|
|
bgColor: '#93897d',
|
|
|
bgColor: '#000',
|
|
|
brandLogo: {
|
|
|
link: `#${brand.brandDomain}`, // 品牌跳转链接 -- 待处理
|
|
|
img: brand.brandIco
|
...
|
...
|
@@ -166,10 +244,11 @@ const setBrandIntro = brand => { |
|
|
|
|
|
/**
|
|
|
* 设置商品描述
|
|
|
* @param brand 品牌相关数据
|
|
|
* @param sizeInfo
|
|
|
* @param comfortInfo
|
|
|
* @return Object
|
|
|
*/
|
|
|
const setDescriptionInfo = (sizeInfo, comfortInfo) => {
|
|
|
const setDescriptionData = (sizeInfo, comfortInfo) => {
|
|
|
let resData = {};
|
|
|
|
|
|
if (_.has(sizeInfo, 'productDescBo.erpProductId')) {
|
...
|
...
|
@@ -198,7 +277,7 @@ const setDescriptionInfo = (sizeInfo, comfortInfo) => { |
|
|
];
|
|
|
|
|
|
if (_.isArray(sizeInfo.productDescBo.standardBos)) {
|
|
|
_.forEach(sizeInfo.productDescBo.standardBos, function(value) {
|
|
|
_.forEach(sizeInfo.productDescBo.standardBos, value => {
|
|
|
basic.push({
|
|
|
key: value.standardName,
|
|
|
value: value.standardVal
|
...
|
...
|
@@ -211,7 +290,7 @@ const setDescriptionInfo = (sizeInfo, comfortInfo) => { |
|
|
if (comfortInfo) {
|
|
|
let comfort = [];
|
|
|
|
|
|
_.forEach(comfortInfo, function(value) {
|
|
|
_.forEach(comfortInfo, value => {
|
|
|
let i = 1;
|
|
|
let blocks = [];
|
|
|
let flag = false;
|
...
|
...
|
@@ -249,9 +328,243 @@ const setDescriptionInfo = (sizeInfo, comfortInfo) => { |
|
|
return resData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置洗涤材质信息
|
|
|
* @param sizeInfo
|
|
|
* @return Object
|
|
|
*/
|
|
|
const setMaterialData = sizeInfo => {
|
|
|
let resData = {};
|
|
|
let material = {};
|
|
|
|
|
|
// 洗涤提示
|
|
|
if (sizeInfo.washTipsBoList) {
|
|
|
let wash = [];
|
|
|
|
|
|
_.forEach(sizeInfo.washTipsBoList, value => {
|
|
|
wash.push({
|
|
|
name: value.caption,
|
|
|
img: value.img
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (!_.isEmpty(wash)) {
|
|
|
material.wash = wash;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 商品材质[洗涤说明]
|
|
|
if (sizeInfo.productMaterialList) {
|
|
|
let detail = [];
|
|
|
|
|
|
_.forEach(sizeInfo.productMaterialList, value => {
|
|
|
detail.push({
|
|
|
img: value.imageUrl,
|
|
|
name: value.caption,
|
|
|
enName: value.encaption,
|
|
|
text: value.remark
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (!_.isEmpty(detail)) {
|
|
|
material.detail = detail;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!_.isEmpty(material)) {
|
|
|
Object.assign(material, {
|
|
|
titleEn: 'MATERIALS',
|
|
|
titleCn: '材料洗涤'
|
|
|
});
|
|
|
|
|
|
resData.material = material;
|
|
|
}
|
|
|
return resData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置尺寸信息
|
|
|
* @param sizeInfo
|
|
|
* @return Object
|
|
|
*/
|
|
|
const setSizeData = (sizeInfo) => {
|
|
|
let resData = {};
|
|
|
|
|
|
if (sizeInfo.sizeInfoBo) {
|
|
|
let referenceName,
|
|
|
boyReference,
|
|
|
girlReference,
|
|
|
gender;
|
|
|
let size = {
|
|
|
titleEn: 'SIZEINFO',
|
|
|
titleCn: '尺码信息'
|
|
|
};
|
|
|
|
|
|
sizeInfo.sizeInfoBo = _sizeInfoBoSort(sizeInfo.sizeInfoBo);
|
|
|
|
|
|
// 参考尺码
|
|
|
if (_.has(sizeInfo, 'productExtra')) {
|
|
|
boyReference = sizeInfo.productExtra.boyReference;
|
|
|
girlReference = sizeInfo.productExtra.girlReference;
|
|
|
}
|
|
|
|
|
|
gender = _.has(sizeInfo, 'productDescBo.gender') ? sizeInfo.productDescBo.gender : 3;
|
|
|
if (gender === 3 && boyReference) {
|
|
|
referenceName = '参考尺码(男)';
|
|
|
} else if (gender === 3 && girlReference) {
|
|
|
referenceName = '参考尺码(女)';
|
|
|
} else {
|
|
|
referenceName = '参考尺码';
|
|
|
}
|
|
|
|
|
|
// 判断是否显示参考尺码
|
|
|
let showReference = (boyReference && _.get(sizeInfo.sizeInfoBo, 'sizeBoList[0].boyReferSize', false)) ||
|
|
|
(girlReference && _.get(sizeInfo.sizeInfoBo, 'sizeBoList[0].girlReferSize', false));
|
|
|
|
|
|
if (sizeInfo.sizeInfoBo.sizeAttributeBos) {
|
|
|
let sizeTable = {};
|
|
|
|
|
|
// 尺码信息头部
|
|
|
sizeTable.thead = [{name: '吊牌尺码', id: '', width: 126}];
|
|
|
|
|
|
// 显示参考尺码
|
|
|
if (showReference) {
|
|
|
sizeTable.thead.push({name: referenceName, id: '', width: 126});
|
|
|
}
|
|
|
|
|
|
_.forEach(sizeInfo.sizeInfoBo.sizeAttributeBos, value => {
|
|
|
sizeTable.thead.push({
|
|
|
name: value.attributeName || ' ',
|
|
|
id: value.id,
|
|
|
width: 126
|
|
|
});
|
|
|
});
|
|
|
|
|
|
sizeTable.tbody = [];
|
|
|
_.forEach(sizeInfo.sizeInfoBo.sizeBoList, value => {
|
|
|
let sizes = [];
|
|
|
|
|
|
// 吊牌尺码
|
|
|
sizes.push(value.sizeName);
|
|
|
|
|
|
// 判断是否显示参考尺码
|
|
|
if (boyReference && (gender === 1 || gender === 3) && showReference) {
|
|
|
sizes.push(value.boyReferSize.referenceName || ' ');
|
|
|
} else if (girlReference && (gender === 2 || gender === 3) && showReference) {
|
|
|
sizes.push(value.girlReferSize.referenceName || ' ');
|
|
|
} else {
|
|
|
if (sizeTable.thead[1] && showReference) {
|
|
|
sizeTable.thead[1] = {};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 其他尺码信息
|
|
|
value.sortAttributes.forEach(attr => {
|
|
|
sizes.push((attr.sizeValue || ' '));
|
|
|
});
|
|
|
|
|
|
// 尺码信息
|
|
|
sizeTable.tbody.push(sizes);
|
|
|
});
|
|
|
|
|
|
// 参考尺码为空
|
|
|
if (_.isEmpty(sizeTable.thead[1]) && showReference) {
|
|
|
// 移除这个值
|
|
|
sizeTable.thead.splice(1, 1);
|
|
|
}
|
|
|
|
|
|
size.param = sizeTable;
|
|
|
}
|
|
|
|
|
|
if (!_.isEmpty(sizeInfo.modelBos)) {
|
|
|
let tasteTable = {};
|
|
|
|
|
|
tasteTable.thead = [
|
|
|
{name: '模特', width: 170},
|
|
|
{name: '身高', width: 126},
|
|
|
{name: '体重', width: 126},
|
|
|
{name: '三围', width: 126},
|
|
|
{name: '吊牌尺码', width: 126},
|
|
|
{name: '试穿描述', width: 126}
|
|
|
];
|
|
|
|
|
|
tasteTable.tbody = [];
|
|
|
_.forEach(sizeInfo.modelBos, value => {
|
|
|
let modelInfo = [
|
|
|
value.avatar, value.modelName, value.height,
|
|
|
value.weight, value.vitalStatistics, value.fitModelBo.fit_size,
|
|
|
value.fitModelBo.feel
|
|
|
];
|
|
|
|
|
|
// 是否有备注
|
|
|
if (_.get(value, 'fitModelBo.fit_remark', false)) {
|
|
|
modelInfo.push(value.fitModelBo.fit_remark);
|
|
|
tasteTable.thead[7] = {name: '备注', width: 170};
|
|
|
}
|
|
|
tasteTable.tbody.push(modelInfo);
|
|
|
});
|
|
|
|
|
|
size.taste = tasteTable;
|
|
|
}
|
|
|
|
|
|
resData.sizeInfo = size;
|
|
|
}
|
|
|
return resData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 设置商品详情页介绍
|
|
|
*
|
|
|
* @param array sizeInfo
|
|
|
* @return string
|
|
|
*/
|
|
|
const setDetailData = sizeInfo => {
|
|
|
let resData = {};
|
|
|
|
|
|
// 详情配图
|
|
|
if (_.has(sizeInfo, 'productIntroBo.productIntro')) {
|
|
|
let details = {
|
|
|
titleEn: 'DETAILS',
|
|
|
titleCn: '商品详情'
|
|
|
};
|
|
|
|
|
|
if (sizeInfo.productDescBo && sizeInfo.productDescBo.phrase) {
|
|
|
details.content = `${sizeInfo.productDescBo.phrase}<br/>`;
|
|
|
}
|
|
|
|
|
|
// 图片换规则
|
|
|
const replacePairs = [
|
|
|
{
|
|
|
reg: /<img src=/g,
|
|
|
str: '<img class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f' +
|
|
|
'///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
|
|
|
},
|
|
|
{
|
|
|
reg: /<img border="0" src=/g,
|
|
|
str: '<img border="0" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP' +
|
|
|
'///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
|
|
|
}
|
|
|
];
|
|
|
let content = sizeInfo.productIntroBo.productIntro;
|
|
|
|
|
|
// 图片换成懒加载方式
|
|
|
_.forEach(replacePairs, value => {
|
|
|
content = _.replace(content, value.reg, value.str);
|
|
|
});
|
|
|
details.content += content;
|
|
|
|
|
|
resData.details = details;
|
|
|
}
|
|
|
return resData;
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
setBrandBanner,
|
|
|
setPathNav,
|
|
|
setProductData,
|
|
|
setBrandIntro,
|
|
|
setDescriptionInfo
|
|
|
setDescriptionData,
|
|
|
setMaterialData,
|
|
|
setSizeData,
|
|
|
setDetailData
|
|
|
}; |
...
|
...
|
|