Authored by yyq

Merge branch 'release/newSearch' of git.yoho.cn:fe/yohobuy-node into release/newSearch

@@ -47,11 +47,14 @@ const _getGender = (channel) => { @@ -47,11 +47,14 @@ const _getGender = (channel) => {
47 * 获取商品分类列表数据 47 * 获取商品分类列表数据
48 */ 48 */
49 exports.getListData = (params, channel) => { 49 exports.getListData = (params, channel) => {
  50 +
  51 + let searchParams = searchHandler.getSearchParams(params);
  52 +
50 // 调用接口 53 // 调用接口
51 let apiMethod = [ 54 let apiMethod = [
52 headerModel.requestHeaderData(channel), 55 headerModel.requestHeaderData(channel),
53 - searchApi.getSortList(),  
54 - searchApi.getProductList(params) 56 + searchApi.getSortList(params),
  57 + searchApi.getProductList(searchParams)
55 ]; 58 ];
56 59
57 // 搜索分类介绍和广告 60 // 搜索分类介绍和广告
@@ -93,6 +96,7 @@ exports.getListData = (params, channel) => { @@ -93,6 +96,7 @@ exports.getListData = (params, channel) => {
93 footPager: searchHandler.handlePagerData(result[2].data.total, params), 96 footPager: searchHandler.handlePagerData(result[2].data.total, params),
94 goods: productProcess.processProductList(result[2].data.product_list, 97 goods: productProcess.processProductList(result[2].data.product_list,
95 Object.assign({showDiscount: false}, params)), 98 Object.assign({showDiscount: false}, params)),
  99 + hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
96 100
97 // 最近浏览记录 101 // 最近浏览记录
98 latestWalk: 7 102 latestWalk: 7
@@ -124,11 +128,13 @@ exports.getListData = (params, channel) => { @@ -124,11 +128,13 @@ exports.getListData = (params, channel) => {
124 */ 128 */
125 exports.getListNewData = (params, channel) => { 129 exports.getListNewData = (params, channel) => {
126 130
  131 + let searchParams = searchHandler.getSearchParams(params);
  132 +
127 // 调用接口 133 // 调用接口
128 let apiMethod = [ 134 let apiMethod = [
129 headerModel.requestHeaderData(channel), 135 headerModel.requestHeaderData(channel),
130 - searchApi.getSortList(),  
131 - searchApi.getProductList(Object.assign({new: 'Y'}, params)), 136 + searchApi.getSortList(searchParams),
  137 + searchApi.getProductList(Object.assign({new: 'Y'}, searchParams)),
132 searchApi.getWeekNew(params) 138 searchApi.getWeekNew(params)
133 ]; 139 ];
134 140
@@ -159,6 +165,7 @@ exports.getListNewData = (params, channel) => { @@ -159,6 +165,7 @@ exports.getListNewData = (params, channel) => {
159 footPager: searchHandler.handlePagerData(result[2].data.total, params), 165 footPager: searchHandler.handlePagerData(result[2].data.total, params),
160 goods: productProcess.processProductList(result[2].data.product_list, 166 goods: productProcess.processProductList(result[2].data.product_list,
161 Object.assign({showDiscount: false}, params)), 167 Object.assign({showDiscount: false}, params)),
  168 + hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
162 169
163 // 最近浏览记录 170 // 最近浏览记录
164 latestWalk: 7 171 latestWalk: 7
@@ -211,14 +218,16 @@ exports.getBrandInfo = (params) => { @@ -211,14 +218,16 @@ exports.getBrandInfo = (params) => {
211 */ 218 */
212 exports.getBrandData = (params, extra, channel) => { 219 exports.getBrandData = (params, extra, channel) => {
213 220
  221 + let searchParams = searchHandler.getSearchParams(params);
  222 +
214 // 设置品牌默认排序方式 223 // 设置品牌默认排序方式
215 let order = params.order || 'b_w_desc'; 224 let order = params.order || 'b_w_desc';
216 225
217 // 调用接口 226 // 调用接口
218 let apiMethod = [ 227 let apiMethod = [
219 headerModel.requestHeaderData(channel), 228 headerModel.requestHeaderData(channel),
220 - searchApi.getSortList({brand: extra.brandId}),  
221 - searchApi.getProductList(Object.assign({order: order, brand: extra.brandId}, params)) 229 + searchApi.getSortList(Object.assign({}, params, {brand: extra.brandId})),
  230 + searchApi.getProductList(Object.assign({order: order, brand: extra.brandId}, searchParams))
222 231
223 ]; 232 ];
224 233
@@ -250,6 +259,7 @@ exports.getBrandData = (params, extra, channel) => { @@ -250,6 +259,7 @@ exports.getBrandData = (params, extra, channel) => {
250 footPager: searchHandler.handlePagerData(result[2].data.total, params), 259 footPager: searchHandler.handlePagerData(result[2].data.total, params),
251 goods: productProcess.processProductList(result[2].data.product_list, 260 goods: productProcess.processProductList(result[2].data.product_list,
252 Object.assign({showDiscount: false}, params)), 261 Object.assign({showDiscount: false}, params)),
  262 + hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
253 263
254 // 最近浏览记录 264 // 最近浏览记录
255 latestWalk: 7 265 latestWalk: 7
@@ -923,7 +923,7 @@ exports.handlePathNavData = (data, params, page) => { @@ -923,7 +923,7 @@ exports.handlePathNavData = (data, params, page) => {
923 * @param {[type]} params 筛选条件 923 * @param {[type]} params 筛选条件
924 * @return {[type]} [description] 924 * @return {[type]} [description]
925 */ 925 */
926 -exports.handlePagerData = (total, params) => { 926 +exports.handlePagerData = (total, params, noNextBtn) => {
927 let dest = { 927 let dest = {
928 prePage: { 928 prePage: {
929 url: '' 929 url: ''
@@ -934,8 +934,8 @@ exports.handlePagerData = (total, params) => { @@ -934,8 +934,8 @@ exports.handlePagerData = (total, params) => {
934 pages: [] 934 pages: []
935 }; 935 };
936 936
937 - let currentPage = parseInt((_.isEmpty(params.page) ? 1 : params.page), 10); // 当前页  
938 - let perPageCount = parseInt((_.isEmpty(params.limit) ? 60 : params.limit), 10); // 每页商品数 937 + let currentPage = parseInt(_.get(params, 'page', 1), 10); // 当前页
  938 + let perPageCount = parseInt(_.get(params, 'limit', true === noNextBtn ? 60 : 59), 10); // 每页商品数
939 let totalPage = parseInt(total / perPageCount, 10) + 1; // 总页数 939 let totalPage = parseInt(total / perPageCount, 10) + 1; // 总页数
940 940
941 if (currentPage === 1) { 941 if (currentPage === 1) {
@@ -1332,8 +1332,10 @@ exports.getCriteo = (glist) => { @@ -1332,8 +1332,10 @@ exports.getCriteo = (glist) => {
1332 if (glist) { 1332 if (glist) {
1333 _.forEach(glist, (val) => { 1333 _.forEach(glist, (val) => {
1334 1334
1335 - if (sknArr.length < 3 && val && val.product_skn) {  
1336 - sknArr.push(val.product_skn); 1335 + if (sknArr.length < 3) {
  1336 + if (val && val.product_skn) {
  1337 + sknArr.push(val.product_skn);
  1338 + }
1337 } else { 1339 } else {
1338 return false; 1340 return false;
1339 } 1341 }
@@ -1342,3 +1344,41 @@ exports.getCriteo = (glist) => { @@ -1342,3 +1344,41 @@ exports.getCriteo = (glist) => {
1342 1344
1343 return sknArr; 1345 return sknArr;
1344 }; 1346 };
  1347 +
  1348 +// handlePagerData
  1349 +exports.getSearchParams = params => {
  1350 +
  1351 + let mlimit = 59;
  1352 +
  1353 + if (params && params.limit) {
  1354 +
  1355 + let olimit = parseInt(params.limit, 10);
  1356 +
  1357 + switch (olimit) {
  1358 + case 100:
  1359 + mlimit = 99;
  1360 + break;
  1361 + case 200:
  1362 + mlimit = 199;
  1363 + break;
  1364 + default:
  1365 + mlimit = 59;
  1366 + }
  1367 + }
  1368 +
  1369 + /** 处理页面数据 **/
  1370 + let nparams = {
  1371 + limit: mlimit
  1372 + };
  1373 +
  1374 + if (params && params.price) {
  1375 + let mp = params.price.split(',');
  1376 + let nmp = [];
  1377 +
  1378 + nmp[0] = (mp && mp[0]) || 0;
  1379 + nmp[1] = (mp && mp[1]) || 99999;
  1380 + nparams.price = nmp.join(',');
  1381 + }
  1382 +
  1383 + return Object.assign({}, params, nparams);
  1384 +};
@@ -18,25 +18,14 @@ const _ = require('lodash'); @@ -18,25 +18,14 @@ const _ = require('lodash');
18 * @return {[type]} [description] 18 * @return {[type]} [description]
19 */ 19 */
20 exports.getSearchData = (params, channel) => { 20 exports.getSearchData = (params, channel) => {
21 - let mlimit = params && params.limit && params.limit > 0 ? params.limit - 1 : 59;  
22 21
23 - /** 处理页面数据 **/  
24 - let nparams = {};  
25 -  
26 - if (params && params.price) {  
27 - let mp = params.price.split(',');  
28 - let nmp = [];  
29 -  
30 - nmp[0] = (mp && mp[0]) || 0;  
31 - nmp[1] = (mp && mp[1]) || 99999;  
32 - nparams.price = nmp.join(',');  
33 - } 22 + let searchParams = searchHandler.getSearchParams(params);
34 23
35 // 调用接口 24 // 调用接口
36 let apiMethod = [ 25 let apiMethod = [
37 headerModel.requestHeaderData(channel), 26 headerModel.requestHeaderData(channel),
38 - searchApi.getSortList(Object.assign({}, params, nparams, {msort: '', misort: ''})),  
39 - searchApi.getProductList(Object.assign({}, params, {limit: mlimit}, nparams)), 27 + searchApi.getSortList(Object.assign({}, searchParams, {msort: '', misort: ''})),
  28 + searchApi.getProductList(searchParams),
40 searchApi.getShopList(params) 29 searchApi.getShopList(params)
41 ]; 30 ];
42 31