Showing
4 changed files
with
43 additions
and
29 deletions
@@ -14,6 +14,7 @@ const api = global.yoho.API; | @@ -14,6 +14,7 @@ const api = global.yoho.API; | ||
14 | const cache = require('memory-cache'); | 14 | const cache = require('memory-cache'); |
15 | const helpers = global.yoho.helpers; | 15 | const helpers = global.yoho.helpers; |
16 | const redis = global.yoho.redis; | 16 | const redis = global.yoho.redis; |
17 | +const co = require('bluebird').coroutine; | ||
17 | 18 | ||
18 | /** | 19 | /** |
19 | * 封面图 | 20 | * 封面图 |
@@ -309,25 +310,45 @@ const getSearchData = (params) => { | @@ -309,25 +310,45 @@ const getSearchData = (params) => { | ||
309 | }; | 310 | }; |
310 | 311 | ||
311 | /** | 312 | /** |
313 | + * 搜索品牌的商品 | ||
314 | + */ | ||
315 | +const getBrandGoods = (params) => { | ||
316 | + let finalParams = { | ||
317 | + method: 'app.search.brand', | ||
318 | + }; | ||
319 | + | ||
320 | + finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params)); | ||
321 | + return api.get('', finalParams); | ||
322 | +}; | ||
323 | + | ||
324 | +/** | ||
312 | * 获取筛选数据 | 325 | * 获取筛选数据 |
313 | - * @param {[object]} params | ||
314 | - * @return {[array]} | ||
315 | */ | 326 | */ |
316 | const getFilterData = (params) => { | 327 | const getFilterData = (params) => { |
317 | - return _searchGoods(params).then((result) => { | ||
318 | - if (result && result.code === 200) { | ||
319 | - return productProcess.processFilter(result.data.filter || []); | 328 | + return co(function* () { |
329 | + let filterDataResult = {}; | ||
330 | + | ||
331 | + if (params.isBrandShop === 'Y') { | ||
332 | + filterDataResult = yield getBrandGoods(params); | ||
333 | + } else { | ||
334 | + filterDataResult = yield _searchGoods(params); | ||
335 | + } | ||
336 | + | ||
337 | + let filterData = _.get(filterDataResult, 'data.filter', []); | ||
338 | + | ||
339 | + if (filterData) { | ||
340 | + return productProcess.processFilter(filterData); | ||
320 | } else { | 341 | } else { |
321 | - logger.error('get filter data api return code is not 200'); | ||
322 | return []; | 342 | return []; |
323 | } | 343 | } |
324 | - }); | 344 | + })(); |
325 | }; | 345 | }; |
326 | 346 | ||
327 | /** | 347 | /** |
328 | * 获取筛选数据 | 348 | * 获取筛选数据 |
329 | * @param {[object]} params | 349 | * @param {[object]} params |
330 | * @return {[array]} | 350 | * @return {[array]} |
351 | + * TODO 这个可能不用了,待确定 | ||
331 | */ | 352 | */ |
332 | const getFilterSearchData = (params) => { | 353 | const getFilterSearchData = (params) => { |
333 | return _searchGoods(params).then((result) => { | 354 | return _searchGoods(params).then((result) => { |
@@ -571,18 +592,6 @@ const getSearchKeywordDataById = (id, params, uid) => { | @@ -571,18 +592,6 @@ const getSearchKeywordDataById = (id, params, uid) => { | ||
571 | }); | 592 | }); |
572 | }; | 593 | }; |
573 | 594 | ||
574 | -/** | ||
575 | - * 搜索品牌的商品 | ||
576 | - */ | ||
577 | -const getBrandGoods = (params) => { | ||
578 | - let finalParams = { | ||
579 | - method: 'app.search.brand', | ||
580 | - }; | ||
581 | - | ||
582 | - finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params)); | ||
583 | - return api.get('', finalParams); | ||
584 | -}; | ||
585 | - | ||
586 | module.exports = { | 595 | module.exports = { |
587 | getSearchData, | 596 | getSearchData, |
588 | getFilterData, | 597 | getFilterData, |
@@ -4,6 +4,9 @@ let ProductListWithFilter = require('product/product-list-with-filter'); | @@ -4,6 +4,9 @@ let ProductListWithFilter = require('product/product-list-with-filter'); | ||
4 | let brandId = $('#brandId').val(); | 4 | let brandId = $('#brandId').val(); |
5 | 5 | ||
6 | let productListWithFilterModel = | 6 | let productListWithFilterModel = |
7 | - new ProductListWithFilter({brand_id: brandId}, 'product/search/brand/goods'); | 7 | + new ProductListWithFilter({ |
8 | + brand_id: brandId, | ||
9 | + isBrandShop: 'Y' // 传给 filter,表明调用哪个接口获取筛选面板的数据 | ||
10 | + }, 'product/search/brand/goods'); | ||
8 | 11 | ||
9 | productListWithFilterModel.getFilter(); | 12 | productListWithFilterModel.getFilter(); |
@@ -14,7 +14,9 @@ const lazyLoad = require('yoho-jquery-lazyload'); | @@ -14,7 +14,9 @@ const lazyLoad = require('yoho-jquery-lazyload'); | ||
14 | 14 | ||
15 | class ProductListWithFilter { | 15 | class ProductListWithFilter { |
16 | constructor(filterParams, searchUrl) { | 16 | constructor(filterParams, searchUrl) { |
17 | - this.searchUrl = searchUrl || 'product/search/search'; | 17 | + this.filterParams = filterParams; |
18 | + this.searchUrl = location.protocol + '//m.yohobuy.com/' + (searchUrl || 'product/search/search'); | ||
19 | + this.filterUrl = location.protocol + '//m.yohobuy.com/product/search/filter'; | ||
18 | this.view = { | 20 | this.view = { |
19 | goodsContainer: $('#goods-container'), | 21 | goodsContainer: $('#goods-container'), |
20 | container: $('#goods-container').children('.default-goods'), | 22 | container: $('#goods-container').children('.default-goods'), |
@@ -53,7 +55,7 @@ class ProductListWithFilter { | @@ -53,7 +55,7 @@ class ProductListWithFilter { | ||
53 | }; | 55 | }; |
54 | this.beforeScroll = document.body.scrollTop; // 滚动前位置记录 | 56 | this.beforeScroll = document.body.scrollTop; // 滚动前位置记录 |
55 | this.navType = 'default'; // 目前激活的导航页面 | 57 | this.navType = 'default'; // 目前激活的导航页面 |
56 | - this.defaultOpt = Object.assign({}, this.navInfo.default, filterParams); // 默认参数 | 58 | + this.defaultOpt = Object.assign({}, this.navInfo.default, this.filterParams); // 默认参数 |
57 | this.onSearching = false; // 是否正在搜索 | 59 | this.onSearching = false; // 是否正在搜索 |
58 | this.isScrollLoad = false; // 是否是滚动加载 | 60 | this.isScrollLoad = false; // 是否是滚动加载 |
59 | this.page = 1; // 页码 | 61 | this.page = 1; // 页码 |
@@ -122,7 +124,7 @@ class ProductListWithFilter { | @@ -122,7 +124,7 @@ class ProductListWithFilter { | ||
122 | 124 | ||
123 | $.ajax({ | 125 | $.ajax({ |
124 | type: 'GET', | 126 | type: 'GET', |
125 | - url: `${location.protocol}//m.yohobuy.com/${this.searchUrl}`, | 127 | + url: this.searchUrl, |
126 | data: this.defaultOpt, | 128 | data: this.defaultOpt, |
127 | xhrFields: { | 129 | xhrFields: { |
128 | withCredentials: true | 130 | withCredentials: true |
@@ -186,8 +188,8 @@ class ProductListWithFilter { | @@ -186,8 +188,8 @@ class ProductListWithFilter { | ||
186 | getFilter() { | 188 | getFilter() { |
187 | $.ajax({ | 189 | $.ajax({ |
188 | type: 'GET', | 190 | type: 'GET', |
189 | - url: location.protocol + '//m.yohobuy.com/product/search/filter', | ||
190 | - data: this.defaultOpt, | 191 | + url: this.filterUrl, |
192 | + data: this.filterParams, | ||
191 | success: (data) => { | 193 | success: (data) => { |
192 | if (!data) { | 194 | if (!data) { |
193 | return false; | 195 | return false; |
@@ -128,15 +128,15 @@ const getSearchParamsWithoutMethod = (params) => { | @@ -128,15 +128,15 @@ const getSearchParamsWithoutMethod = (params) => { | ||
128 | finalParams.gender = params.gender; | 128 | finalParams.gender = params.gender; |
129 | } | 129 | } |
130 | 130 | ||
131 | - if (params.color) { | 131 | + if (params.color && params.color !== '0') { |
132 | finalParams.color = params.color; | 132 | finalParams.color = params.color; |
133 | } | 133 | } |
134 | 134 | ||
135 | - if (params.price) { | 135 | + if (params.price && params.price !== '0') { |
136 | finalParams.price = params.price; | 136 | finalParams.price = params.price; |
137 | } | 137 | } |
138 | 138 | ||
139 | - if (params.size) { | 139 | + if (params.size && params.size !== '0') { |
140 | finalParams.size = params.size; | 140 | finalParams.size = params.size; |
141 | } | 141 | } |
142 | 142 | ||
@@ -144,7 +144,7 @@ const getSearchParamsWithoutMethod = (params) => { | @@ -144,7 +144,7 @@ const getSearchParamsWithoutMethod = (params) => { | ||
144 | finalParams.p_d = params.p_d; | 144 | finalParams.p_d = params.p_d; |
145 | } | 145 | } |
146 | 146 | ||
147 | - if (params.sort) { | 147 | + if (params.sort && params.sort !== '0') { |
148 | finalParams.sort = params.sort; | 148 | finalParams.sort = params.sort; |
149 | } | 149 | } |
150 | 150 |
-
Please register or login to post a comment