Authored by 郭成尧

filter-modified

... ... @@ -14,6 +14,7 @@ const api = global.yoho.API;
const cache = require('memory-cache');
const helpers = global.yoho.helpers;
const redis = global.yoho.redis;
const co = require('bluebird').coroutine;
/**
* 封面图
... ... @@ -309,25 +310,45 @@ const getSearchData = (params) => {
};
/**
* 搜索品牌的商品
*/
const getBrandGoods = (params) => {
let finalParams = {
method: 'app.search.brand',
};
finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
return api.get('', finalParams);
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
const getFilterData = (params) => {
return _searchGoods(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || []);
return co(function* () {
let filterDataResult = {};
if (params.isBrandShop === 'Y') {
filterDataResult = yield getBrandGoods(params);
} else {
filterDataResult = yield _searchGoods(params);
}
let filterData = _.get(filterDataResult, 'data.filter', []);
if (filterData) {
return productProcess.processFilter(filterData);
} else {
logger.error('get filter data api return code is not 200');
return [];
}
});
})();
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
* TODO 这个可能不用了,待确定
*/
const getFilterSearchData = (params) => {
return _searchGoods(params).then((result) => {
... ... @@ -571,18 +592,6 @@ const getSearchKeywordDataById = (id, params, uid) => {
});
};
/**
* 搜索品牌的商品
*/
const getBrandGoods = (params) => {
let finalParams = {
method: 'app.search.brand',
};
finalParams = _.assign(finalParams, searchProcess.getSearchParamsWithoutMethod(params));
return api.get('', finalParams);
};
module.exports = {
getSearchData,
getFilterData,
... ...
... ... @@ -4,6 +4,9 @@ let ProductListWithFilter = require('product/product-list-with-filter');
let brandId = $('#brandId').val();
let productListWithFilterModel =
new ProductListWithFilter({brand_id: brandId}, 'product/search/brand/goods');
new ProductListWithFilter({
brand_id: brandId,
isBrandShop: 'Y' // 传给 filter,表明调用哪个接口获取筛选面板的数据
}, 'product/search/brand/goods');
productListWithFilterModel.getFilter();
... ...
... ... @@ -14,7 +14,9 @@ const lazyLoad = require('yoho-jquery-lazyload');
class ProductListWithFilter {
constructor(filterParams, searchUrl) {
this.searchUrl = searchUrl || 'product/search/search';
this.filterParams = filterParams;
this.searchUrl = location.protocol + '//m.yohobuy.com/' + (searchUrl || 'product/search/search');
this.filterUrl = location.protocol + '//m.yohobuy.com/product/search/filter';
this.view = {
goodsContainer: $('#goods-container'),
container: $('#goods-container').children('.default-goods'),
... ... @@ -53,7 +55,7 @@ class ProductListWithFilter {
};
this.beforeScroll = document.body.scrollTop; // 滚动前位置记录
this.navType = 'default'; // 目前激活的导航页面
this.defaultOpt = Object.assign({}, this.navInfo.default, filterParams); // 默认参数
this.defaultOpt = Object.assign({}, this.navInfo.default, this.filterParams); // 默认参数
this.onSearching = false; // 是否正在搜索
this.isScrollLoad = false; // 是否是滚动加载
this.page = 1; // 页码
... ... @@ -122,7 +124,7 @@ class ProductListWithFilter {
$.ajax({
type: 'GET',
url: `${location.protocol}//m.yohobuy.com/${this.searchUrl}`,
url: this.searchUrl,
data: this.defaultOpt,
xhrFields: {
withCredentials: true
... ... @@ -186,8 +188,8 @@ class ProductListWithFilter {
getFilter() {
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/search/filter',
data: this.defaultOpt,
url: this.filterUrl,
data: this.filterParams,
success: (data) => {
if (!data) {
return false;
... ...
... ... @@ -128,15 +128,15 @@ const getSearchParamsWithoutMethod = (params) => {
finalParams.gender = params.gender;
}
if (params.color) {
if (params.color && params.color !== '0') {
finalParams.color = params.color;
}
if (params.price) {
if (params.price && params.price !== '0') {
finalParams.price = params.price;
}
if (params.size) {
if (params.size && params.size !== '0') {
finalParams.size = params.size;
}
... ... @@ -144,7 +144,7 @@ const getSearchParamsWithoutMethod = (params) => {
finalParams.p_d = params.p_d;
}
if (params.sort) {
if (params.sort && params.sort !== '0') {
finalParams.sort = params.sort;
}
... ...