list.js
4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* @Author: sefon
* @Date: 2016-07-24 11:48:22
*/
'use strict';
const utils = '../../../utils';
const api = global.yoho.API;
const searchApi = require('./search-api');
const headerModel = require('../../../doraemon/models/header');
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('./search-handler');
// 搜索分类信息需要的参数
const positionId = 10;
// 获取分类左侧广告id
const sortAdsId = 79;
/**
* 获取商品分类列表数据
*/
exports.getListData = (params) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(),
searchApi.getSortList(),
searchApi.getProductList(params)
];
// 搜索分类介绍和广告
if (params.msort && params.misort) {
let IntroParams = {
max_sort_id: params.msort,
middle_sort_id: params.misort,
gender: params.gender || '1,3'
};
apiMethod.push(searchApi.getSortIntro(Object.assign(IntroParams, {position_id: positionId})));
apiMethod.push(searchApi.getSortAds(Object.assign(IntroParams, {position_id: sortAdsId})));
}
return api.all(apiMethod).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true
}),
list: {
leftContent: {}
}
};
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = {
leftContent: searchHandler.handleSortData(result[1].data.sort, params),
pathNav: searchHandler.handlePathNavData(result[1].data.sort, params, 'sort')
};
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
Object.assign(finalResult.list, {
filters: searchHandler.handleFilterData(result[2].data.filter, params),
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false}, params))
});
}
// 分类介绍
if (result[3] && result[3].code === 200) {
finalResult.list.sortIntro = searchHandler.handleSortIntro(result[3].data);
}
// 分类广告
if (result[4] && result[4].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleSortAds(result[4].data));
}
return finalResult;
});
};
/**
* 获取新品到着数据
*/
exports.getListNewData = (params) => {
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(),
searchApi.getSortList(),
searchApi.getProductList(params),
searchApi.getWeekNew(params)
];
return api.all(apiMethod).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true
}),
list: {
leftContent: {}
}
};
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = {
leftContent: searchHandler.handleSortData(result[1].data.sort, params),
pathNav: searchHandler.handlePathNavData(result[1].data.sort, params, 'new')
};
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
Object.assign(finalResult.list, {
filters: searchHandler.handleFilterData(result[2].data.filter, params),
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false}, params))
});
}
// 新品上架
if (result[3] && result[3].code === 200) {
Object.assign(finalResult.list.leftContent, searchHandler.handleWeekNew(result[3].data, params));
}
return finalResult;
});
};