Merge branch 'feature/sale' of git.dev.yoho.cn:web/yohobuywap-node into feature/sale
Showing
6 changed files
with
387 additions
and
53 deletions
@@ -52,6 +52,7 @@ const procProductImg = (product) => { | @@ -52,6 +52,7 @@ const procProductImg = (product) => { | ||
52 | return '1'; | 52 | return '1'; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | + | ||
55 | /** | 56 | /** |
56 | * 商品搜索数据处理 | 57 | * 商品搜索数据处理 |
57 | */ | 58 | */ |
@@ -237,6 +238,46 @@ const processSearch = (list, options) => { | @@ -237,6 +238,46 @@ const processSearch = (list, options) => { | ||
237 | // } | 238 | // } |
238 | }; | 239 | }; |
239 | 240 | ||
241 | +/** | ||
242 | + * 断码区分类数据处理 | ||
243 | + */ | ||
244 | +const processBreakingSort = (list) => { | ||
245 | + const formatData = {}; | ||
246 | + const sortName = []; | ||
247 | + const sub = []; | ||
248 | + | ||
249 | + list = list || []; | ||
250 | + list = camelCase(list); | ||
251 | + | ||
252 | + _.forEach(list, (data, index) => { | ||
253 | + sortName.push(data.sortName); | ||
254 | + data.sub.key = index; | ||
255 | + sub.push(data.sub); | ||
256 | + }); | ||
257 | + | ||
258 | + formatData.sortName = sortName; | ||
259 | + formatData.sub = sub; | ||
260 | + | ||
261 | + return formatData; | ||
262 | +}; | ||
263 | + | ||
264 | + | ||
265 | +/** | ||
266 | + * 获取商品数据 | ||
267 | + */ | ||
268 | +exports.getSearchData = (params) => { | ||
269 | + return api.get('', sign.apiSign(Object.assign({ | ||
270 | + method: 'app.search.sales' | ||
271 | + }, params))).then((result) => { | ||
272 | + if (result && result.code === 200) { | ||
273 | + return processSearch(result); | ||
274 | + } else { | ||
275 | + logger.error('SALE 商品搜索返回 code 不是 200'); | ||
276 | + return []; | ||
277 | + } | ||
278 | + }); | ||
279 | +}; | ||
280 | + | ||
240 | const getResources = (page) => { | 281 | const getResources = (page) => { |
241 | const contentCode = { | 282 | const contentCode = { |
242 | sale: '7c2b77093421efa8ae9302c91460db73', | 283 | sale: '7c2b77093421efa8ae9302c91460db73', |
@@ -261,7 +302,7 @@ const getBreakingSort = (yhChannel) => { | @@ -261,7 +302,7 @@ const getBreakingSort = (yhChannel) => { | ||
261 | yh_channel: yhChannel || '1' | 302 | yh_channel: yhChannel || '1' |
262 | })).then((result) => { | 303 | })).then((result) => { |
263 | if (result && result.code === 200) { | 304 | if (result && result.code === 200) { |
264 | - return result.data; | 305 | + return processBreakingSort(result.data); |
265 | } else { | 306 | } else { |
266 | logger.error('断码区分类接口返回 code 不是 200'); | 307 | logger.error('断码区分类接口返回 code 不是 200'); |
267 | return {}; | 308 | return {}; |
@@ -325,10 +366,10 @@ exports.getSpecialData = (params) => { | @@ -325,10 +366,10 @@ exports.getSpecialData = (params) => { | ||
325 | }, params))).then((result) => { | 366 | }, params))).then((result) => { |
326 | if (result && result.code === 200) { | 367 | if (result && result.code === 200) { |
327 | specialData.data = processSpecial(result.data); | 368 | specialData.data = processSpecial(result.data); |
369 | + return specialData; | ||
328 | } else { | 370 | } else { |
329 | - logger.error('SALE 专题活动列表接口返回 code 不是 200'); | 371 | + return Promise.reject('error'); |
330 | } | 372 | } |
331 | - return specialData; | ||
332 | }); | 373 | }); |
333 | }; | 374 | }; |
334 | 375 |
@@ -6,50 +6,33 @@ | @@ -6,50 +6,33 @@ | ||
6 | {{/if}} | 6 | {{/if}} |
7 | {{/content}} | 7 | {{/content}} |
8 | 8 | ||
9 | - <ul id="list-nav" class="list-nav clearfix"> | ||
10 | - <li class="new active"> | ||
11 | - <a href="javascript:void(0);"> | ||
12 | - <span class="span-test">上装</span> | ||
13 | - </a> | ||
14 | - </li> | ||
15 | - <li class="price"> | ||
16 | - <a href="javascript:void(0);"> | ||
17 | - <span class="span-test">夏装</span> | ||
18 | - </a> | ||
19 | - </li> | ||
20 | - <li class="discount"> | ||
21 | - <a href="javascript:void(0);"> | ||
22 | - <span class="span-test">鞋</span> | ||
23 | - </a> | ||
24 | - </li> | ||
25 | - <li class="discount"> | ||
26 | - <a href="javascript:void(0);"> | ||
27 | - <span class="span-test">其他</span> | ||
28 | - </a> | ||
29 | - </li> | ||
30 | - <li class="filter"> | ||
31 | - <a href="javascript:void(0);"> | ||
32 | - <span class="span-test">筛选</span> | ||
33 | - <span class="iconfont cur"></span> | ||
34 | - </a> | ||
35 | - </li> | ||
36 | - </ul> | ||
37 | - <div class="swiper-container" id="size-swiper"> | ||
38 | - <ul class="swiper-wrapper"> | ||
39 | - <li class="swiper-slide on">XS码</li> | ||
40 | - <li class="swiper-slide">S码</li> | ||
41 | - <li class="swiper-slide">M码</li> | ||
42 | - <li class="swiper-slide">L码</li> | ||
43 | - <li class="swiper-slide">XL码</li> | ||
44 | - <li class="swiper-slide">XXL码</li> | ||
45 | - <li class="swiper-slide">S码</li> | ||
46 | - <li class="swiper-slide">M码</li> | ||
47 | - <li class="swiper-slide">L码</li> | ||
48 | - <li class="swiper-slide">XL码</li> | ||
49 | - <li class="swiper-slide">XXL码</li> | 9 | + {{# nav}} |
10 | + <ul id="list-nav" class="list-nav clearfix"> | ||
11 | + {{# sortName}} | ||
12 | + <li {{#if @first}} class="active" {{/if}}> | ||
13 | + <a href="javascript:void(0);"> | ||
14 | + <span class="span-test">{{.}}</span> | ||
15 | + </a> | ||
16 | + </li> | ||
17 | + {{/ sortName}} | ||
18 | + <li class="filter"> | ||
19 | + <a href="javascript:void(0);"> | ||
20 | + <span class="span-test">筛选</span> | ||
21 | + <span class="iconfont cur"></span> | ||
22 | + </a> | ||
23 | + </li> | ||
50 | </ul> | 24 | </ul> |
51 | - </div> | ||
52 | 25 | ||
26 | + {{# sub}} | ||
27 | + <div class="swiper-container" id="size-swiper-{{key}}" {{#if @first}}style="display:block"{{/if}}> | ||
28 | + <ul class="swiper-wrapper"> | ||
29 | + {{# this}} | ||
30 | + <li class="swiper-slide" data-id="{{sizeId}}">{{sizeName}}</li> | ||
31 | + {{/ this}} | ||
32 | + </ul> | ||
33 | + </div> | ||
34 | + {{/ sub}} | ||
35 | + {{/ nav}} | ||
53 | 36 | ||
54 | <div id="goods-container" class="goods-container"> | 37 | <div id="goods-container" class="goods-container"> |
55 | <div class="new-goods container clearfix"> | 38 | <div class="new-goods container clearfix"> |
1 | -{{#if .}} {{!-- 剔除值为false的项 --}} | 1 | +{{#productList}} {{!-- 剔除值为false的项 --}} |
2 | <div class="good-info" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false"> | 2 | <div class="good-info" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false"> |
3 | <div class="tag-container clearfix"> | 3 | <div class="tag-container clearfix"> |
4 | {{# tags}} | 4 | {{# tags}} |
@@ -47,4 +47,4 @@ | @@ -47,4 +47,4 @@ | ||
47 | {{/if}} | 47 | {{/if}} |
48 | </div> | 48 | </div> |
49 | </div> | 49 | </div> |
50 | -{{/if}} | ||
50 | +{{/productList}} |
@@ -12,12 +12,318 @@ var $ = require('yoho-jquery'), | @@ -12,12 +12,318 @@ var $ = require('yoho-jquery'), | ||
12 | filter = require('../plugin/filter'), | 12 | filter = require('../plugin/filter'), |
13 | loading = require('../plugin/loading'); | 13 | loading = require('../plugin/loading'); |
14 | 14 | ||
15 | -var $listNav = $('#list-nav'); | 15 | +var $goodsContainer = $('#goods-container'), |
16 | + $goodsChildren = $goodsContainer.children(), | ||
17 | + $ngc = $($goodsChildren.get(0)), | ||
18 | + $pgc = $($goodsChildren.get(1)), | ||
19 | + $dgc = $($goodsChildren.get(2)); | ||
16 | 20 | ||
17 | -new Swiper('.swiper-container', { | ||
18 | - slidesPerView: 'auto' | 21 | +var winH = $(window).height(), |
22 | + noResult = '<p class="no-result">未找到相关搜索结果</p>'; | ||
23 | + | ||
24 | +// 默认筛选条件 | ||
25 | +var defaultOpt = require('./query-param'); | ||
26 | + | ||
27 | +var $listNav = $('#list-nav'), | ||
28 | + | ||
29 | + // 导航数据信息 | ||
30 | + navInfo = { | ||
31 | + newest: { | ||
32 | + order: 1, | ||
33 | + reload: true, | ||
34 | + page: 0, | ||
35 | + end: false | ||
36 | + }, | ||
37 | + price: { | ||
38 | + order: 1, | ||
39 | + reload: true, | ||
40 | + page: 0, | ||
41 | + end: false | ||
42 | + }, | ||
43 | + discount: { | ||
44 | + order: 1, | ||
45 | + reload: true, | ||
46 | + page: 0, | ||
47 | + end: false | ||
48 | + } | ||
49 | + }, | ||
50 | + $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项 | ||
51 | + searching; | ||
52 | + | ||
53 | +var swipers = []; | ||
54 | + | ||
55 | +require('./suspend-cart'); // 悬浮购物车 | ||
56 | +require('../common'); | ||
57 | + | ||
58 | +ellipsis.init(); | ||
59 | + | ||
60 | +lazyLoad($('img.lazy')); | ||
61 | + | ||
62 | +$.each($('.swiper-container'), function(key) { | ||
63 | + swipers[key] = new Swiper('#size-swiper-' + key, { | ||
64 | + slidesPerView: 'auto' | ||
65 | + }); | ||
19 | }); | 66 | }); |
20 | 67 | ||
68 | + | ||
69 | +/** | ||
70 | + * 筛选注册的回调,筛选子项点击后逻辑 | ||
71 | + * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载 | ||
72 | + * @param opt {type, id} | ||
73 | + */ | ||
74 | +function search(opt) { | ||
75 | + var setting = {}, | ||
76 | + ext, | ||
77 | + att, | ||
78 | + nav, navType, | ||
79 | + page; | ||
80 | + | ||
81 | + if (searching) { | ||
82 | + return; | ||
83 | + } | ||
84 | + | ||
85 | + if (opt) { | ||
86 | + | ||
87 | + // 筛选项变更则重置reload为true | ||
88 | + for (att in navInfo) { | ||
89 | + if (navInfo.hasOwnProperty(att)) { | ||
90 | + navInfo[att].reload = true; | ||
91 | + } | ||
92 | + } | ||
93 | + | ||
94 | + // 处理active状态 | ||
95 | + $listNav.children('.active').removeClass('active'); | ||
96 | + $pre.addClass('active'); | ||
97 | + | ||
98 | + switch (opt.type) { | ||
99 | + case 'gender': | ||
100 | + ext = { | ||
101 | + gender: opt.id | ||
102 | + }; | ||
103 | + break; | ||
104 | + case 'brand': | ||
105 | + ext = { | ||
106 | + brand: opt.id | ||
107 | + }; | ||
108 | + break; | ||
109 | + case 'sort': | ||
110 | + ext = { | ||
111 | + sort: opt.id | ||
112 | + }; | ||
113 | + break; | ||
114 | + case 'color': | ||
115 | + ext = { | ||
116 | + color: opt.id | ||
117 | + }; | ||
118 | + break; | ||
119 | + case 'size': | ||
120 | + ext = { | ||
121 | + size: opt.id | ||
122 | + }; | ||
123 | + break; | ||
124 | + case 'price': | ||
125 | + ext = { | ||
126 | + price: opt.id | ||
127 | + }; | ||
128 | + break; | ||
129 | + case 'discount': | ||
130 | + ext = { | ||
131 | + discount: opt.id | ||
132 | + }; | ||
133 | + break; | ||
134 | + default: | ||
135 | + break; | ||
136 | + } | ||
137 | + | ||
138 | + $.extend(defaultOpt, ext); // 扩展筛选项 | ||
139 | + } | ||
140 | + | ||
141 | + | ||
142 | + // 导航类别 | ||
143 | + if ($pre.hasClass('new')) { | ||
144 | + navType = 'newest'; | ||
145 | + } else if ($pre.hasClass('price')) { | ||
146 | + navType = 'price'; | ||
147 | + } else if ($pre.hasClass('discount')) { | ||
148 | + navType = 'discount'; | ||
149 | + } | ||
150 | + | ||
151 | + nav = navInfo[navType]; | ||
152 | + page = nav.page + 1; | ||
153 | + if (nav.reload) { | ||
154 | + page = 1; | ||
155 | + } else if (nav.end) { | ||
156 | + | ||
157 | + // 不需要重新加载并且数据请求结束 | ||
158 | + return; | ||
159 | + } | ||
160 | + | ||
161 | + $.extend(setting, defaultOpt, { | ||
162 | + type: navType, | ||
163 | + order: nav.order, | ||
164 | + page: page | ||
165 | + }); | ||
166 | + | ||
167 | + searching = true; | ||
168 | + loading.showLoadingMask(); | ||
169 | + | ||
170 | + $.ajax({ | ||
171 | + type: 'GET', | ||
172 | + url: '/product/sale/search', | ||
173 | + data: setting, | ||
174 | + success: function(data) { | ||
175 | + var $container, | ||
176 | + num; | ||
177 | + | ||
178 | + console.log(data); | ||
179 | + | ||
180 | + switch (navType) { | ||
181 | + case 'newest': | ||
182 | + $container = $ngc; | ||
183 | + break; | ||
184 | + case 'price': | ||
185 | + $container = $pgc; | ||
186 | + break; | ||
187 | + case 'discount': | ||
188 | + $container = $dgc; | ||
189 | + break; | ||
190 | + default: | ||
191 | + break; | ||
192 | + } | ||
193 | + | ||
194 | + if (data === ' ') { | ||
195 | + nav.end = true; | ||
196 | + | ||
197 | + if (nav.reload) { | ||
198 | + $container.html(noResult); | ||
199 | + } | ||
200 | + } else { | ||
201 | + if (nav.reload) { | ||
202 | + $container.html(data); | ||
203 | + lazyLoad($container.find('.lazy')); | ||
204 | + } else { | ||
205 | + num = $container.find('.good-info').length; | ||
206 | + $container.append(data); | ||
207 | + | ||
208 | + // lazy good-infos who append in | ||
209 | + lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy')); | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | + nav.reload = false; | ||
214 | + nav.page = page; | ||
215 | + | ||
216 | + searching = false; | ||
217 | + loading.hideLoadingMask(); | ||
218 | + | ||
219 | + window.rePosFooter(); | ||
220 | + | ||
221 | + $('.good-detail-text .name').each(function() { | ||
222 | + var $this = $(this), | ||
223 | + $title = $this.find('a'); | ||
224 | + | ||
225 | + $title[0].mlellipsis(2); | ||
226 | + }); | ||
227 | + }, | ||
228 | + error: function() { | ||
229 | + tip.show('网络断开连接了~'); | ||
230 | + searching = false; | ||
231 | + loading.hideLoadingMask(); | ||
232 | + } | ||
233 | + }); | ||
234 | + | ||
235 | +} | ||
236 | + | ||
237 | +$.ajax({ | ||
238 | + type: 'GET', | ||
239 | + url: '/product/newsale/filter', | ||
240 | + data: defaultOpt, | ||
241 | + success: function(data) { | ||
242 | + $goodsContainer.append(data); | ||
243 | + | ||
244 | + // 初始化filter&注册filter回调 | ||
245 | + filter.initFilter({ | ||
246 | + fCbFn: search, | ||
247 | + hCbFn: function() { | ||
248 | + | ||
249 | + // 切换active状态到$pre上 | ||
250 | + $pre.addClass('active'); | ||
251 | + $pre.siblings('.filter').removeClass('active'); | ||
252 | + }, | ||
253 | + missStatus: true | ||
254 | + }); | ||
255 | + } | ||
256 | +}); | ||
257 | +lazyLoad($('.lazy')); | ||
258 | + | ||
259 | +$listNav.bind('contextmenu', function() { | ||
260 | + return false; | ||
261 | +}); | ||
262 | + | ||
263 | +$listNav.on('touchend touchcancel', function(e) { | ||
264 | + var $this = $(e.target).closest('li'), | ||
265 | + nav; | ||
266 | + | ||
267 | + e.preventDefault(); | ||
268 | + | ||
269 | + if (typeof $this === 'undefined' || $this.length === 0) { | ||
270 | + return; | ||
271 | + } | ||
272 | + | ||
273 | + if ($this.hasClass('filter')) { | ||
274 | + | ||
275 | + // 筛选面板切换状态 | ||
276 | + if ($this.hasClass('active')) { | ||
277 | + filter.hideFilter(); | ||
278 | + | ||
279 | + // 点击筛选钱的active项回复active | ||
280 | + $pre.addClass('active'); | ||
281 | + $this.removeClass('active'); | ||
282 | + } else { | ||
283 | + $pre = $this.siblings('.active'); | ||
284 | + | ||
285 | + $pre.removeClass('active'); | ||
286 | + $this.addClass('active'); | ||
287 | + | ||
288 | + filter.showFilter(); | ||
289 | + } | ||
290 | + } else { | ||
291 | + if ($this.hasClass('active')) { | ||
292 | + return; | ||
293 | + } else { | ||
294 | + $this.siblings().removeClass('active'); | ||
295 | + $this.addClass('active'); | ||
296 | + $('.swiper-container').hide(); | ||
297 | + $('#size-swiper-' + $this.index()).show(); | ||
298 | + swipers[$this.index()].onResize(); | ||
299 | + } | ||
300 | + | ||
301 | + if (nav.reload) { | ||
302 | + search(); | ||
303 | + } | ||
304 | + } | ||
305 | + e.stopPropagation(); | ||
306 | +}); | ||
307 | + | ||
308 | +function scrollHandler() { | ||
309 | + | ||
310 | + // 当scroll到1/4$goodsContainer高度后继续请求下一页数据 | ||
311 | + if ($(window).scrollTop() + winH > | ||
312 | + $(document).height() - 0.25 * $goodsContainer.height() - 50) { | ||
313 | + if (typeof($pre) !== 'undefined') { | ||
314 | + search(); | ||
315 | + } | ||
316 | + } | ||
317 | +} | ||
318 | + | ||
319 | +// srcoll to load more | ||
320 | +$(window).scroll(function() { | ||
321 | + window.requestAnimationFrame(scrollHandler); | ||
322 | +}); | ||
323 | + | ||
324 | +// 初始请求最新第一页数据 | ||
325 | +search(); | ||
326 | + | ||
21 | $listNav.on('touchstart', 'li', function() { | 327 | $listNav.on('touchstart', 'li', function() { |
22 | $(this).addClass('bytouch'); | 328 | $(this).addClass('bytouch'); |
23 | }).on('touchend touchcancel', function() { | 329 | }).on('touchend touchcancel', function() { |
@@ -11,7 +11,10 @@ | @@ -11,7 +11,10 @@ | ||
11 | } | 11 | } |
12 | } | 12 | } |
13 | 13 | ||
14 | - #size-swiper { | 14 | + #size-swiper-0, |
15 | + #size-swiper-1, | ||
16 | + #size-swiper-2, | ||
17 | + #size-swiper-3 { | ||
15 | width: 100%; | 18 | width: 100%; |
16 | line-height: 50px; | 19 | line-height: 50px; |
17 | color: #999; | 20 | color: #999; |
@@ -21,6 +24,7 @@ | @@ -21,6 +24,7 @@ | ||
21 | background: #f0f0f0; | 24 | background: #f0f0f0; |
22 | padding: 0 22px; | 25 | padding: 0 22px; |
23 | box-sizing: border-box; | 26 | box-sizing: border-box; |
27 | + display: none; | ||
24 | 28 | ||
25 | ul { | 29 | ul { |
26 | width: 100%; | 30 | width: 100%; |
@@ -53,4 +57,4 @@ | @@ -53,4 +57,4 @@ | ||
53 | display: block; | 57 | display: block; |
54 | } | 58 | } |
55 | } | 59 | } |
56 | -} | ||
60 | +} |
-
Please register or login to post a comment