Authored by yyq

shop pjax

... ... @@ -17,6 +17,16 @@ const shop = (shopId, req, res, next, brandInfo) => {
list.getShopInfo(shopId, req.user.id).then(shopInfo => {
if (+shopInfo.shopTemplateType === 2) { // 经典模板
let pjax = req.query._pjax;
if (pjax) {
list.getShopGoodsData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
Object.assign(result, {layout: false});
res.render('list/goods-list', result);
}).catch(next);
return;
}
list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
Object.assign(result, {
page: 'shop',
... ... @@ -27,9 +37,9 @@ const shop = (shopId, req, res, next, brandInfo) => {
} else { // 基础模板
list.getBaseShopData(req.query, Object.assign({uid: req.user.uid}, brandInfo),
req.yoho.channel, shopId).then(result => {
Object.assign(result, {page: 'list'});
res.render('list/brand', result);
}).catch(next);
Object.assign(result, {page: 'list'});
res.render('list/brand', result);
}).catch(next);
}
}).catch(next);
};
... ...
... ... @@ -672,6 +672,54 @@ const getShopData = (shopId, channel, params, shopInfo) => {
});
};
/**
* 获取店铺商品数据
*/
const getShopGoodsData = (shopId, channel, params) => {
let gender = _getGender(channel);
let resData = {};
_.unset(params, '_pjax');
return Promise.all([
searchApi.getProductList(Object.assign({
shop_id: shopId
}, params)), // 搜索店铺商品
searchApi.getShopBrands(shopId) // 店铺品牌数据
]).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); // 启用新的分页导航
}
let shopBrandIds = []; // 店铺的所有品牌id
if (result[1].code === 200 && result[1].data) {
_.forEach(result[1].data, value => {
shopBrandIds.push(value.brand_id);
});
}
// 根据品牌获取分类 (腾讯云测试没有该接口,暂时不调用分类)
return searchApi.getSortList({brand: shopBrandIds}).then(subRes => {
if (subRes.code === 200) {
let groupSort = _.get(subRes, 'data.sort', []);
Object.assign(resData, searchHandler.setShopSort(groupSort, params));
}
return resData;
});
});
};
const getShopListData = (channel, params, uid) => {
let gender = _getGender(channel),
shopId = params.shopId,
... ... @@ -848,6 +896,7 @@ module.exports = {
getAdnav,
getShopInfo,
getShopData,
getShopGoodsData,
getShopListData,
getBaseShopData
};
... ...
{{> list/shop-list}}
\ No newline at end of file
... ...