1
|
const api = global.yoho.API;
|
1
|
const api = global.yoho.API;
|
2
|
|
2
|
|
|
|
3
|
+let _getProduct = function(o) {
|
|
|
4
|
+ if (!o) {
|
|
|
5
|
+ return {};
|
|
|
6
|
+ }
|
|
|
7
|
+ return {
|
|
|
8
|
+ small_sort_id: o.small_sort_id,
|
|
|
9
|
+ middle_sort_id: o.middle_sort_id,
|
|
|
10
|
+ max_sort_id: o.max_sort_id,
|
|
|
11
|
+ brand_id: o.brand_id,
|
|
|
12
|
+ brand_domain: o.brand_domain,
|
|
|
13
|
+ brand_name: o.brand_name,
|
|
|
14
|
+ product_id: o.product_id,
|
|
|
15
|
+ product_name: o.product_name,
|
|
|
16
|
+ product_skn: o.product_skn,
|
|
|
17
|
+ market_price: o.market_price,
|
|
|
18
|
+ sales_price: o.sales_price,
|
|
|
19
|
+ cn_alphabet: o.cn_alphabet,
|
|
|
20
|
+ default_images: o.default_images,
|
|
|
21
|
+ goods_id: Array.isArray(o.goods_list) && o.goods_list.length ? o.goods_list[0].goods_id : ''
|
|
|
22
|
+ };
|
|
|
23
|
+};
|
|
|
24
|
+
|
3
|
module.exports = {
|
25
|
module.exports = {
|
4
|
- productLst: function(params) {
|
26
|
+ productLst: function(params, enumParam) {
|
5
|
return api.get('', Object.assign({
|
27
|
return api.get('', Object.assign({
|
6
|
method: 'app.search.newPromotion'
|
28
|
method: 'app.search.newPromotion'
|
7
|
}, params)).then(res => {
|
29
|
}, params)).then(res => {
|
8
|
- var data = [],
|
30
|
+ var data = new Array(Number(params.limit)),
|
9
|
lst = (res.data && res.data.product_list) || [];
|
31
|
lst = (res.data && res.data.product_list) || [];
|
10
|
|
32
|
|
11
|
- lst.forEach(function(o) {
|
|
|
12
|
- data.push({
|
|
|
13
|
- brand_domain: o.brand_domain,
|
|
|
14
|
- brand_name: o.brand_name,
|
|
|
15
|
- product_id: o.product_id,
|
|
|
16
|
- product_name: o.product_name,
|
|
|
17
|
- product_skn: o.product_skn,
|
|
|
18
|
- market_price: o.market_price,
|
|
|
19
|
- sales_price: o.sales_price,
|
|
|
20
|
- cn_alphabet: o.cn_alphabet,
|
|
|
21
|
- default_images: o.default_images,
|
|
|
22
|
- goods_id: Array.isArray(o.goods_list) && o.goods_list.length ? o.goods_list[0].goods_id : ''
|
|
|
23
|
- });
|
|
|
24
|
- });
|
33
|
+ for (var i = 0; i < data.length; i++) {
|
|
|
34
|
+ var o = lst[i] || {};
|
25
|
|
35
|
|
|
|
36
|
+ if (params.specified_sort) {
|
|
|
37
|
+ // 枚举类型
|
|
|
38
|
+ if (enumParam.brands && Number(enumParam.brands[i]) === Number(o.brand_id)) {
|
|
|
39
|
+ data[i] = _getProduct(o);
|
|
|
40
|
+ } else if (enumParam.sorts && Number(enumParam.sorts[i]) === Number(o.small_sort_id)) {
|
|
|
41
|
+ data[i] = _getProduct(o);
|
|
|
42
|
+ } else if (enumParam.misorts && Number(enumParam.misorts[i]) === Number(o.middle_sort_id)) {
|
|
|
43
|
+ data[i] = _getProduct(o);
|
|
|
44
|
+ } else if (enumParam.msorts && Number(enumParam.msorts[i]) === Number(o.max_sort_id)) {
|
|
|
45
|
+ data[i] = _getProduct(o);
|
|
|
46
|
+ } else {
|
|
|
47
|
+ lst.splice(i, 0, {});
|
|
|
48
|
+ data[i] = {};
|
|
|
49
|
+ }
|
|
|
50
|
+ } else {
|
|
|
51
|
+ data[i] = _getProduct(o);
|
|
|
52
|
+ }
|
|
|
53
|
+ }
|
26
|
return data;
|
54
|
return data;
|
27
|
});
|
55
|
});
|
28
|
}
|
56
|
}
|