|
|
'use strict';
|
|
|
require('../app');
|
|
|
const _ = require('lodash');
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const helpers = global.yoho.helpers;
|
...
|
...
|
@@ -10,7 +11,7 @@ const helpers = global.yoho.helpers; |
|
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
|
|
*
|
|
|
*/
|
|
|
const procProductImg = (product, gender, yhChannel) => {
|
|
|
const _procProductImg = (product, gender, yhChannel) => {
|
|
|
if (gender === '2,3' || gender === '2' || gender === '3' && yhChannel === '2') {
|
|
|
return product.cover2 || product.imagesUrl || product.cover1 || '';
|
|
|
}
|
...
|
...
|
@@ -18,6 +19,23 @@ const procProductImg = (product, gender, yhChannel) => { |
|
|
return product.cover1 || product.imagesUrl || product.cover2 || '';
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 按照数组中指定字段排序二维数组
|
|
|
*
|
|
|
* @param array list 需要排序的数组
|
|
|
* @param string key 字段名称
|
|
|
* @param boolean 有 desc 时候降序排列,默认为false
|
|
|
*/
|
|
|
const _sortListByField = (list, key, desc) => {
|
|
|
list = _.toArray(list);
|
|
|
list = list.sort((a, b) => {
|
|
|
if (a[key] && b[key]) {
|
|
|
return (desc ? a[key] > b[key] : a[key] < b[key]) ? -1 : 1;
|
|
|
}
|
|
|
return (desc ? a > b : a < b) ? -1 : 1;
|
|
|
});
|
|
|
return list;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 商品搜索商品数据处理
|
...
|
...
|
@@ -70,7 +88,7 @@ exports.processProductList = (list, options) => { |
|
|
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!flag) {
|
|
|
product.defaultImages = procProductImg(product.goodsList[0], product.gender, options.yh_channel);
|
|
|
product.defaultImages = _procProductImg(product.goodsList[0], product.gender, options.yh_channel);
|
|
|
}
|
|
|
|
|
|
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
...
|
...
|
@@ -219,6 +237,11 @@ exports.processFilter = (list, options) => { |
|
|
name: filtersType[key].name
|
|
|
});
|
|
|
|
|
|
// 折扣,价格区间,需要排序
|
|
|
if (key === 'discount' || key === 'priceRange') {
|
|
|
item = _sortListByField(item, 'name');
|
|
|
}
|
|
|
|
|
|
_.forEach(item, (sub, index) => {
|
|
|
let subs = {};
|
|
|
|
...
|
...
|
@@ -244,6 +267,5 @@ exports.processFilter = (list, options) => { |
|
|
|
|
|
filters.classify[filtersType[key].sortNum] = classify;
|
|
|
});
|
|
|
|
|
|
return filters;
|
|
|
}; |
...
|
...
|
|