Authored by OF1706

search api

... ... @@ -113,7 +113,7 @@ const serachFilterBrands = (req, res, next) => {
* @return {[type]} [description]
*/
const suggestHistory = (req, res, next) => {
search.getSuggest(req.query).then(result => {
search.getSearchHistory(req.query).then(result => {
if (req.query.json === '1') {
return res.send(result);
... ... @@ -139,7 +139,7 @@ const suggestHistory = (req, res, next) => {
* @return {[type]} [description]
*/
const suggestRecommend = (req, res, next) => {
search.getSuggest(req.query).then(result => {
search.getSearchRecommend(req.query).then(result => {
if (req.query.json === '1') {
return res.send(result);
... ...
... ... @@ -189,7 +189,7 @@ exports.getBrands4Filter = (params) => {
/**
* 搜索 历史记录提示
*/
exports.getSuggestHistory = (params) => {
exports.getSearchHistory = (params) => {
return searchApi.getSuggestHistory(params).then(result => {
let dest = [];
... ... @@ -207,83 +207,15 @@ exports.getSuggestHistory = (params) => {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getSearchData = (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.getSortList(Object.assign({}, searchParams, {msort: '', misort: '', sort: ''})),
searchApi.getProductList(searchParams),
searchApi.getShopList(params)
];
return api.all(apiMethod).then(result => {
let finalResult = {
headerData: Object.assign(result[0].headerData, {
header: true
}),
search: {}
};
// 获取左侧类目数据
if (result[1].code === 200) {
let dps = {};
_.forEach(needParams, (value) => {
if (params[value]) {
dps[value] = params[value];
}
});
exports.getSearchRecommend = (params) => {
return searchApi.getSuggestRecommend(params).then(result => {
let dest = [];
finalResult.search = {
leftContent: searchHandler.handleSortData(result[1].data.sort, dps, params)
};
if (result.code === 200) {
dest = searchHandler.handleSuggest(result.data);
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, params),
finalResult.search.leftContent.sort);
filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
finalResult.search.leftContent.checked);
Object.assign(finalResult.search,
searchHandler.handlePathNavData({total: result[2].data.total }, params, 'search', channel),
{
filters: filters,
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, from: {type: 'search', params: params}}, params)),
latestWalk: 6,
hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
shopEntry: result[3]
});
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.search, 'goods'))};
}
return finalResult;
return dest;
});
};
... ...
... ... @@ -345,6 +345,16 @@
</li>
\{{/data}}
</script>
<script type="text/html" id="search-suggest-recommend">
\{{#data}}
<li>
<a style="display: block;" href="\{{href}}" title="\{{keyword}}"
act="\{{href}}">
<span class="searchvalue">\{{keyword}}</span>
</a>
</li>
\{{/data}}
</script>
</div>
<input id="api-domain" type="hidden" value="{{apiDomain}}">
... ...
... ... @@ -16,7 +16,9 @@ var $head = $('.head-wrapper'),
$logotrans = $head.find('.main-logo'),
$searchSug = $head.find('.search-suggest'),
$searchHistory = $head.find('.search-suggest-history'),
$searchRecommend = $head.find('.search-hot'),
$searchHistoryHbs = $head.find('#search-suggest-history'),
$searchRecommendHbs = $head.find('#search-suggest-recommend')
$goCart = $head.find('.go-cart'),
$myYohoBox = $('#myYohoBox'),
$goodsNum = $goCart.find('.goods-num-tip'),
... ... @@ -899,6 +901,38 @@ $searchKey.keydown(function() {
}
});
/**
* 搜索 热门搜索和默认搜索 api
* @return {[type]} [description]
*/
function searchSuggestRecommend(key) {
var param = {
return_type: 'jsonp',
keyword: key
};
$.getJSON('//search.yohobuy.com/product/search/suggestRecommend?callback=?', param, function(jsonData) {
var searchSuggestRecommendHtml;
if (jsonData.code === 200) {
if (jsonData.data && jsonData.data.length) {
searchSuggestRecommendHtml = handlebars.compile($searchRecommendHbs.html() || '');
$searchRecommend.html(searchSuggestRecommendHtml(jsonData)).show();
} else {
$searchRecommend.hide();
}
}
});
}
/**
* 搜索 热门搜索和默认搜索 dom
* @return {[type]} [description]
*/
$(function(){
searchSuggestRecommend();
});
actionCover();
actionAddKeyWords();
setTimeout(emailUserCertTip, 0);
... ...