Authored by OF1706

suggetList

... ... @@ -9,6 +9,8 @@ const mRoot = '../models';
const search = require(`${mRoot}/search`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const utils = '../../../utils';
const stringCode = require(`${utils}/string-code`);
const config = global.yoho.config;
... ... @@ -163,12 +165,44 @@ const searchLessRecommend = (req, res, next) => {
};
/**
* 搜索推荐列表页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
const suggestIndex = (req, res, next) => {
let params = req.params.id || '';
let resData = {
title: '潮流商品搜索 | YOHO!BUY 有货',
keywords: 'Yoho! 有货,潮流,时尚,流行,购物,B2C,正品,购物网站,网上购物,货到付款,' +
'品牌服饰,男士护肤,黑框眼镜,匡威,板鞋,i.t,izzue,5cm,eastpak,vans,lylescott,g-shock,' +
'new balance,lacoste,melissa,casio,卡西欧手表,舒雅,jasonwood,odm,AAAA,香港购物,日本潮流',
description: '潮流商品搜索,上衣,衬衫,TEE,卫衣,冲锋衣,风衣,羽绒服,裤子,休闲鞋,板鞋,配饰,复古眼镜'
};
// return search.getSearchSuggestData{query: stringCode.hexToUtf8(params)},
return search.getSearchSuggestData({query: '卫衣'},
req.yoho.channel).then(result => {
Object.assign(resData, result);
if (!_.get(resData, 'search.goods') || !_.get(resData, 'search.goods').length) {
_.set(resData, 'search.keyWord', req.query.query);
return res.render('search/no-result', resData);
}
res.render('search/index', resData);
}).catch(next);
};
module.exports = {
index,
suggest,
suggest4Old,
searchFilterBrands,
searchHistory, // 搜索历史记录
searchLessRecommend
searchLessRecommend,
suggestIndex
};
... ...
... ... @@ -372,6 +372,7 @@ const getShopList = params => {
* @return
*/
const getSuggest = (params) => {
let finalParams = {
method: 'app.search.fuzzy',
keyword: params.keyword || ''
... ...
... ... @@ -16,6 +16,8 @@ const indexUrl = {
kids: helpers.urlFormat('/kids'),
lifestyle: helpers.urlFormat('/lifestyle')
};
const utils = '../../../utils';
const stringCode = require(`${utils}/string-code`);
// 打折、新品、限量
const checksName = {
... ... @@ -1685,8 +1687,6 @@ exports.getSearchParams = params => {
});
}
/** 查询参数再处理 **/
// 对可能有中文的情况进行处理
if (params.query) {
... ... @@ -1732,5 +1732,41 @@ exports.handleBrandShopCoupons = (data, params) => {
return false;
};
/**
* 处理页面左侧分类筛选数据
* @param origin 分类原始数据,一般是接口返回数据中的 group_sort 字段
* @param params 当前 URL 中已有的参数
* @param extra 可以任意传值用来处理特殊情况
* @param {string} [baseUrl] 需要跳转非当前页面传的相对路径(可不传,默认为空字符串)
* @returns {{}}
*/
exports.handleSuggestData = (origin) => {
let leftContent = {};
let list = [];
let all = [{
name: '全部推荐'
}];
_.forEach(origin, value => {
let category = {
childList: [
{
name: `${value.keyword}`,
href: helpers.urlFormat(`/so/${stringCode.utf8ToHex(value.keyword)}.html`, null, 'www')
}
]
};
list.push(category);
});
leftContent.allSuggest = {all: all, list: list};
return leftContent;
};
... ...
... ... @@ -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);
});
};
... ...
... ... @@ -101,6 +101,7 @@ router.get('/search/suggest', search.suggest); // 搜索提示
router.get('/api/suggest', search.suggest4Old);
router.get('/search/history', search.searchHistory); // 搜索历史提示
router.get('/search/less/recommend', search.searchLessRecommend);// 搜索少或无 有可能喜欢
router.get('/search/suggestItem/:id', gbk2utf, search.suggestIndex);
// 商品分类列表页
router.get('/list/index', gbk2utf, list.index);
... ...
<div class="filter-box">
{{# checkedConditions}}
{{# checkedConditions}}
<div class="filter-box">
{{#if conditions}}
<div class="checked-conditions section">
<span class="title">已选条件:</span>
... ... @@ -268,5 +267,6 @@
</div>
</div>
</div>
{{/if}}
</div>
</div>
{{/if}}
... ...
... ... @@ -85,6 +85,24 @@
{{/each}}
</ul>
{{/ picLink}}
{{!-- 搜索推荐--}}
{{# allSuggest}}
<div class="sort-container">
{{# list}}
<ul class="sort-child-list suggest-list">
{{#each childList}}
<li>
<a href="{{href}}" title="{{name}}">
{{name}}
</a>
</li>
{{/each}}
</ul>
{{/ list}}
</div>
{{/ allSuggest}}
{{/ leftContent}}
{{# brandShopAd}}
... ...
... ... @@ -2,6 +2,7 @@
{{# filters}}
{{> product/filter-box}}
{{/ filters}}
{{log filters}}
{{#if phrase}}
<div class="phrase">
... ...
... ... @@ -63,7 +63,8 @@
.sort-child-list {
display: none;
&.new-sale {
&.new-sale,
&.suggest-list {
display: block;
}
... ...
'use strict';
const utf8ToHex = (string) => {
var buf = new Buffer(string, 'utf8');
return buf.toString('hex');
};
const hexToUtf8 = (string) => {
let buf = new Buffer(string, 'hex');
return buf.toString('utf8');
};
module.exports = {
utf8ToHex,
hexToUtf8
};
... ...