Showing
4 changed files
with
25 additions
and
33 deletions
@@ -120,27 +120,29 @@ const searchHistory = (req, res) => { | @@ -120,27 +120,29 @@ const searchHistory = (req, res) => { | ||
120 | 120 | ||
121 | let history = _.trim(req.cookies['_History']); | 121 | let history = _.trim(req.cookies['_History']); |
122 | let q = _.trim(decodeURIComponent(req.query.query) || ''); | 122 | let q = _.trim(decodeURIComponent(req.query.query) || ''); |
123 | + let data = []; | ||
124 | + let list = {}; | ||
125 | + let ResData = {}; | ||
123 | 126 | ||
124 | history = history ? history.split(',') : []; | 127 | history = history ? history.split(',') : []; |
125 | history = _.reject(history, old => old === q ? true : false); | 128 | history = _.reject(history, old => old === q ? true : false); |
126 | 129 | ||
127 | - if(q != ''){ | 130 | + if (q !== '') { |
128 | history.unshift(q); | 131 | history.unshift(q); |
129 | } | 132 | } |
130 | 133 | ||
131 | - res.cookie('_History',_.take(history, 9).join(','), { | 134 | + res.cookie('_History', _.take(history, 9).join(','), { |
132 | domain: config.cookieDomain, | 135 | domain: config.cookieDomain, |
133 | maxAge: 60 * 60 * 24 * 1000 * 30 // 一月 | 136 | maxAge: 60 * 60 * 24 * 1000 * 30 // 一月 |
134 | }); | 137 | }); |
135 | 138 | ||
136 | - let data = []; | ||
137 | _.forEach(history, function(item) { | 139 | _.forEach(history, function(item) { |
138 | - let list = {}; | ||
139 | list['keyword'] = item; | 140 | list['keyword'] = item; |
140 | - list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search') | 141 | + list['href'] = helpers.urlFormat('', {query: list['keyword']}, 'search'); |
141 | data.push(list); | 142 | data.push(list); |
142 | }); | 143 | }); |
143 | - let ResData = {}; | 144 | + |
145 | + | ||
144 | ResData['data'] = data; | 146 | ResData['data'] = data; |
145 | 147 | ||
146 | res.type('text/plain'); | 148 | res.type('text/plain'); |
@@ -156,7 +158,7 @@ const searchHistory = (req, res) => { | @@ -156,7 +158,7 @@ const searchHistory = (req, res) => { | ||
156 | * @return {[type]} [description] | 158 | * @return {[type]} [description] |
157 | */ | 159 | */ |
158 | const searchRecommend = (req, res, next) => { | 160 | const searchRecommend = (req, res, next) => { |
159 | - search.getSearchRecommend(req.yoho.channel,req.query).then(result => { | 161 | + search.getSearchRecommend(req.yoho.channel, req.query).then(result => { |
160 | 162 | ||
161 | if (req.query.json === '1') { | 163 | if (req.query.json === '1') { |
162 | return res.send(result); | 164 | return res.send(result); |
@@ -165,7 +167,7 @@ const searchRecommend = (req, res, next) => { | @@ -165,7 +167,7 @@ const searchRecommend = (req, res, next) => { | ||
165 | let dest = { | 167 | let dest = { |
166 | code: 200, | 168 | code: 200, |
167 | message: 'recommend', | 169 | message: 'recommend', |
168 | - data: result || '', | 170 | + data: result || '' |
169 | }; | 171 | }; |
170 | 172 | ||
171 | res.type('text/javascript'); | 173 | res.type('text/javascript'); |
@@ -424,7 +424,7 @@ const getBrands4Filter = (params) => { | @@ -424,7 +424,7 @@ const getBrands4Filter = (params) => { | ||
424 | * 搜索 热门搜索和默认搜索 | 424 | * 搜索 热门搜索和默认搜索 |
425 | * @return | 425 | * @return |
426 | */ | 426 | */ |
427 | -const getSearchRecommend = (channel,params) => { | 427 | +const getSearchRecommend = (channel, params) => { |
428 | 428 | ||
429 | let finalParams = { | 429 | let finalParams = { |
430 | method: 'app.search.getTerms', | 430 | method: 'app.search.getTerms', |
@@ -192,12 +192,12 @@ exports.getBrands4Filter = (params) => { | @@ -192,12 +192,12 @@ exports.getBrands4Filter = (params) => { | ||
192 | * @param {[type]} origin [description] | 192 | * @param {[type]} origin [description] |
193 | * @return {[type]} [description] | 193 | * @return {[type]} [description] |
194 | */ | 194 | */ |
195 | -exports.getSearchRecommend = (channel,params) => { | ||
196 | - return searchApi.getSearchRecommend(channel,params).then(result => { | 195 | +exports.getSearchRecommend = (channel, params) => { |
196 | + return searchApi.getSearchRecommend(channel, params).then(result => { | ||
197 | 197 | ||
198 | if (result.code === 200) { | 198 | if (result.code === 200) { |
199 | 199 | ||
200 | - let channelNum = 1; | 200 | + let channelNum = 1; // -eslint-disable-line |
201 | 201 | ||
202 | switch (channel) { | 202 | switch (channel) { |
203 | case 'boys': | 203 | case 'boys': |
@@ -217,7 +217,7 @@ exports.getSearchRecommend = (channel,params) => { | @@ -217,7 +217,7 @@ exports.getSearchRecommend = (channel,params) => { | ||
217 | } | 217 | } |
218 | 218 | ||
219 | let resData = { | 219 | let resData = { |
220 | - hotTerms: [], | 220 | + hotTerms: [] |
221 | }; | 221 | }; |
222 | 222 | ||
223 | resData.hotTerms = _.map(result.data.hotTerms, function(value) { | 223 | resData.hotTerms = _.map(result.data.hotTerms, function(value) { |
@@ -226,12 +226,12 @@ exports.getSearchRecommend = (channel,params) => { | @@ -226,12 +226,12 @@ exports.getSearchRecommend = (channel,params) => { | ||
226 | content: value.content, | 226 | content: value.content, |
227 | sort: value.sort, | 227 | sort: value.sort, |
228 | status: value.status, | 228 | status: value.status, |
229 | - type: value.type, | 229 | + type: value.type |
230 | }; | 230 | }; |
231 | }); | 231 | }); |
232 | 232 | ||
233 | return resData; | 233 | return resData; |
234 | - }else{ | 234 | + } else { |
235 | return result; | 235 | return result; |
236 | } | 236 | } |
237 | 237 |
@@ -867,14 +867,16 @@ function actionAddKeyWords() { | @@ -867,14 +867,16 @@ function actionAddKeyWords() { | ||
867 | function searchSuggestHistory() { | 867 | function searchSuggestHistory() { |
868 | 868 | ||
869 | let $queryKey = $('#query-key'); | 869 | let $queryKey = $('#query-key'); |
870 | - $.getJSON('//search.yohobuy.com/product/search/history?query=' + encodeURIComponent($queryKey.val()), function(jsonData) { | 870 | + |
871 | + $.getJSON('//search.yohobuy.com/product/search/history?query=' + | ||
872 | + encodeURIComponent($queryKey.val()), function(jsonData) { | ||
871 | var searchSuggestHistoryHtml; | 873 | var searchSuggestHistoryHtml; |
872 | 874 | ||
873 | searchSuggestHistoryHtml = handlebars.compile($searchHistoryHbs.html() || ''); | 875 | searchSuggestHistoryHtml = handlebars.compile($searchHistoryHbs.html() || ''); |
874 | $searchHistory.html(searchSuggestHistoryHtml(jsonData)).show(); | 876 | $searchHistory.html(searchSuggestHistoryHtml(jsonData)).show(); |
875 | 877 | ||
876 | - $(".search-suggest-title .searchDel").click(function(){ | ||
877 | - window.setCookie('_History','',{domain:'.yohobuy.com'}); | 878 | + $('.search-suggest-title .searchDel').click(function() { |
879 | + window.setCookie('_History', '', {domain: '.yohobuy.com'}); | ||
878 | $(this).closest('.search-suggest-history').hide(); | 880 | $(this).closest('.search-suggest-history').hide(); |
879 | return false; | 881 | return false; |
880 | }); | 882 | }); |
@@ -888,10 +890,11 @@ function searchSuggestHistory() { | @@ -888,10 +890,11 @@ function searchSuggestHistory() { | ||
888 | 890 | ||
889 | $searchKey.keydown(function() { | 891 | $searchKey.keydown(function() { |
890 | 892 | ||
891 | -}).focus(function(e) { | 893 | +}).focus(function() { |
892 | 894 | ||
893 | // if(e.keyCode === 13){ | 895 | // if(e.keyCode === 13){ |
894 | var val = $.trim($(this).val()); | 896 | var val = $.trim($(this).val()); |
897 | + | ||
895 | searchSuggestHistory(); | 898 | searchSuggestHistory(); |
896 | if (val === '') { | 899 | if (val === '') { |
897 | if ($searchHistory && $searchHistory.length) { | 900 | if ($searchHistory && $searchHistory.length) { |
@@ -899,24 +902,11 @@ $searchKey.keydown(function() { | @@ -899,24 +902,11 @@ $searchKey.keydown(function() { | ||
899 | searchSuggestHistory(val); | 902 | searchSuggestHistory(val); |
900 | } | 903 | } |
901 | } | 904 | } |
905 | + | ||
902 | // } | 906 | // } |
903 | 907 | ||
904 | }); | 908 | }); |
905 | 909 | ||
906 | -// $searchKey.keydown(function() { | ||
907 | -// | ||
908 | -// }).focus(function() { | ||
909 | -// | ||
910 | -// var val = $.trim($(this).val()); | ||
911 | -// searchSuggestHistory(); | ||
912 | -// if (val === '') { | ||
913 | -// if ($searchHistory && $searchHistory.length) { | ||
914 | -// val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符 | ||
915 | -// searchSuggestHistory(val); | ||
916 | -// } | ||
917 | -// } | ||
918 | -// }); | ||
919 | - | ||
920 | /** | 910 | /** |
921 | * 搜索 热门搜索和默认搜索 api | 911 | * 搜索 热门搜索和默认搜索 api |
922 | * @return {[type]} [description] | 912 | * @return {[type]} [description] |
-
Please register or login to post a comment