1
|
'use strict';
|
1
|
'use strict';
|
|
|
2
|
+require('../app');
|
2
|
const _ = require('lodash');
|
3
|
const _ = require('lodash');
|
3
|
const camelCase = global.yoho.camelCase;
|
4
|
const camelCase = global.yoho.camelCase;
|
4
|
const helpers = global.yoho.helpers;
|
5
|
const helpers = global.yoho.helpers;
|
|
@@ -10,7 +11,7 @@ const helpers = global.yoho.helpers; |
|
@@ -10,7 +11,7 @@ const helpers = global.yoho.helpers; |
10
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
11
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
11
|
*
|
12
|
*
|
12
|
*/
|
13
|
*/
|
13
|
-const procProductImg = (product, gender, yhChannel) => {
|
14
|
+const _procProductImg = (product, gender, yhChannel) => {
|
14
|
if (gender === '2,3' || gender === '2' || gender === '3' && yhChannel === '2') {
|
15
|
if (gender === '2,3' || gender === '2' || gender === '3' && yhChannel === '2') {
|
15
|
return product.cover2 || product.imagesUrl || product.cover1 || '';
|
16
|
return product.cover2 || product.imagesUrl || product.cover1 || '';
|
16
|
}
|
17
|
}
|
|
@@ -18,6 +19,23 @@ const procProductImg = (product, gender, yhChannel) => { |
|
@@ -18,6 +19,23 @@ const procProductImg = (product, gender, yhChannel) => { |
18
|
return product.cover1 || product.imagesUrl || product.cover2 || '';
|
19
|
return product.cover1 || product.imagesUrl || product.cover2 || '';
|
19
|
};
|
20
|
};
|
20
|
|
21
|
|
|
|
22
|
+/**
|
|
|
23
|
+ * 按照数组中指定字段排序二维数组
|
|
|
24
|
+ *
|
|
|
25
|
+ * @param array list 需要排序的数组
|
|
|
26
|
+ * @param string key 字段名称
|
|
|
27
|
+ * @param boolean 有 desc 时候降序排列,默认为false
|
|
|
28
|
+ */
|
|
|
29
|
+const _sortListByField = (list, key, desc) => {
|
|
|
30
|
+ list = _.toArray(list);
|
|
|
31
|
+ list = list.sort((a, b) => {
|
|
|
32
|
+ if (a[key] && b[key]) {
|
|
|
33
|
+ return (desc ? a[key] > b[key] : a[key] < b[key]) ? -1 : 1;
|
|
|
34
|
+ }
|
|
|
35
|
+ return (desc ? a > b : a < b) ? -1 : 1;
|
|
|
36
|
+ });
|
|
|
37
|
+ return list;
|
|
|
38
|
+};
|
21
|
|
39
|
|
22
|
/**
|
40
|
/**
|
23
|
* 商品搜索商品数据处理
|
41
|
* 商品搜索商品数据处理
|
|
@@ -70,7 +88,7 @@ exports.processProductList = (list, options) => { |
|
@@ -70,7 +88,7 @@ exports.processProductList = (list, options) => { |
70
|
|
88
|
|
71
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
89
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
72
|
if (!flag) {
|
90
|
if (!flag) {
|
73
|
- product.defaultImages = procProductImg(product.goodsList[0], product.gender, options.yh_channel);
|
91
|
+ product.defaultImages = _procProductImg(product.goodsList[0], product.gender, options.yh_channel);
|
74
|
}
|
92
|
}
|
75
|
|
93
|
|
76
|
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
94
|
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
|
@@ -219,6 +237,11 @@ exports.processFilter = (list, options) => { |
|
@@ -219,6 +237,11 @@ exports.processFilter = (list, options) => { |
219
|
name: filtersType[key].name
|
237
|
name: filtersType[key].name
|
220
|
});
|
238
|
});
|
221
|
|
239
|
|
|
|
240
|
+ // 折扣,价格区间,需要排序
|
|
|
241
|
+ if (key === 'discount' || key === 'priceRange') {
|
|
|
242
|
+ item = _sortListByField(item, 'name');
|
|
|
243
|
+ }
|
|
|
244
|
+
|
222
|
_.forEach(item, (sub, index) => {
|
245
|
_.forEach(item, (sub, index) => {
|
223
|
let subs = {};
|
246
|
let subs = {};
|
224
|
|
247
|
|
|
@@ -244,6 +267,5 @@ exports.processFilter = (list, options) => { |
|
@@ -244,6 +267,5 @@ exports.processFilter = (list, options) => { |
244
|
|
267
|
|
245
|
filters.classify[filtersType[key].sortNum] = classify;
|
268
|
filters.classify[filtersType[key].sortNum] = classify;
|
246
|
});
|
269
|
});
|
247
|
-
|
|
|
248
|
return filters;
|
270
|
return filters;
|
249
|
}; |
271
|
}; |