Authored by yyq

pjax

... ... @@ -7,13 +7,24 @@ const tdk = require('../../../utils/getTDK');
exports.index = (req, res, next) => {
let domain = req.query.domain;
let shopId = req.query.shopId;
if (!domain) {
return next();
}
if (req.xhr && req.query._pjax && shopId) {
return shopModel.getShopGoodsData(shopId, req.yoho.channel, req.query).then(result => {
Object.assign(result, {
shopId: shopId,
layout: false
});
res.render('list/goods-list', result);
});
}
Promise.all([
tdk('shop', req.query.shopId, req),
tdk('shop', shopId, req),
shopModel.getShopInfoAsync(domain, req.yoho.channel, req.query)
]).then(result => {
let TDKObj = result[0],
... ... @@ -51,5 +62,5 @@ exports.index = (req, res, next) => {
res.render('list/brand', shopObj);
}
});
}).catch(next);
};
... ...
... ... @@ -99,8 +99,8 @@ const _getShopData = (channel, params, shopInfo) => {
header: headerModel.requestHeaderData(channel), // 头部数据
sort: searchApi.getSortList({shop_id: shopId}),
decorator: searchApi.getShopDecorator(shopId), // 店铺装修数据
product: searchApi.getProductList(Object.assign(params,
{shop_id: shopId, need_filter: 'no'}), 'shop'), // 搜索店铺商品
product: searchApi.getProductList(Object.assign({shop_id: shopId,
need_filter: 'no'}, params), 'shop'), // 搜索店铺商品
brands: searchApi.getShopBrands(shopId), // 店铺品牌数据
coupons: api.shopCouponListAsync(shopId), // 店铺优惠券数据
shopInfo: shopInfo ? Promise.resolve(shopInfo) : api.getShopInfo(shopId)
... ... @@ -441,6 +441,39 @@ exports.getShopInfoAsync = (domain, channel, params) => {
})();
};
exports.getShopGoodsData = (shopId, channel, params) => {
let gender = _getGender(channel);
let resData = {};
_.unset(params, '_pjax');
return Promise.all([
searchApi.getProductList(Object.assign({shop_id: shopId}, params), 'shop'), // 搜索店铺商品
searchApi.getSortList({shop_id: shopId}) // 根据店铺id获取分类
]).then(result => {
// 获取商品数据和顶部筛选条件
if (result[0].code === 200) {
Object.assign(resData, {
sort: searchHandler.handleOptsData(params, _.get(result[0], 'data.total', 0)),
list: productProcess.processProductList(_.get(result[0], 'data.product_list', []), {
newCoverSort: true,
showDiscount: false,
gender: gender
})
});
_.set(resData, 'sort.newPage', true); // 启用新的分页导航
}
if (result[1].code === 200) {
let groupSort = _.get(result[1], 'data', []);
Object.assign(resData, searchHandler.setShopSort(groupSort, Object.assign({}, params,
{page: 1})), searchHandler.setGenderFilter(params));
}
return resData;
});
}
/**
* 基础模板
*/
... ...