Showing
5 changed files
with
347 additions
and
77 deletions
@@ -58,8 +58,9 @@ const processBreakingSort = (list) => { | @@ -58,8 +58,9 @@ const processBreakingSort = (list) => { | ||
58 | list = list || []; | 58 | list = list || []; |
59 | list = camelCase(list); | 59 | list = camelCase(list); |
60 | 60 | ||
61 | - _.forEach(list, (data) => { | 61 | + _.forEach(list, (data, index) => { |
62 | sortName.push(data.sortName); | 62 | sortName.push(data.sortName); |
63 | + data.sub.key = index; | ||
63 | sub.push(data.sub); | 64 | sub.push(data.sub); |
64 | }); | 65 | }); |
65 | 66 | ||
@@ -72,9 +73,7 @@ const processBreakingSort = (list) => { | @@ -72,9 +73,7 @@ const processBreakingSort = (list) => { | ||
72 | /** | 73 | /** |
73 | * 商品搜索数据处理 | 74 | * 商品搜索数据处理 |
74 | */ | 75 | */ |
75 | -const processSearch = (data) => { | ||
76 | - return camelCase(data); | ||
77 | - | 76 | +const processSearch = () => { |
78 | // const goods = []; | 77 | // const goods = []; |
79 | 78 | ||
80 | // list = list || []; | 79 | // list = list || []; |
@@ -114,6 +113,22 @@ const processSearch = (data) => { | @@ -114,6 +113,22 @@ const processSearch = (data) => { | ||
114 | // }); | 113 | // }); |
115 | }; | 114 | }; |
116 | 115 | ||
116 | +/** | ||
117 | + * 获取商品数据 | ||
118 | + */ | ||
119 | +exports.getSearchData = (params) => { | ||
120 | + return api.get('', sign.apiSign(Object.assign({ | ||
121 | + method: 'app.search.sales' | ||
122 | + }, params))).then((result) => { | ||
123 | + if (result && result.code === 200) { | ||
124 | + return processSearch(result); | ||
125 | + } else { | ||
126 | + logger.error('SALE 商品搜索返回 code 不是 200'); | ||
127 | + return []; | ||
128 | + } | ||
129 | + }); | ||
130 | +}; | ||
131 | + | ||
117 | const getResources = (page) => { | 132 | const getResources = (page) => { |
118 | const contentCode = { | 133 | const contentCode = { |
119 | sale: '7c2b77093421efa8ae9302c91460db73', | 134 | sale: '7c2b77093421efa8ae9302c91460db73', |
@@ -147,23 +162,6 @@ const getBreakingSort = (yhChannel) => { | @@ -147,23 +162,6 @@ const getBreakingSort = (yhChannel) => { | ||
147 | }; | 162 | }; |
148 | 163 | ||
149 | /** | 164 | /** |
150 | - * 获取商品数据 | ||
151 | - */ | ||
152 | -exports.getSearchData = (params) => { | ||
153 | - params = params || {}; | ||
154 | - return api.get('', sign.apiSign(Object.assign({ | ||
155 | - method: 'app.search.sales' | ||
156 | - }, params))).then((result) => { | ||
157 | - if (result && result.code === 200) { | ||
158 | - return processSearch(result.data); | ||
159 | - } else { | ||
160 | - logger.error('SALE 商品搜索返回 code 不是 200'); | ||
161 | - return {}; | ||
162 | - } | ||
163 | - }); | ||
164 | -}; | ||
165 | - | ||
166 | -/** | ||
167 | * 获取sale首页数据 | 165 | * 获取sale首页数据 |
168 | * @param {[object]} params | 166 | * @param {[object]} params |
169 | * @return {[object]} | 167 | * @return {[object]} |
@@ -202,10 +200,10 @@ exports.getSpecialData = (params) => { | @@ -202,10 +200,10 @@ exports.getSpecialData = (params) => { | ||
202 | }, params))).then((result) => { | 200 | }, params))).then((result) => { |
203 | if (result && result.code === 200) { | 201 | if (result && result.code === 200) { |
204 | specialData.data = processSpecial(result.data); | 202 | specialData.data = processSpecial(result.data); |
203 | + return specialData; | ||
205 | } else { | 204 | } else { |
206 | - logger.error('SALE 专题活动列表接口返回 code 不是 200'); | 205 | + return Promise.reject('error'); |
207 | } | 206 | } |
208 | - return specialData; | ||
209 | }); | 207 | }); |
210 | }; | 208 | }; |
211 | 209 |
@@ -23,54 +23,16 @@ | @@ -23,54 +23,16 @@ | ||
23 | </li> | 23 | </li> |
24 | </ul> | 24 | </ul> |
25 | 25 | ||
26 | - <div class="swiper-container" id="size-swiper"> | ||
27 | - <ul class="swiper-wrapper"> | ||
28 | - {{# sub}} | ||
29 | - {{log this}} | ||
30 | - <li class="swiper-slide" data-id="{{sizeId}}">{{sizeName}}</li> | ||
31 | - {{/ sub}} | ||
32 | - </ul> | ||
33 | - </div> | 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}} | ||
34 | {{/ nav}} | 35 | {{/ nav}} |
35 | - {{!-- <ul id="list-nav" class="list-nav clearfix"> | ||
36 | - <li class="new active"> | ||
37 | - <a href="javascript:void(0);"> | ||
38 | - <span class="span-test">上装</span> | ||
39 | - </a> | ||
40 | - </li> | ||
41 | - <li class="price"> | ||
42 | - <a href="javascript:void(0);"> | ||
43 | - <span class="span-test">夏装</span> | ||
44 | - </a> | ||
45 | - </li> | ||
46 | - <li class="discount"> | ||
47 | - <a href="javascript:void(0);"> | ||
48 | - <span class="span-test">鞋</span> | ||
49 | - </a> | ||
50 | - </li> | ||
51 | - <li class="discount"> | ||
52 | - <a href="javascript:void(0);"> | ||
53 | - <span class="span-test">其他</span> | ||
54 | - </a> | ||
55 | - </li> | ||
56 | - | ||
57 | - </ul> --}} | ||
58 | - {{!-- <div class="swiper-container" id="size-swiper"> | ||
59 | - <ul class="swiper-wrapper"> | ||
60 | - <li class="swiper-slide on">XS码</li> | ||
61 | - <li class="swiper-slide">S码</li> | ||
62 | - <li class="swiper-slide">M码</li> | ||
63 | - <li class="swiper-slide">L码</li> | ||
64 | - <li class="swiper-slide">XL码</li> | ||
65 | - <li class="swiper-slide">XXL码</li> | ||
66 | - <li class="swiper-slide">S码</li> | ||
67 | - <li class="swiper-slide">M码</li> | ||
68 | - <li class="swiper-slide">L码</li> | ||
69 | - <li class="swiper-slide">XL码</li> | ||
70 | - <li class="swiper-slide">XXL码</li> | ||
71 | - </ul> | ||
72 | - </div> --}} | ||
73 | - | ||
74 | 36 | ||
75 | <div id="goods-container" class="goods-container"> | 37 | <div id="goods-container" class="goods-container"> |
76 | <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