Authored by yyq

shop pjax

@@ -17,6 +17,16 @@ const shop = (shopId, req, res, next, brandInfo) => { @@ -17,6 +17,16 @@ const shop = (shopId, req, res, next, brandInfo) => {
17 17
18 list.getShopInfo(shopId, req.user.id).then(shopInfo => { 18 list.getShopInfo(shopId, req.user.id).then(shopInfo => {
19 if (+shopInfo.shopTemplateType === 2) { // 经典模板 19 if (+shopInfo.shopTemplateType === 2) { // 经典模板
  20 + let pjax = req.query._pjax;
  21 +
  22 + if (pjax) {
  23 + list.getShopGoodsData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
  24 + Object.assign(result, {layout: false});
  25 + res.render('list/goods-list', result);
  26 + }).catch(next);
  27 + return;
  28 + }
  29 +
20 list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => { 30 list.getShopData(shopId, req.yoho.channel, req.query, shopInfo).then(result => {
21 Object.assign(result, { 31 Object.assign(result, {
22 page: 'shop', 32 page: 'shop',
@@ -27,9 +37,9 @@ const shop = (shopId, req, res, next, brandInfo) => { @@ -27,9 +37,9 @@ const shop = (shopId, req, res, next, brandInfo) => {
27 } else { // 基础模板 37 } else { // 基础模板
28 list.getBaseShopData(req.query, Object.assign({uid: req.user.uid}, brandInfo), 38 list.getBaseShopData(req.query, Object.assign({uid: req.user.uid}, brandInfo),
29 req.yoho.channel, shopId).then(result => { 39 req.yoho.channel, shopId).then(result => {
30 - Object.assign(result, {page: 'list'});  
31 - res.render('list/brand', result);  
32 - }).catch(next); 40 + Object.assign(result, {page: 'list'});
  41 + res.render('list/brand', result);
  42 + }).catch(next);
33 } 43 }
34 }).catch(next); 44 }).catch(next);
35 }; 45 };
@@ -672,6 +672,54 @@ const getShopData = (shopId, channel, params, shopInfo) => { @@ -672,6 +672,54 @@ const getShopData = (shopId, channel, params, shopInfo) => {
672 }); 672 });
673 }; 673 };
674 674
  675 +/**
  676 + * 获取店铺商品数据
  677 + */
  678 +const getShopGoodsData = (shopId, channel, params) => {
  679 + let gender = _getGender(channel);
  680 + let resData = {};
  681 +
  682 + _.unset(params, '_pjax');
  683 + return Promise.all([
  684 + searchApi.getProductList(Object.assign({
  685 + shop_id: shopId
  686 + }, params)), // 搜索店铺商品
  687 + searchApi.getShopBrands(shopId) // 店铺品牌数据
  688 + ]).then(result => {
  689 + // 获取商品数据和顶部筛选条件
  690 + if (result[0].code === 200) {
  691 + Object.assign(resData, {
  692 + sort: searchHandler.handleOptsData(params, _.get(result[0], 'data.total', 0)),
  693 + list: productProcess.processProductList(_.get(result[0], 'data.product_list', []), {
  694 + newCoverSort: true,
  695 + showDiscount: false,
  696 + gender: gender
  697 + })
  698 + });
  699 + _.set(resData, 'sort.newPage', true); // 启用新的分页导航
  700 + }
  701 +
  702 + let shopBrandIds = []; // 店铺的所有品牌id
  703 +
  704 + if (result[1].code === 200 && result[1].data) {
  705 + _.forEach(result[1].data, value => {
  706 + shopBrandIds.push(value.brand_id);
  707 + });
  708 + }
  709 +
  710 + // 根据品牌获取分类 (腾讯云测试没有该接口,暂时不调用分类)
  711 + return searchApi.getSortList({brand: shopBrandIds}).then(subRes => {
  712 + if (subRes.code === 200) {
  713 + let groupSort = _.get(subRes, 'data.sort', []);
  714 +
  715 + Object.assign(resData, searchHandler.setShopSort(groupSort, params));
  716 + }
  717 +
  718 + return resData;
  719 + });
  720 + });
  721 +};
  722 +
675 const getShopListData = (channel, params, uid) => { 723 const getShopListData = (channel, params, uid) => {
676 let gender = _getGender(channel), 724 let gender = _getGender(channel),
677 shopId = params.shopId, 725 shopId = params.shopId,
@@ -848,6 +896,7 @@ module.exports = { @@ -848,6 +896,7 @@ module.exports = {
848 getAdnav, 896 getAdnav,
849 getShopInfo, 897 getShopInfo,
850 getShopData, 898 getShopData,
  899 + getShopGoodsData,
851 getShopListData, 900 getShopListData,
852 getBaseShopData 901 getBaseShopData
853 }; 902 };