Showing
6 changed files
with
137 additions
and
153 deletions
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | const shopModel = require('../models/shopCollect'), | 3 | const shopModel = require('../models/shopCollect'), |
4 | headerModel = require('../../../doraemon/models/header'); | 4 | headerModel = require('../../../doraemon/models/header'); |
5 | 5 | ||
6 | -const shopIndex = (req, res, next) => { | 6 | +const shopIndex = (req, res) => { |
7 | 7 | ||
8 | res.render('shop-collect/index', { | 8 | res.render('shop-collect/index', { |
9 | module: 'activity', | 9 | module: 'activity', |
@@ -19,44 +19,30 @@ const shopIndex = (req, res, next) => { | @@ -19,44 +19,30 @@ const shopIndex = (req, res, next) => { | ||
19 | {src: '//img10.static.yhbimg.com/yhb-img01/2016/10/10/15/01a6351f91fe38304d268db009c9126bd4.jpg?imageView2/2/w/640/h/240/q/70'}, | 19 | {src: '//img10.static.yhbimg.com/yhb-img01/2016/10/10/15/01a6351f91fe38304d268db009c9126bd4.jpg?imageView2/2/w/640/h/240/q/70'}, |
20 | {src: '//img11.static.yhbimg.com/yhb-img01/2016/10/12/17/0168982b53cefca01ff3b2c5b91e606714.jpg?imageView2/2/w/640/h/240/q/70'} | 20 | {src: '//img11.static.yhbimg.com/yhb-img01/2016/10/12/17/0168982b53cefca01ff3b2c5b91e606714.jpg?imageView2/2/w/640/h/240/q/70'} |
21 | ] | 21 | ] |
22 | - }, | ||
23 | - navList: [ | ||
24 | - { | ||
25 | - navName: '推荐' | ||
26 | - }, | ||
27 | - { | ||
28 | - navName: '推荐' | ||
29 | - }, | ||
30 | - { | ||
31 | - navName: '推荐' | ||
32 | - }, | ||
33 | - { | ||
34 | - navName: '推荐' | ||
35 | - }, | ||
36 | - { | ||
37 | - navName: '推荐' | ||
38 | - }, | ||
39 | - { | ||
40 | - navName: '推荐' | ||
41 | - }, | ||
42 | - { | ||
43 | - navName: '推荐' | ||
44 | - } | ||
45 | - ] | 22 | + } |
46 | } | 23 | } |
47 | }); | 24 | }); |
48 | }; | 25 | }; |
49 | 26 | ||
27 | +const shopNav = (req, res, next) => { | ||
28 | + | ||
29 | + shopModel.shopNav().then((result) => { | ||
30 | + res.json(result); | ||
31 | + }).catch(next); | ||
32 | +}; | ||
33 | + | ||
34 | + | ||
50 | const shopList = (req, res, next) => { | 35 | const shopList = (req, res, next) => { |
51 | - let uid = req.user.uid || 12696231; | 36 | + let uid = req.user.uid; |
52 | let tabName = req.query.tabName; | 37 | let tabName = req.query.tabName; |
53 | 38 | ||
54 | shopModel.shopList(uid, tabName).then((result) => { | 39 | shopModel.shopList(uid, tabName).then((result) => { |
55 | res.json(result); | 40 | res.json(result); |
56 | - }); | 41 | + }).catch(next); |
57 | }; | 42 | }; |
58 | 43 | ||
59 | module.exports = { | 44 | module.exports = { |
60 | shopIndex, | 45 | shopIndex, |
61 | - shopList | 46 | + shopList, |
47 | + shopNav | ||
62 | }; | 48 | }; |
@@ -16,29 +16,11 @@ const shopList = (uid, tabName) => { | @@ -16,29 +16,11 @@ const shopList = (uid, tabName) => { | ||
16 | uid: uid, | 16 | uid: uid, |
17 | tab_name: tabName | 17 | tab_name: tabName |
18 | }).then((result) => { | 18 | }).then((result) => { |
19 | - console.log(result); | ||
20 | - result = { | ||
21 | - alg: 'SALT_MD5', | ||
22 | - code: 200, | ||
23 | - data: [ | ||
24 | - { | ||
25 | - bannerUrl: 'http://aaa.jpg', | ||
26 | - collectionNum: 134, | ||
27 | - id: 2, | ||
28 | - logoUrl: 'http://bbb.png', | ||
29 | - shopName: 'Stussy', | ||
30 | - shopsId: 333, | ||
31 | - tabName: 'promotion', | ||
32 | - words: '关注送20有货币', | ||
33 | - isFavorite: 'Y' | ||
34 | - } | ||
35 | - ], | ||
36 | - md5: 'e2acc1bf474ee2b1a581d2ca91286511', | ||
37 | - message: 'product shopsPromote Info' | ||
38 | - }; | ||
39 | 19 | ||
40 | if (result && result.code === 200) { | 20 | if (result && result.code === 200) { |
41 | - // console.log(result.data, 123) | 21 | + _.forEach(result.data, function(data) { |
22 | + data.isFavorite = data.isFavorite === 'Y'; | ||
23 | + }); | ||
42 | return result.data; | 24 | return result.data; |
43 | } else { | 25 | } else { |
44 | logger.error('shop list data return code is not 200'); | 26 | logger.error('shop list data return code is not 200'); |
@@ -47,6 +29,15 @@ const shopList = (uid, tabName) => { | @@ -47,6 +29,15 @@ const shopList = (uid, tabName) => { | ||
47 | }); | 29 | }); |
48 | }; | 30 | }; |
49 | 31 | ||
32 | +const shopNav = () => { | ||
33 | + return api.get('', { | ||
34 | + method: 'app.shops.promoteTabNameList' | ||
35 | + }).then((result) => { | ||
36 | + return result.data; | ||
37 | + }); | ||
38 | +}; | ||
39 | + | ||
50 | module.exports = { | 40 | module.exports = { |
51 | - shopList | 41 | + shopList, |
42 | + shopNav | ||
52 | }; | 43 | }; |
@@ -86,5 +86,6 @@ router.get('/vip-day/msg/fetch.json', vipDay.fetchMsg); | @@ -86,5 +86,6 @@ router.get('/vip-day/msg/fetch.json', vipDay.fetchMsg); | ||
86 | 86 | ||
87 | router.get('/shopCollect', shopCollect.shopIndex);// 店铺收藏 | 87 | router.get('/shopCollect', shopCollect.shopIndex);// 店铺收藏 |
88 | router.get('/shopList', shopCollect.shopList);// 店铺收藏列表 | 88 | router.get('/shopList', shopCollect.shopList);// 店铺收藏列表 |
89 | +router.get('/shopNav', shopCollect.shopNav);// 店铺收藏导航 | ||
89 | 90 | ||
90 | module.exports = router; | 91 | module.exports = router; |
@@ -9,7 +9,6 @@ var $ = require('yoho-jquery'), | @@ -9,7 +9,6 @@ var $ = require('yoho-jquery'), | ||
9 | // Handlebars = require('yoho-handlebars'); | 9 | // Handlebars = require('yoho-handlebars'); |
10 | 10 | ||
11 | var searching, | 11 | var searching, |
12 | - $collect = $('.collect-btn'), | ||
13 | shopId, | 12 | shopId, |
14 | navSwiper, | 13 | navSwiper, |
15 | stoping; | 14 | stoping; |
@@ -17,125 +16,145 @@ var searching, | @@ -17,125 +16,145 @@ var searching, | ||
17 | var shopNav = require('template/shopCollect/shop-nav.hbs'), | 16 | var shopNav = require('template/shopCollect/shop-nav.hbs'), |
18 | shopList = require('template/shopCollect/shop-list.hbs'); | 17 | shopList = require('template/shopCollect/shop-list.hbs'); |
19 | 18 | ||
20 | -var navString = shopNav({ | ||
21 | - navList: [ | ||
22 | - { | ||
23 | - navName: '欧美', | ||
24 | - tabName: 'promotion' | ||
25 | - }, | ||
26 | - { | ||
27 | - navName: '欧美', | ||
28 | - tabName: 'promotion1' | ||
29 | - }, | ||
30 | - { | ||
31 | - navName: '推荐', | ||
32 | - tabName: 'promotion2' | ||
33 | - } | ||
34 | - ] | ||
35 | -}); | ||
36 | - | ||
37 | require('../common'); | 19 | require('../common'); |
38 | 20 | ||
39 | var navType = window.queryString; | 21 | var navType = window.queryString; |
40 | 22 | ||
41 | -$('.shop-nav').html(navString); | ||
42 | - | ||
43 | -$collect.on('click', function() { | ||
44 | - console.log(12); | ||
45 | - var opt, | ||
46 | - $this = $(this); | 23 | +require('../common'); |
47 | 24 | ||
48 | - shopId = $this.parents('.shop-info').data('id'); | 25 | +// 店铺列表数据 |
26 | +function shopListData(tabName, stoping) { | ||
49 | 27 | ||
50 | - if (searching) { | 28 | + if (stoping) { |
51 | return; | 29 | return; |
52 | } | 30 | } |
53 | - searching = true; | ||
54 | - | ||
55 | - if ($collect.hasClass('already-collect')) { | ||
56 | - opt = 'cancel'; | ||
57 | - } else { | ||
58 | - opt = 'ok'; | ||
59 | - } | ||
60 | 31 | ||
61 | $.ajax({ | 32 | $.ajax({ |
62 | method: 'get', | 33 | method: 'get', |
63 | - url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand', | 34 | + url: '/activity/shopList', |
64 | data: { | 35 | data: { |
65 | - id: shopId, | ||
66 | - opt: opt, | ||
67 | - type: 'shop', | ||
68 | - }, | ||
69 | - xhrFields: { | ||
70 | - withCredentials: true | 36 | + tabName: tabName |
71 | }, | 37 | }, |
72 | success: function(data) { | 38 | success: function(data) { |
73 | 39 | ||
74 | - if (data.code === 200) { | ||
75 | - if ($collect.hasClass('already-collect')) { | ||
76 | - $collect.removeClass('already-collect'); | ||
77 | - tip.show('店铺取消收藏成功'); | 40 | + var list = shopList({ |
41 | + shopList: data | ||
42 | + }); | ||
43 | + | ||
44 | + $('.shop-list').html(list); | ||
45 | + | ||
46 | + stoping = false; | ||
47 | + | ||
48 | + $('.collect-btn').on('click', function() { | ||
49 | + var opt, | ||
50 | + $this = $(this); | ||
51 | + | ||
52 | + shopId = $this.parents('.shop-info').data('id'); | ||
53 | + | ||
54 | + if (searching) { | ||
55 | + return; | ||
56 | + } | ||
57 | + searching = true; | ||
58 | + | ||
59 | + if ($this.hasClass('already-collect')) { | ||
60 | + opt = 'cancel'; | ||
78 | } else { | 61 | } else { |
79 | - $collect.addClass('already-collect'); | ||
80 | - tip.show('店铺收藏成功'); | 62 | + opt = 'ok'; |
81 | } | 63 | } |
82 | - } | ||
83 | 64 | ||
84 | - if (data.code === 400) { | ||
85 | - window.location.href = 'http://www.yohobuy.com/passport/login'; | ||
86 | - } | ||
87 | - searching = false; | 65 | + $.ajax({ |
66 | + method: 'get', | ||
67 | + url: location.protocol + '//m.yohobuy.com' + '/product/opt/favoriteBrand', | ||
68 | + data: { | ||
69 | + id: shopId, | ||
70 | + opt: opt, | ||
71 | + type: 'shop', | ||
72 | + }, | ||
73 | + xhrFields: { | ||
74 | + withCredentials: true | ||
75 | + }, | ||
76 | + success: function(data) { | ||
77 | + | ||
78 | + if (data.code === 200) { | ||
79 | + if ($this.hasClass('already-collect')) { | ||
80 | + $this.removeClass('already-collect'); | ||
81 | + tip.show('店铺取消收藏成功'); | ||
82 | + } else { | ||
83 | + $this.addClass('already-collect'); | ||
84 | + tip.show('店铺收藏成功'); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + if (data.code === 400) { | ||
89 | + window.location.href = 'http://www.yohobuy.com/passport/login'; | ||
90 | + } | ||
91 | + searching = false; | ||
92 | + }, | ||
93 | + error: function() { | ||
94 | + tip.show('网络断开连接了~'); | ||
95 | + searching = false; | ||
96 | + } | ||
97 | + }); | ||
98 | + }); | ||
88 | }, | 99 | }, |
89 | error: function() { | 100 | error: function() { |
90 | tip.show('网络断开连接了~'); | 101 | tip.show('网络断开连接了~'); |
91 | - searching = false; | 102 | + stoping = false; |
92 | } | 103 | } |
93 | }); | 104 | }); |
94 | -}); | 105 | +} |
95 | 106 | ||
96 | -function shopListData(tabName, stoping) { | ||
97 | - | ||
98 | - if (stoping) { | ||
99 | - return; | ||
100 | - } | ||
101 | 107 | ||
108 | +// 导航数据 | ||
109 | +function shopNavData() { | ||
102 | $.ajax({ | 110 | $.ajax({ |
103 | method: 'get', | 111 | method: 'get', |
104 | - url: '/activity/shopList', | ||
105 | - data: { | ||
106 | - tabName: tabName | ||
107 | - }, | 112 | + url: '/activity/shopNav', |
113 | + | ||
108 | success: function(data) { | 114 | success: function(data) { |
109 | 115 | ||
110 | - var list = shopList({ | ||
111 | - shopList: data | 116 | + var navString = shopNav({ |
117 | + navList: data | ||
112 | }); | 118 | }); |
113 | 119 | ||
114 | - $('.shop-list').html(list); | 120 | + $('.shop-nav').html(navString); |
121 | + | ||
122 | + if (navType.id) { | ||
123 | + $('.shop-nav').find('li').each(function() { | ||
124 | + if (navType.id === $(this).data('type')) { | ||
125 | + $(this).addClass('active'); | ||
126 | + shopListData($(this).data('type')); | ||
127 | + } | ||
128 | + }); | ||
129 | + | ||
130 | + } else { | ||
131 | + $('.shop-nav').find('li').eq(0).addClass('active'); | ||
132 | + shopListData($('.shop-nav').find('li').eq(0).data('type')); | ||
133 | + } | ||
134 | + | ||
135 | + $('.shop-nav').find('li').on('click', function() { | ||
136 | + var $this = $(this), | ||
137 | + tabName = $this.data('type'); | ||
138 | + | ||
139 | + if ($this.hasClass('active')) { | ||
140 | + stoping = true; | ||
141 | + } else { | ||
142 | + stoping = false; | ||
143 | + } | ||
144 | + | ||
145 | + shopListData(tabName, stoping); | ||
146 | + | ||
147 | + $this.addClass('active').siblings().removeClass('active'); | ||
148 | + }); | ||
115 | 149 | ||
116 | - stoping = false; | ||
117 | }, | 150 | }, |
118 | error: function() { | 151 | error: function() { |
119 | tip.show('网络断开连接了~'); | 152 | tip.show('网络断开连接了~'); |
120 | - stoping = false; | 153 | + |
121 | } | 154 | } |
122 | }); | 155 | }); |
123 | } | 156 | } |
124 | 157 | ||
125 | -$('.shop-nav').find('li').on('click', function() { | ||
126 | - var $this = $(this), | ||
127 | - tabName = $this.data('type'); | ||
128 | - | ||
129 | - if ($this.hasClass('active')) { | ||
130 | - stoping = true; | ||
131 | - } else { | ||
132 | - stoping = false; | ||
133 | - } | ||
134 | - | ||
135 | - shopListData(tabName, stoping); | ||
136 | - | ||
137 | - $this.addClass('active').siblings().removeClass('active'); | ||
138 | -}); | ||
139 | 158 | ||
140 | $(function() { | 159 | $(function() { |
141 | navSwiper = new Swiper('.shop-nav', { | 160 | navSwiper = new Swiper('.shop-nav', { |
@@ -157,18 +176,5 @@ $(function() { | @@ -157,18 +176,5 @@ $(function() { | ||
157 | }); | 176 | }); |
158 | } | 177 | } |
159 | 178 | ||
160 | - if (navType.id) { | ||
161 | - $('.shop-nav').find('li').each(function() { | ||
162 | - if (navType.id === $(this).data('type')) { | ||
163 | - $(this).addClass('active'); | ||
164 | - shopListData($(this).data('type')); | ||
165 | - } | ||
166 | - }); | ||
167 | - | ||
168 | - } else { | ||
169 | - $('.shop-nav').find('li').eq(0).addClass('active'); | ||
170 | - shopListData($('.shop-nav').find('li').eq(0).data('type')); | ||
171 | - } | ||
172 | - | ||
173 | - | 179 | + shopNavData(); |
174 | }); | 180 | }); |
1 | {{# shopList}} | 1 | {{# shopList}} |
2 | - <div class="shop-info" data-id="1284"> | 2 | + <div class="shop-info" data-id="{{shopsId}}"> |
3 | <div class="info-title"> | 3 | <div class="info-title"> |
4 | <div class="collect"> | 4 | <div class="collect"> |
5 | - <span class="fans">粉丝{{fansNum}}</span> | ||
6 | - <i class="iconfont collect-btn already-collect"></i> | 5 | + <span class="fans">粉丝{{collectionNum}}</span> |
6 | + <i class="iconfont collect-btn {{#if isFavorite}}already-collect{{/ if}}"></i> | ||
7 | </div> | 7 | </div> |
8 | 8 | ||
9 | <div class="shop-tile"> | 9 | <div class="shop-tile"> |
10 | - <img src="{{logo}}"></img> | 10 | + <img src="{{logoUrl}}"></img> |
11 | <p> | 11 | <p> |
12 | - <span class="shop-name">stussy</span><br> | ||
13 | - <span class="giving">关注送yoho币</span> | 12 | + <span class="shop-name">{{shopName}}</span><br> |
13 | + <span class="giving">{{words}}</span> | ||
14 | </p> | 14 | </p> |
15 | </div> | 15 | </div> |
16 | </div> | 16 | </div> |
17 | 17 | ||
18 | <div class="info-content"> | 18 | <div class="info-content"> |
19 | - <img class="content"></img> | 19 | + <img class="content" src="{{bannerUrl}}"></img> |
20 | </div> | 20 | </div> |
21 | </div> | 21 | </div> |
22 | {{/ shopList}} | 22 | {{/ shopList}} |
-
Please register or login to post a comment