Merge branch 'release/5.0.0' of git.yoho.cn:fe/yohobuy-node into release/5.0.0
Showing
5 changed files
with
118 additions
and
38 deletions
@@ -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 | }; |
@@ -204,9 +204,7 @@ const formatterFilterBrands = (source, paramBrand, params) => { | @@ -204,9 +204,7 @@ const formatterFilterBrands = (source, paramBrand, params) => { | ||
204 | index: '0-9', | 204 | index: '0-9', |
205 | name: '0~9' | 205 | name: '0~9' |
206 | }], | 206 | }], |
207 | - selectedBrands: [], | ||
208 | - showMore: true, | ||
209 | - showMulti: true | 207 | + selectedBrands: [] |
210 | }; | 208 | }; |
211 | 209 | ||
212 | 210 | ||
@@ -257,6 +255,13 @@ const formatterFilterBrands = (source, paramBrand, params) => { | @@ -257,6 +255,13 @@ const formatterFilterBrands = (source, paramBrand, params) => { | ||
257 | count++; | 255 | count++; |
258 | }); | 256 | }); |
259 | 257 | ||
258 | + if (dbrand.default.length > 9) { | ||
259 | + Object.assign(dbrand, { | ||
260 | + showMore: true, | ||
261 | + showMulti: true | ||
262 | + }); | ||
263 | + } | ||
264 | + | ||
260 | if (paramBrand) { | 265 | if (paramBrand) { |
261 | _.forEach(paramBrand, value => { | 266 | _.forEach(paramBrand, value => { |
262 | let brand = { | 267 | let brand = { |
@@ -538,7 +543,10 @@ exports.setShopSort = (data, params) => { | @@ -538,7 +543,10 @@ exports.setShopSort = (data, params) => { | ||
538 | }); | 543 | }); |
539 | 544 | ||
540 | if (list.length) { | 545 | if (list.length) { |
541 | - _.set(resData, 'goodsMenu.menuList', list); | 546 | + resData.goodsMenu = { |
547 | + menuList: list, | ||
548 | + url: `/product/shoplist?navBar=1&shopId=${params.shopId}` | ||
549 | + }; | ||
542 | } | 550 | } |
543 | } | 551 | } |
544 | 552 | ||
@@ -554,19 +562,6 @@ exports.setShopSort = (data, params) => { | @@ -554,19 +562,6 @@ exports.setShopSort = (data, params) => { | ||
554 | exports.handleFilterData = (origin, params, total) => { | 562 | exports.handleFilterData = (origin, params, total) => { |
555 | let dest = { | 563 | let dest = { |
556 | ageLevel: [], | 564 | ageLevel: [], |
557 | - brand: { | ||
558 | - default: [], | ||
559 | - brandsShow: [], | ||
560 | - brandIndex: [{ | ||
561 | - index: 'all', | ||
562 | - name: '全部' | ||
563 | - }, { | ||
564 | - index: '0-9', | ||
565 | - name: '0~9' | ||
566 | - }], | ||
567 | - showMore: true, | ||
568 | - showMulti: true | ||
569 | - }, | ||
570 | price: [], | 565 | price: [], |
571 | gender: [], | 566 | gender: [], |
572 | color: [], | 567 | color: [], |
@@ -68,11 +68,9 @@ const hotProducts = (data) => { | @@ -68,11 +68,9 @@ const hotProducts = (data) => { | ||
68 | */ | 68 | */ |
69 | const goodsTabBar = (data, shopId) => { | 69 | const goodsTabBar = (data, shopId) => { |
70 | let dest = { | 70 | let dest = { |
71 | - hot: [], | ||
72 | - new: [] | ||
73 | - }, | ||
74 | - more = {name: 'MORE', href: shopListUrl + '?shopId=' + shopId}; | ||
75 | - | 71 | + hot: [], |
72 | + new: [] | ||
73 | + }; | ||
76 | 74 | ||
77 | _.forEach(data.hot, (value) => { | 75 | _.forEach(data.hot, (value) => { |
78 | if (value.url) { | 76 | if (value.url) { |
@@ -92,8 +90,8 @@ const goodsTabBar = (data, shopId) => { | @@ -92,8 +90,8 @@ const goodsTabBar = (data, shopId) => { | ||
92 | }); | 90 | }); |
93 | } | 91 | } |
94 | }); | 92 | }); |
95 | - dest.hot.push(more); | ||
96 | - dest.new.push(more); | 93 | + dest.hot.push({name: 'MORE', url: `${shopListUrl}?navBar=2&order=s_n_desc&shopId=${shopId}`}); |
94 | + dest.new.push({name: 'MORE', url: `${shopListUrl}?navBar=3&order=s_t_desc&shopId=${shopId}`}); | ||
97 | return dest; | 95 | return dest; |
98 | }; | 96 | }; |
99 | 97 | ||
@@ -144,11 +142,11 @@ const navigationBar = (data, shopId) => { | @@ -144,11 +142,11 @@ const navigationBar = (data, shopId) => { | ||
144 | }, | 142 | }, |
145 | { | 143 | { |
146 | name: '人气单品', | 144 | name: '人气单品', |
147 | - url: `${shopListUrl}/?navBar=2&shopId=${shopId}` | 145 | + url: `${shopListUrl}/?navBar=2&order=s_n_desc&shopId=${shopId}` |
148 | }, | 146 | }, |
149 | { | 147 | { |
150 | name: '新品上架', | 148 | name: '新品上架', |
151 | - url: `${shopListUrl}/?navBar=3&shopId=${shopId}` | 149 | + url: `${shopListUrl}/?navBar=3&order=s_t_desc&shopId=${shopId}` |
152 | } | 150 | } |
153 | ]; | 151 | ]; |
154 | 152 | ||
@@ -162,13 +160,24 @@ const navigationBar = (data, shopId) => { | @@ -162,13 +160,24 @@ const navigationBar = (data, shopId) => { | ||
162 | * @param type $data | 160 | * @param type $data |
163 | * @return type [] | 161 | * @return type [] |
164 | */ | 162 | */ |
165 | -const largeSlideImg = (data) => { | 163 | +const largeSlideImg = (data, shopId) => { |
166 | let dest = []; | 164 | let dest = []; |
167 | 165 | ||
168 | _.forEach(data, (value) => { | 166 | _.forEach(data, (value) => { |
167 | + let url; | ||
168 | + | ||
169 | + value = _.get(value, 'data[0]', {}); | ||
170 | + url = value.url; | ||
171 | + | ||
172 | + if (+value.categoryId > 0) { | ||
173 | + if (!url) { | ||
174 | + url = `${shopListUrl}?shopId=${shopId}`; | ||
175 | + } | ||
176 | + url += `&productPool=${value.categoryId}`; | ||
177 | + } | ||
169 | dest.push({ | 178 | dest.push({ |
170 | - img: value.data[0].src, | ||
171 | - url: helpers.urlFormat(value.data[0].url) | 179 | + img: value.src, |
180 | + url: url | ||
172 | }); | 181 | }); |
173 | }); | 182 | }); |
174 | 183 | ||
@@ -180,13 +189,24 @@ const largeSlideImg = (data) => { | @@ -180,13 +189,24 @@ const largeSlideImg = (data) => { | ||
180 | * @param data 装修数据 | 189 | * @param data 装修数据 |
181 | * @returns {{}} | 190 | * @returns {{}} |
182 | */ | 191 | */ |
183 | -const oneRowTwoColImages = (data) => { | 192 | +const oneRowTwoColImages = (data, shopId) => { |
184 | let dest = []; | 193 | let dest = []; |
185 | 194 | ||
186 | _.forEach(data, (value) => { | 195 | _.forEach(data, (value) => { |
196 | + let url; | ||
197 | + | ||
198 | + value = _.get(value, 'data[0]', {}); | ||
199 | + url = value.url; | ||
200 | + | ||
201 | + if (+value.categoryId > 0) { | ||
202 | + if (!url) { | ||
203 | + url = `${shopListUrl}?shopId=${shopId}`; | ||
204 | + } | ||
205 | + url += `&productPool=${value.categoryId}`; | ||
206 | + } | ||
187 | dest.push({ | 207 | dest.push({ |
188 | - img: value.data[0].src, | ||
189 | - url: helpers.urlFormat(value.data[0].url) | 208 | + img: value.src, |
209 | + url: url | ||
190 | }); | 210 | }); |
191 | }); | 211 | }); |
192 | return {oneRowTwoColImages: dest}; | 212 | return {oneRowTwoColImages: dest}; |
@@ -201,12 +221,17 @@ const recommend = (data, shopId) => { | @@ -201,12 +221,17 @@ const recommend = (data, shopId) => { | ||
201 | let dest = []; | 221 | let dest = []; |
202 | 222 | ||
203 | _.forEach(data, (value) => { | 223 | _.forEach(data, (value) => { |
224 | + let url = value.url || `${shopListUrl}?shopId=${shopId}`; | ||
225 | + | ||
226 | + if (+value.categoryId > 0) { | ||
227 | + url += `&productPool=${value.categoryId}`; | ||
228 | + } | ||
204 | dest.push({ | 229 | dest.push({ |
205 | enName: value.enName, | 230 | enName: value.enName, |
206 | name: value.name, | 231 | name: value.name, |
207 | img: value.src, | 232 | img: value.src, |
208 | title: value.title, | 233 | title: value.title, |
209 | - url: `${shopListUrl}?shopId=${shopId}&filter_poolId=${value.categoryId}` | 234 | + url: url |
210 | }); | 235 | }); |
211 | }); | 236 | }); |
212 | 237 | ||
@@ -301,7 +326,7 @@ exports.getShopDecorator = (data, params, shopId) => { | @@ -301,7 +326,7 @@ exports.getShopDecorator = (data, params, shopId) => { | ||
301 | Object.assign(dest.hotSingle, hotProducts(info)); | 326 | Object.assign(dest.hotSingle, hotProducts(info)); |
302 | break; | 327 | break; |
303 | case 'goodsTabBar': | 328 | case 'goodsTabBar': |
304 | - tabBar = goodsTabBar(info); | 329 | + tabBar = goodsTabBar(info, shopId); |
305 | Object.assign(dest.newArrivel, {navs: tabBar.new}); | 330 | Object.assign(dest.newArrivel, {navs: tabBar.new}); |
306 | Object.assign(dest.hotSingle, {navs: tabBar.hot}); | 331 | Object.assign(dest.hotSingle, {navs: tabBar.hot}); |
307 | break; | 332 | break; |
@@ -315,7 +340,7 @@ exports.getShopDecorator = (data, params, shopId) => { | @@ -315,7 +340,7 @@ exports.getShopDecorator = (data, params, shopId) => { | ||
315 | Object.assign(dest, navigationBar(info, shopId)); | 340 | Object.assign(dest, navigationBar(info, shopId)); |
316 | break; | 341 | break; |
317 | case 'largeSlideImg': | 342 | case 'largeSlideImg': |
318 | - Object.assign(dest, largeSlideImg(info)); | 343 | + Object.assign(dest, largeSlideImg(info, shopId)); |
319 | break; | 344 | break; |
320 | case 'oneRowTwoColImages': | 345 | case 'oneRowTwoColImages': |
321 | Object.assign(dest, oneRowTwoColImages(info, shopId)); | 346 | Object.assign(dest, oneRowTwoColImages(info, shopId)); |
1 | +{{> list/shop-list}} |
-
Please register or login to post a comment