|
|
'use strict';
|
|
|
const path = require('path');
|
|
|
const _ = require('lodash');
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const utilsPath = path.join(global.utils, '/constant');
|
|
|
const genderMap = require(utilsPath).genderMap;
|
|
|
|
|
|
/**
|
|
|
* 根据性别来决定 默认图片获取字段 如果是 2、3
|
|
|
*
|
|
|
* 则优先从cover2 --》 cover1 -- 》 images_url
|
|
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
|
|
*
|
|
|
*/
|
|
|
const _procProductImg = (product, gender, yhChannel) => {
|
|
|
if (gender === '2,3' || gender === '2' || gender === '3' && yhChannel === '2') {
|
|
|
return product.cover2 || product.imagesUrl || product.cover1 || '';
|
|
|
const _procProductImg = (product, genderVal) => {
|
|
|
let defaultImages;
|
|
|
|
|
|
switch (genderVal) {
|
|
|
case genderMap.men:
|
|
|
defaultImages = product.cover1 || product.imagesUrl;
|
|
|
break;
|
|
|
case genderMap.women:
|
|
|
defaultImages = product.cover2 || product.imagesUrl;
|
|
|
break;
|
|
|
default:
|
|
|
defaultImages = product.imagesUrl || product.cover1 || product.cover2;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return product.cover1 || product.imagesUrl || product.cover2 || '';
|
|
|
defaultImages || (defaultImages = '');
|
|
|
|
|
|
return defaultImages;
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -32,11 +43,13 @@ module.exports = (list, options) => { |
|
|
height: 388,
|
|
|
isApp: false,
|
|
|
showPoint: true,
|
|
|
gender: '2,3',
|
|
|
gender: '',
|
|
|
yhChannel: ''
|
|
|
}, options);
|
|
|
list = camelCase(list);
|
|
|
|
|
|
let genderVal = options.gender.split(',')[0];
|
|
|
|
|
|
_.forEach(list, (product) => {
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!product.productId || !product.goodsList.length) {
|
...
|
...
|
@@ -59,18 +72,17 @@ module.exports = (list, options) => { |
|
|
// 如果设置了默认图片,就取默认的图片
|
|
|
_.forEach(product.goodsList, (goods) => {
|
|
|
if (flag) {
|
|
|
return;
|
|
|
return false;
|
|
|
}
|
|
|
if (goods.isDefault === 'Y') {
|
|
|
// product.defaultImages = procProductImg(goods);
|
|
|
product.defaultImages = product.defaultImages;
|
|
|
product.defaultImages = _procProductImg(goods, genderVal);
|
|
|
flag = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!flag) {
|
|
|
product.defaultImages = _procProductImg(product.goodsList[0], product.gender, options.yhChannel);
|
|
|
product.defaultImages = _procProductImg(product.goodsList[0], genderVal);
|
|
|
}
|
|
|
|
|
|
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
...
|
...
|
|