search.js
2.94 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
/**
* 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, channel) => {
let mlimit = params && params.limit && params.limit > 0 ? params.limit - 1 : 59;
/** 处理页面数据 **/
let nparams = {};
if (params && params.price) {
let mp = params.price.split(',');
let nmp = [];
nmp[0] = (mp && mp[0]) || 0;
nmp[1] = (mp && mp[1]) || 99999;
nparams.price = nmp.join(',');
}
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList(Object.assign({}, params, nparams, {msort: '', misort: ''})),
searchApi.getProductList(Object.assign({}, params, {limit: mlimit}, nparams)),
searchApi.getShopList(params)
];
// 搜索店铺
/* if (params.query) {
apiMethod.push(searchApi.getBrandShop(params.query));
}*/
return api.all(apiMethod).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.sort, params)
};
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
Object.assign(
finalResult.search, searchHandler.handlePathNavData({total: result[2].data.total }, params, 'search'),
{
filters: searchHandler.handleFilterDataAll(result[2].data, 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)),
latestWalk: 7,
hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
shopEntry: result[3]
});
}
return finalResult;
});
};
/**
* 搜索提示
*/
exports.getSuggest = (params) => {
return searchApi.getSuggest(params).then(result => {
let dest = [];
if (result.code === 200) {
dest = searchHandler.handleSuggest(result.data);
}
return dest;
});
};