...
|
...
|
@@ -321,3 +321,100 @@ exports.getSearchLessProduct = (channelNum, uid, udid, page) => { |
|
|
})();
|
|
|
|
|
|
};
|
|
|
|
|
|
const setSearchSuggestData = (result, params, channel) => {
|
|
|
let changeQuery = Object.assign({}, params);
|
|
|
let finalResult = {
|
|
|
headerData: Object.assign(result[0].headerData, {
|
|
|
header: true
|
|
|
}),
|
|
|
search: {}
|
|
|
};
|
|
|
|
|
|
// 获取左侧类目数据
|
|
|
if (result[1].code === 200) {
|
|
|
|
|
|
finalResult.search = {
|
|
|
leftContent: searchHandler.handleSuggestData(result[1].data),
|
|
|
isSearch: true
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 获取商品数据和顶部筛选条件
|
|
|
if (result[2].code === 200) {
|
|
|
|
|
|
// 搜索推荐词,获取对应的参数值
|
|
|
let termsSuggestion = _.get(result[2], 'data.suggestion.terms_suggestion', []);
|
|
|
|
|
|
// 推荐词 获取无商品,首次搜索,通过isChangedQuery做开关
|
|
|
if (result[2].data.isChangedQuery === 'Y') {
|
|
|
Object.assign(changeQuery, {query: termsSuggestion[0]});
|
|
|
}
|
|
|
|
|
|
Object.assign(finalResult.search,
|
|
|
searchHandler.handlePathNavData({total: result[2].data.total }, params, 'search', channel),
|
|
|
{
|
|
|
filters: {},
|
|
|
opts: searchHandler.handleOptsData(changeQuery, result[2].data.total, result[2].data.filter),
|
|
|
totalCount: result[2].data.total,
|
|
|
footPager: searchHandler.handlePagerData(result[2].data.total, changeQuery),
|
|
|
goods: productProcess.processProductList(result[2].data.product_list,
|
|
|
Object.assign({showDiscount: false, from: {type: 'search', params: params}}, params)),
|
|
|
latestWalk: 6,
|
|
|
hasNextPage: searchHandler.handleNextPage(changeQuery, result[2].data.total),
|
|
|
shopEntry: result[3],
|
|
|
name: params.query,
|
|
|
suggest: (termsSuggestion.length !== 0) ? termsSuggestion.slice(0, 3) : false,
|
|
|
changedQuery: result[2].data.isChangedQuery === 'Y',
|
|
|
suggestFirst: finalResult.search.suggestFirst,
|
|
|
suggestSecond: finalResult.search.suggestSecond
|
|
|
});
|
|
|
|
|
|
if (finalResult.search.changedQuery) {
|
|
|
|
|
|
finalResult.search.suggestFirst = finalResult.search.suggest[0];
|
|
|
finalResult.search.suggestSecond = _.slice(termsSuggestion, 1, termsSuggestion.length).splice(0, 3);
|
|
|
}
|
|
|
|
|
|
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};
|
|
|
}
|
|
|
return finalResult;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取搜索建议数据
|
|
|
* @param {[type]} origin [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
exports.getSearchSuggestData = (params, channel) => {
|
|
|
let searchParams = searchHandler.getSearchParams(params);
|
|
|
|
|
|
switch (channel) {
|
|
|
case 'boys':
|
|
|
searchParams.physical_channel = 1;
|
|
|
break;
|
|
|
case 'girls':
|
|
|
searchParams.physical_channel = 2;
|
|
|
break;
|
|
|
case 'kids':
|
|
|
searchParams.physical_channel = 3;
|
|
|
break;
|
|
|
case 'lifestyle':
|
|
|
searchParams.physical_channel = 4;
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
// 调用接口
|
|
|
let apiMethod = [
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
searchApi.getSuggest({keyword: searchParams.query}),
|
|
|
searchApi.getProductList(searchParams, 'fuzzySearch')
|
|
|
];
|
|
|
|
|
|
return api.all(apiMethod).then(result => {
|
|
|
|
|
|
return setSearchSuggestData(result, params, channel);
|
|
|
});
|
|
|
}; |
...
|
...
|
|