search.js
1.75 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
/**
* search
* @Author: sefon 2016-7-12 16:31:56
*/
'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');
/**
* 获取搜索数据
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getSearchData = (params) => {
return api.all([
headerModel.requestHeaderData(),
searchApi.getSortList(),
searchApi.getProductList(params)
]).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true
}),
search: {}
};
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.search = {
leftContent: searchHandler.handleSortData(result[1].data.filter.group_sort, params),
pathNav: searchHandler.handlePathNavData({total: result[1].data.total }, params, 'search')
};
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
Object.assign(finalResult.search, {
filters: searchHandler.handleFilterData(result[2].data.filter, params),
opts: searchHandler.handleOptsData(params, result[2].data.total),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list, {showDiscount: false})
});
}
return finalResult;
});
};