Authored by 王水玲

sale 目录结构整理

Showing 34 changed files with 550 additions and 562 deletions
@@ -44,7 +44,7 @@ exports.index = (req, res) => { @@ -44,7 +44,7 @@ exports.index = (req, res) => {
44 }; 44 };
45 45
46 saleModel.getSaleData().then((result) => { 46 saleModel.getSaleData().then((result) => {
47 - res.render('sale', Object.assign(renderData, queryParam, { 47 + res.render('sale/index', Object.assign(renderData, queryParam, {
48 content: result, 48 content: result,
49 floorHeader: { 49 floorHeader: {
50 title: { 50 title: {
@@ -75,7 +75,7 @@ exports.breakCode = (req, res) => { @@ -75,7 +75,7 @@ exports.breakCode = (req, res) => {
75 saleModel.getBreakCodeData({ 75 saleModel.getBreakCodeData({
76 yhChannel: req.query.channel 76 yhChannel: req.query.channel
77 }).then((result) => { 77 }).then((result) => {
78 - res.render('break-code', Object.assign(renderData, result)); 78 + res.render('sale/break-code', Object.assign(renderData, result));
79 }).catch((err) => { 79 }).catch((err) => {
80 saleLogger(err, res); 80 saleLogger(err, res);
81 }); 81 });
@@ -97,7 +97,7 @@ exports.special = (req, res) => { @@ -97,7 +97,7 @@ exports.special = (req, res) => {
97 }; 97 };
98 98
99 saleModel.getSpecialData().then((result) => { 99 saleModel.getSpecialData().then((result) => {
100 - res.render('special', Object.assign(renderData, result)); 100 + res.render('sale/special', Object.assign(renderData, result));
101 }).catch((err) => { 101 }).catch((err) => {
102 saleLogger(err, res); 102 saleLogger(err, res);
103 }); 103 });
@@ -122,7 +122,7 @@ exports.specialDetail = (req, res) => { @@ -122,7 +122,7 @@ exports.specialDetail = (req, res) => {
122 saleModel.getSpecialDetailData(id).then((result) => { 122 saleModel.getSpecialDetailData(id).then((result) => {
123 headerData.navTitle = result.title; 123 headerData.navTitle = result.title;
124 renderData.pageHeader = headerData; 124 renderData.pageHeader = headerData;
125 - res.render('special-detail', Object.assign(renderData, result)); 125 + res.render('sale/special-detail', Object.assign(renderData, result));
126 }).catch((err) => { 126 }).catch((err) => {
127 saleLogger(err, res); 127 saleLogger(err, res);
128 }); 128 });
@@ -144,7 +144,7 @@ exports.vip = (req, res) => { @@ -144,7 +144,7 @@ exports.vip = (req, res) => {
144 }; 144 };
145 145
146 saleModel.getVipData().then((result) => { 146 saleModel.getVipData().then((result) => {
147 - res.render('vip', Object.assign(renderData, { 147 + res.render('sale/vip', Object.assign(renderData, {
148 content: result 148 content: result
149 })); 149 }));
150 }).catch((err) => { 150 }).catch((err) => {
@@ -303,33 +303,6 @@ exports.getFilterData = (params) => { @@ -303,33 +303,6 @@ exports.getFilterData = (params) => {
303 }; 303 };
304 304
305 /** 305 /**
306 - * 获取商品数据  
307 - * @param {[object]} params  
308 - * @param {[string]} uid  
309 - * @return {[array]}  
310 - */  
311 -exports.getSearchData = (params, uid) => {  
312 - return Promise.all([  
313 - searchSales(params).then((result) => {  
314 - if (result && result.code === 200) {  
315 - return productProcess.processProductList(result.data.product_list || []);  
316 - } else {  
317 - logger.error('SALE 商品搜索返回 code 不是 200');  
318 - return [];  
319 - }  
320 - }),  
321 - getUserProfile(uid).then((result) => {  
322 - if (result && result.code === 200) {  
323 - return camelCase(result.data.vip_info);  
324 - } else {  
325 - logger.error('获取用户信息返回 code 不是 200');  
326 - return {};  
327 - }  
328 - })  
329 - ]);  
330 -};  
331 -  
332 -/**  
333 * 获取sale首页数据 306 * 获取sale首页数据
334 * @return {[array]} 307 * @return {[array]}
335 */ 308 */
@@ -23,10 +23,10 @@ router.get('/detail/intro/:productskn', detail.intro); @@ -23,10 +23,10 @@ router.get('/detail/intro/:productskn', detail.intro);
23 router.get('/detail/preference/:productskn/:yhchannel/:brandId', detail.preference); 23 router.get('/detail/preference/:productskn/:yhchannel/:brandId', detail.preference);
24 24
25 router.get('/sale', sale.index); 25 router.get('/sale', sale.index);
26 -router.get('/special', sale.special);  
27 -router.get('/specialDetail', sale.specialDetail);  
28 -router.get('/breakCode', sale.breakCode);  
29 -router.get('/vip', sale.vip); 26 +router.get('/sale/special', sale.special);
  27 +router.get('/sale/special/detail', sale.specialDetail);
  28 +router.get('/sale/breakCode', sale.breakCode);
  29 +router.get('/sale/vip', sale.vip);
30 30
31 router.get('/sale/search', sale.search); 31 router.get('/sale/search', sale.search);
32 router.get('/sale/filter', sale.filter); 32 router.get('/sale/filter', sale.filter);
1 <div class="break-code-page discount-page yoho-page"> 1 <div class="break-code-page discount-page yoho-page">
  2 +
2 {{#content}} 3 {{#content}}
3 {{! 头部banner}} 4 {{! 头部banner}}
4 {{#if focus}} 5 {{#if focus}}
@@ -8,6 +9,7 @@ @@ -8,6 +9,7 @@
8 9
9 {{# nav}} 10 {{# nav}}
10 <ul id="list-nav" class="list-nav clearfix"> 11 <ul id="list-nav" class="list-nav clearfix">
  12 +
11 {{# sortData}} 13 {{# sortData}}
12 <li {{#if @first}} class="active" {{/if}} data-id="{{sortId}}"> 14 <li {{#if @first}} class="active" {{/if}} data-id="{{sortId}}">
13 <a href="javascript:void(0);"> 15 <a href="javascript:void(0);">
@@ -15,6 +17,7 @@ @@ -15,6 +17,7 @@
15 </a> 17 </a>
16 </li> 18 </li>
17 {{/ sortData}} 19 {{/ sortData}}
  20 +
18 <li class="filter"> 21 <li class="filter">
19 <a href="javascript:void(0);"> 22 <a href="javascript:void(0);">
20 <span class="span-test">筛选</span> 23 <span class="span-test">筛选</span>
@@ -47,9 +50,11 @@ @@ -47,9 +50,11 @@
47 <div class="other-goods container hide clearfix"></div> 50 <div class="other-goods container hide clearfix"></div>
48 51
49 {{> common/filter}} 52 {{> common/filter}}
  53 +
50 </div> 54 </div>
51 55
52 {{> common/query-param}} 56 {{> common/query-param}}
53 57
54 {{> common/suspend-cart}} 58 {{> common/suspend-cart}}
  59 +
55 </div> 60 </div>
1 <div class="discount-page sale-page yoho-page"> 1 <div class="discount-page sale-page yoho-page">
  2 +
2 {{#content}} 3 {{#content}}
3 {{! 头部banner}} 4 {{! 头部banner}}
4 {{#if focus}} 5 {{#if focus}}
5 {{> resources/banner-top}} 6 {{> resources/banner-top}}
6 {{/if}} 7 {{/if}}
  8 +
7 {{! 两个小图}} 9 {{! 两个小图}}
8 {{#if smallPic}} 10 {{#if smallPic}}
9 {{> resources/thumb-row}} 11 {{> resources/thumb-row}}
10 {{/if}} 12 {{/if}}
11 {{/content}} 13 {{/content}}
  14 +
12 {{#floorHeader}} 15 {{#floorHeader}}
13 {{> common/floor-header}} 16 {{> common/floor-header}}
14 {{/floorHeader}} 17 {{/floorHeader}}
  18 +
15 <ul id="list-nav" class="list-nav clearfix"> 19 <ul id="list-nav" class="list-nav clearfix">
16 <li class="new active"> 20 <li class="new active">
17 <a href="javascript:void(0);"> 21 <a href="javascript:void(0);">
@@ -44,5 +48,6 @@ @@ -44,5 +48,6 @@
44 </li> 48 </li>
45 </ul> 49 </ul>
46 50
47 - {{> product/sale-common}} 51 + {{> product/sale/common}}
  52 +
48 </div> 53 </div>
1 <div class="sale-channel-page discount-page yoho-page"> 1 <div class="sale-channel-page discount-page yoho-page">
2 - {{> product/sale-banner}} 2 +
  3 + {{> product/sale/banner}}
  4 +
3 <ul id="list-nav" class="list-nav clearfix"> 5 <ul id="list-nav" class="list-nav clearfix">
4 <li class="all active"> 6 <li class="all active">
5 <a href="javascript:void(0);"> 7 <a href="javascript:void(0);">
@@ -31,5 +33,7 @@ @@ -31,5 +33,7 @@
31 </a> 33 </a>
32 </li> 34 </li>
33 </ul> 35 </ul>
34 - {{> product/sale-common}} 36 +
  37 + {{> product/sale/common}}
  38 +
35 </div> 39 </div>
1 <div class="sale-vip-page discount-page yoho-page"> 1 <div class="sale-vip-page discount-page yoho-page">
2 2
3 - {{> product/sale-banner}} 3 + {{> product/sale/banner}}
  4 +
4 <ul id="list-nav" class="list-nav clearfix"> 5 <ul id="list-nav" class="list-nav clearfix">
5 <li class="new active"> 6 <li class="new active">
6 <a href="javascript:void(0);"> 7 <a href="javascript:void(0);">
@@ -28,5 +29,7 @@ @@ -28,5 +29,7 @@
28 </a> 29 </a>
29 </li> 30 </li>
30 </ul> 31 </ul>
31 - {{> product/sale-common}} 32 +
  33 + {{> product/sale/common}}
  34 +
32 </div> 35 </div>
1 <div class="banner"> 1 <div class="banner">
  2 +
2 {{#content}} 3 {{#content}}
3 {{! 头部banner}} 4 {{! 头部banner}}
4 {{#if focus}} 5 {{#if focus}}
5 {{> resources/banner-top}} 6 {{> resources/banner-top}}
6 {{/if}} 7 {{/if}}
7 {{/content}} 8 {{/content}}
  9 +
8 {{# activity}} 10 {{# activity}}
9 <img src="{{image coverUrl 640 250}}"/> 11 <img src="{{image coverUrl 640 250}}"/>
10 <p class="activity-time" data-time-ms="{{leftTime}}"><i class="iconfont time-ico">&#xe603;</i><span>{{time}}</span></p> 12 <p class="activity-time" data-time-ms="{{leftTime}}"><i class="iconfont time-ico">&#xe603;</i><span>{{time}}</span></p>
11 {{/ activity}} 13 {{/ activity}}
  14 +
12 </div> 15 </div>
1 -<div id="thumb-row">  
2 - {{# data}}  
3 - <a href="{{url}}">  
4 - <img class="thumb-row-box lazy" data-original="{{image src 275 130}}">  
5 - </a>  
6 - {{/ data}}  
7 -</div>  
1 -/**  
2 - * 断码区  
3 - * @author: wsl<shuiling.wang@yoho.cn>  
4 - * @date: 2016/5/20  
5 - */  
6 -  
7 -var $ = require('yoho-jquery'),  
8 - Swiper = require('yoho-swiper'),  
9 - ellipsis = require('yoho-mlellipsis'),  
10 - lazyLoad = require('yoho-jquery-lazyload'),  
11 - tip = require('../plugin/tip'),  
12 - filter = require('../plugin/filter'),  
13 - loading = require('../plugin/loading');  
14 -  
15 -var $goodsContainer = $('#goods-container'),  
16 - $goodsChildren = $goodsContainer.children(),  
17 - $coatGc = $($goodsChildren.get(0)),  
18 - $trouserGc = $($goodsChildren.get(1)),  
19 - $shoesgc = $($goodsChildren.get(2)),  
20 - $othergc = $($goodsChildren.get(3));  
21 -  
22 -var winH = $(window).height(),  
23 - noResult = '<p class="no-result">未找到相关搜索结果</p>';  
24 -  
25 -// 默认筛选条件  
26 -var defaultOpt = require('./query-param');  
27 -  
28 -var storeOpt = $.extend({}, defaultOpt);  
29 -  
30 -var $listNav = $('#list-nav'),  
31 - $swiperSize = $('.swiper-size'),  
32 -  
33 - // 导航数据信息  
34 - navInfo = {  
35 - coat: {  
36 - reload: true,  
37 - page: 0,  
38 - end: false,  
39 - saleType: 1  
40 - },  
41 - trouser: {  
42 - reload: true,  
43 - page: 0,  
44 - end: false,  
45 - saleType: 1  
46 - },  
47 - shoes: {  
48 - reload: true,  
49 - page: 0,  
50 - end: false,  
51 - saleType: 1  
52 - },  
53 - other: {  
54 - reload: true,  
55 - page: 0,  
56 - end: false,  
57 - saleType: 1  
58 - }  
59 - },  
60 - $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项  
61 - searching;  
62 -  
63 -var swipers = [],  
64 - goodsType = ['coat', 'trouser', 'shoes', 'other'];  
65 -  
66 -require('./suspend-cart'); // 悬浮购物车  
67 -require('../common');  
68 -  
69 -ellipsis.init();  
70 -  
71 -lazyLoad($('img.lazy'));  
72 -  
73 -if ($('.banner-swiper .swiper-slide').length > 1) {  
74 - new Swiper('.swiper-container', {  
75 - lazyLoading: true,  
76 - lazyLoadingInPrevNext: true,  
77 - loop: true,  
78 - autoplay: 3000,  
79 - autoplayDisableOnInteraction: true,  
80 - paginationClickable: true,  
81 - pagination: '.banner-top .pagination-inner'  
82 - });  
83 -}  
84 -  
85 -$.each($swiperSize, function(key) {  
86 - swipers[key] = new Swiper('#size-swiper-' + key, {  
87 - slidesPerView: 'auto'  
88 - });  
89 -});  
90 -  
91 -$.each($listNav.find('li'), function(key, item) {  
92 - $(item).addClass(goodsType[key]);  
93 -});  
94 -  
95 -// 判断导航类型  
96 -function judgeType(dom) {  
97 - var navType;  
98 -  
99 - if (dom.hasClass('coat')) {  
100 - navType = 'coat';  
101 - } else if (dom.hasClass('trouser')) {  
102 - navType = 'trouser';  
103 - } else if (dom.hasClass('shoes')) {  
104 - navType = 'shoes';  
105 - } else {  
106 - navType = 'other';  
107 - }  
108 -  
109 - return navType;  
110 -}  
111 -  
112 -/**  
113 - * 筛选注册的回调,筛选子项点击后逻辑  
114 - * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载  
115 - * @param opt {type, id}  
116 - */  
117 -function search(opt) {  
118 - var setting = {},  
119 - ext = {},  
120 - att,  
121 - nav, navType,  
122 - page,  
123 - i;  
124 -  
125 - delete defaultOpt.size;  
126 -  
127 - if (searching) {  
128 - return;  
129 - }  
130 -  
131 - if ($.type(opt) === 'object') {  
132 - opt = [opt];  
133 - }  
134 -  
135 - if (opt) {  
136 -  
137 - // 筛选项变更则重置reload为true  
138 - for (att in navInfo) {  
139 - if (navInfo.hasOwnProperty(att)) {  
140 - navInfo[att].reload = true;  
141 - }  
142 - }  
143 - for (i = 0; i < opt.length; i++) {  
144 - switch (opt[i].type) {  
145 - case 'gender':  
146 - ext = {  
147 - gender: opt[i].id  
148 - };  
149 - break;  
150 - case 'brand':  
151 - ext = {  
152 - brand: opt[i].id  
153 - };  
154 - break;  
155 - case 'sort':  
156 - ext = {  
157 - sort: opt[i].id  
158 - };  
159 - break;  
160 - case 'color':  
161 - ext = {  
162 - color: opt[i].id  
163 - };  
164 - break;  
165 - case 'size':  
166 - ext = {  
167 - size: opt[i].id  
168 - };  
169 - break;  
170 - case 'price':  
171 - ext = {  
172 - price: opt[i].id  
173 - };  
174 - break;  
175 - case 'discount':  
176 - ext = {  
177 - discount: opt[i].id  
178 - };  
179 - break;  
180 - case 'p_d':  
181 - ext = {  
182 - p_d: opt[i].id  
183 - };  
184 - break;  
185 - default:  
186 - break;  
187 - }  
188 - }  
189 -  
190 - $.extend(defaultOpt, ext); // 扩展筛选项  
191 - }  
192 -  
193 - // 导航类别  
194 - navType = judgeType($pre);  
195 -  
196 - nav = navInfo[navType];  
197 - page = nav.page + 1;  
198 - if (nav.reload) {  
199 - page = 1;  
200 - } else if (nav.end) {  
201 -  
202 - // 不需要重新加载并且数据请求结束  
203 - return;  
204 - }  
205 -  
206 - $.extend(setting, defaultOpt, {  
207 - type: 'stock',  
208 - order: 0,  
209 - page: page  
210 - });  
211 -  
212 - searching = true;  
213 - loading.showLoadingMask();  
214 -  
215 - $.ajax({  
216 - type: 'GET',  
217 - url: '/product/sale/search',  
218 - data: setting,  
219 - success: function(data) {  
220 - var $container,  
221 - num;  
222 -  
223 - switch (navType) {  
224 - case 'coat':  
225 - $container = $coatGc;  
226 - break;  
227 - case 'trouser':  
228 - $container = $trouserGc;  
229 - break;  
230 - case 'shoes':  
231 - $container = $shoesgc;  
232 - break;  
233 - default:  
234 - $container = $othergc;  
235 - break;  
236 - }  
237 -  
238 - if ($container.hasClass('hide')) {  
239 - $container.siblings().addClass('hide');  
240 - $container.removeClass('hide');  
241 - }  
242 -  
243 - if (data === '') {  
244 - nav.end = true;  
245 -  
246 - if (nav.reload) {  
247 - $container.html(noResult);  
248 - }  
249 - } else {  
250 - if (nav.reload) {  
251 - $container.html(data);  
252 - lazyLoad($container.find('.lazy'));  
253 - } else {  
254 - num = $container.find('.good-info').length;  
255 - $container.append(data);  
256 -  
257 - // lazy good-infos who append in  
258 - lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy'));  
259 - }  
260 - }  
261 -  
262 - nav.reload = false;  
263 - nav.page = page;  
264 -  
265 - searching = false;  
266 - loading.hideLoadingMask();  
267 -  
268 - window.rePosFooter();  
269 -  
270 - $('.good-detail-text .name').each(function() {  
271 - var $this = $(this),  
272 - $title = $this.find('a');  
273 -  
274 - $title[0].mlellipsis(2);  
275 - });  
276 - },  
277 - error: function() {  
278 - tip.show('网络断开连接了~');  
279 - searching = false;  
280 - loading.hideLoadingMask();  
281 - }  
282 - });  
283 -  
284 -}  
285 -  
286 -$.ajax({  
287 - type: 'GET',  
288 - url: '/product/sale/filter',  
289 - data: $.extend(defaultOpt, {  
290 - saleType: '1'  
291 - }),  
292 - success: function(data) {  
293 - $goodsContainer.append(data);  
294 -  
295 - // 初始化filter&注册filter回调  
296 - filter.initFilter({  
297 - fCbFn: search,  
298 - hCbFn: function() {  
299 -  
300 - // 切换active状态到$pre上  
301 - $pre.addClass('active');  
302 - $pre.siblings('.filter').removeClass('active');  
303 -  
304 - $('#size-swiper-' + $pre.index()).show();  
305 - },  
306 - missStatus: true  
307 - });  
308 - }  
309 -});  
310 -lazyLoad($('.lazy'));  
311 -  
312 -$listNav.bind('contextmenu', function() {  
313 - return false;  
314 -});  
315 -  
316 -$listNav.on('touchend touchcancel', function(e) {  
317 - var $this = $(e.target).closest('li'),  
318 - nav, sortId, navType, $active;  
319 -  
320 - e.preventDefault();  
321 - if ($this.hasClass('filter')) {  
322 -  
323 - // 筛选面板切换状态  
324 - if ($this.hasClass('active')) {  
325 - filter.hideFilter();  
326 -  
327 - // 点击筛选钱的active项回复active  
328 - $pre.addClass('active');  
329 - $this.removeClass('active');  
330 - } else {  
331 - $pre = $this.siblings('.active');  
332 - $swiperSize.hide();  
333 - $pre.removeClass('active');  
334 - $this.addClass('active');  
335 - filter.showFilter();  
336 - }  
337 - } else {  
338 -  
339 - // 导航类别  
340 - navType = judgeType($this);  
341 -  
342 - nav = navInfo[navType];  
343 -  
344 - if (!($this.hasClass('active'))) {  
345 -  
346 - $active = $this.siblings('.active');  
347 -  
348 - $pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项  
349 -  
350 - if ($active.hasClass('filter')) {  
351 -  
352 - // 若之前active项为筛选,则隐藏筛选面板  
353 - filter.hideFilter();  
354 - } else {  
355 -  
356 - // 切换container显示  
357 - $goodsContainer.children('.container:not(.hide)').addClass('hide');  
358 -  
359 - switch (navType) {  
360 - case 'coat':  
361 - $coatGc.removeClass('hide');  
362 - break;  
363 -  
364 - case 'trouser':  
365 - $trouserGc.removeClass('hide');  
366 - break;  
367 -  
368 - case 'shoes':  
369 - $shoesgc.removeClass('hide');  
370 - break;  
371 - case 'other':  
372 - $othergc.removeClass('hide');  
373 - break;  
374 - default:  
375 - break;  
376 - }  
377 -  
378 - // 重置筛选项  
379 - filter.resetFilter();  
380 - defaultOpt = $.extend({}, storeOpt);  
381 - }  
382 -  
383 - $active.removeClass('active');  
384 - $this.addClass('active');  
385 - sortId = $this.data('id');  
386 - $swiperSize.hide();  
387 - $('#size-swiper-' + $this.index()).show();  
388 - swipers[$this.index()].onResize();  
389 - }  
390 -  
391 - if (nav.reload) {  
392 - search([{  
393 - type: 'sort',  
394 - id: sortId  
395 - }]);  
396 - }  
397 - }  
398 - e.stopPropagation();  
399 -});  
400 -  
401 -$swiperSize.on('touchend touchcancel', function(e) {  
402 - var $this = $(e.target).closest('li'),  
403 - index = $this.parents('.swiper-size').index(),  
404 - $parentType = $listNav.find('li').eq(index),  
405 - nav, sortId, sizeId, navType, $active;  
406 -  
407 - e.preventDefault();  
408 -  
409 - if (typeof $this === 'undefined' || $this.length === 0) {  
410 - return;  
411 - }  
412 -  
413 - // 导航类别  
414 - navType = judgeType($parentType);  
415 -  
416 - nav = navInfo[navType];  
417 -  
418 - if ($this.hasClass('active')) {  
419 - return;  
420 - } else {  
421 - nav.reload = true;  
422 - $active = $this.siblings('.active');  
423 - $pre = $parentType; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项  
424 - $active.removeClass('active');  
425 - $this.addClass('active');  
426 - sortId = $parentType.data('id');  
427 - sizeId = $this.data('id');  
428 - }  
429 -  
430 - if (nav.reload) {  
431 - search([{  
432 - type: 'sort',  
433 - id: sortId  
434 - }, {  
435 - type: 'size',  
436 - id: sizeId  
437 - }]);  
438 - }  
439 - e.stopPropagation();  
440 -});  
441 -  
442 -function scrollHandler() {  
443 -  
444 - // 当scroll到1/4$goodsContainer高度后继续请求下一页数据  
445 - if ($(window).scrollTop() + winH >  
446 - $(document).height() - 0.25 * $goodsContainer.height() - 50) {  
447 - if (typeof($pre) !== 'undefined') {  
448 - search();  
449 - }  
450 - }  
451 -}  
452 -  
453 -// srcoll to load more  
454 -$(window).scroll(function() {  
455 - window.requestAnimationFrame(scrollHandler);  
456 -});  
457 -  
458 -// 初始请求最新第一页数据  
459 -search([{  
460 - type: 'sort',  
461 - id: $('.coat').data('id')  
462 -}]);  
463 -  
464 -$listNav.on('touchstart', 'li', function() {  
465 - $(this).addClass('bytouch');  
466 -}).on('touchend touchcancel', function() {  
467 - $listNav.find('li').removeClass('bytouch');  
468 -});  
1 -require('./break-code'); 1 +/**
  2 + * 断码区
  3 + * @author: wsl<shuiling.wang@yoho.cn>
  4 + * @date: 2016/5/20
  5 + */
  6 +
  7 +var $ = require('yoho-jquery'),
  8 + Swiper = require('yoho-swiper'),
  9 + ellipsis = require('yoho-mlellipsis'),
  10 + lazyLoad = require('yoho-jquery-lazyload'),
  11 + tip = require('../plugin/tip'),
  12 + filter = require('../plugin/filter'),
  13 + loading = require('../plugin/loading');
  14 +
  15 +var $goodsContainer = $('#goods-container'),
  16 + $goodsChildren = $goodsContainer.children(),
  17 + $coatGc = $($goodsChildren.get(0)),
  18 + $trouserGc = $($goodsChildren.get(1)),
  19 + $shoesgc = $($goodsChildren.get(2)),
  20 + $othergc = $($goodsChildren.get(3));
  21 +
  22 +var winH = $(window).height(),
  23 + noResult = '<p class="no-result">未找到相关搜索结果</p>';
  24 +
  25 +// 默认筛选条件
  26 +var defaultOpt = require('../common/query-param');
  27 +
  28 +var storeOpt = $.extend({}, defaultOpt);
  29 +
  30 +var $listNav = $('#list-nav'),
  31 + $swiperSize = $('.swiper-size'),
  32 +
  33 + // 导航数据信息
  34 + navInfo = {
  35 + coat: {
  36 + reload: true,
  37 + page: 0,
  38 + end: false,
  39 + saleType: 1
  40 + },
  41 + trouser: {
  42 + reload: true,
  43 + page: 0,
  44 + end: false,
  45 + saleType: 1
  46 + },
  47 + shoes: {
  48 + reload: true,
  49 + page: 0,
  50 + end: false,
  51 + saleType: 1
  52 + },
  53 + other: {
  54 + reload: true,
  55 + page: 0,
  56 + end: false,
  57 + saleType: 1
  58 + }
  59 + },
  60 + $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
  61 + searching;
  62 +
  63 +var swipers = [],
  64 + goodsType = ['coat', 'trouser', 'shoes', 'other'];
  65 +
  66 +require('../common/suspend-cart'); // 悬浮购物车
  67 +require('../common');
  68 +
  69 +ellipsis.init();
  70 +
  71 +lazyLoad($('img.lazy'));
  72 +
  73 +if ($('.banner-swiper .swiper-slide').length > 1) {
  74 + new Swiper('.swiper-container', {
  75 + lazyLoading: true,
  76 + lazyLoadingInPrevNext: true,
  77 + loop: true,
  78 + autoplay: 3000,
  79 + autoplayDisableOnInteraction: true,
  80 + paginationClickable: true,
  81 + pagination: '.banner-top .pagination-inner'
  82 + });
  83 +}
  84 +
  85 +$.each($swiperSize, function(key) {
  86 + swipers[key] = new Swiper('#size-swiper-' + key, {
  87 + slidesPerView: 'auto'
  88 + });
  89 +});
  90 +
  91 +$.each($listNav.find('li'), function(key, item) {
  92 + $(item).addClass(goodsType[key]);
  93 +});
  94 +
  95 +// 判断导航类型
  96 +function judgeType(dom) {
  97 + var navType;
  98 +
  99 + if (dom.hasClass('coat')) {
  100 + navType = 'coat';
  101 + } else if (dom.hasClass('trouser')) {
  102 + navType = 'trouser';
  103 + } else if (dom.hasClass('shoes')) {
  104 + navType = 'shoes';
  105 + } else {
  106 + navType = 'other';
  107 + }
  108 +
  109 + return navType;
  110 +}
  111 +
  112 +/**
  113 + * 筛选注册的回调,筛选子项点击后逻辑
  114 + * 需要执行search的场景:1.点选筛选项;2.relaod为true时切换导航;3.下拉加载
  115 + * @param opt {type, id}
  116 + */
  117 +function search(opt) {
  118 + var setting = {},
  119 + ext = {},
  120 + att,
  121 + nav, navType,
  122 + page,
  123 + i;
  124 +
  125 + delete defaultOpt.size;
  126 +
  127 + if (searching) {
  128 + return;
  129 + }
  130 +
  131 + if ($.type(opt) === 'object') {
  132 + opt = [opt];
  133 + }
  134 +
  135 + if (opt) {
  136 +
  137 + // 筛选项变更则重置reload为true
  138 + for (att in navInfo) {
  139 + if (navInfo.hasOwnProperty(att)) {
  140 + navInfo[att].reload = true;
  141 + }
  142 + }
  143 + for (i = 0; i < opt.length; i++) {
  144 + switch (opt[i].type) {
  145 + case 'gender':
  146 + ext = {
  147 + gender: opt[i].id
  148 + };
  149 + break;
  150 + case 'brand':
  151 + ext = {
  152 + brand: opt[i].id
  153 + };
  154 + break;
  155 + case 'sort':
  156 + ext = {
  157 + sort: opt[i].id
  158 + };
  159 + break;
  160 + case 'color':
  161 + ext = {
  162 + color: opt[i].id
  163 + };
  164 + break;
  165 + case 'size':
  166 + ext = {
  167 + size: opt[i].id
  168 + };
  169 + break;
  170 + case 'price':
  171 + ext = {
  172 + price: opt[i].id
  173 + };
  174 + break;
  175 + case 'discount':
  176 + ext = {
  177 + discount: opt[i].id
  178 + };
  179 + break;
  180 + case 'p_d':
  181 + ext = {
  182 + p_d: opt[i].id
  183 + };
  184 + break;
  185 + default:
  186 + break;
  187 + }
  188 + }
  189 +
  190 + $.extend(defaultOpt, ext); // 扩展筛选项
  191 + }
  192 +
  193 + // 导航类别
  194 + navType = judgeType($pre);
  195 +
  196 + nav = navInfo[navType];
  197 + page = nav.page + 1;
  198 + if (nav.reload) {
  199 + page = 1;
  200 + } else if (nav.end) {
  201 +
  202 + // 不需要重新加载并且数据请求结束
  203 + return;
  204 + }
  205 +
  206 + $.extend(setting, defaultOpt, {
  207 + type: 'stock',
  208 + order: 0,
  209 + page: page
  210 + });
  211 +
  212 + searching = true;
  213 + loading.showLoadingMask();
  214 +
  215 + $.ajax({
  216 + type: 'GET',
  217 + url: '/product/sale/search',
  218 + data: setting,
  219 + success: function(data) {
  220 + var $container,
  221 + num;
  222 +
  223 + switch (navType) {
  224 + case 'coat':
  225 + $container = $coatGc;
  226 + break;
  227 + case 'trouser':
  228 + $container = $trouserGc;
  229 + break;
  230 + case 'shoes':
  231 + $container = $shoesgc;
  232 + break;
  233 + default:
  234 + $container = $othergc;
  235 + break;
  236 + }
  237 +
  238 + if ($container.hasClass('hide')) {
  239 + $container.siblings().addClass('hide');
  240 + $container.removeClass('hide');
  241 + }
  242 +
  243 + if (data === '') {
  244 + nav.end = true;
  245 +
  246 + if (nav.reload) {
  247 + $container.html(noResult);
  248 + }
  249 + } else {
  250 + if (nav.reload) {
  251 + $container.html(data);
  252 + lazyLoad($container.find('.lazy'));
  253 + } else {
  254 + num = $container.find('.good-info').length;
  255 + $container.append(data);
  256 +
  257 + // lazy good-infos who append in
  258 + lazyLoad($container.find('.good-info:gt(' + (num - 1) + ') .lazy'));
  259 + }
  260 + }
  261 +
  262 + nav.reload = false;
  263 + nav.page = page;
  264 +
  265 + searching = false;
  266 + loading.hideLoadingMask();
  267 +
  268 + window.rePosFooter();
  269 +
  270 + $('.good-detail-text .name').each(function() {
  271 + var $this = $(this),
  272 + $title = $this.find('a');
  273 +
  274 + $title[0].mlellipsis(2);
  275 + });
  276 + },
  277 + error: function() {
  278 + tip.show('网络断开连接了~');
  279 + searching = false;
  280 + loading.hideLoadingMask();
  281 + }
  282 + });
  283 +
  284 +}
  285 +
  286 +$.ajax({
  287 + type: 'GET',
  288 + url: '/product/sale/filter',
  289 + data: $.extend(defaultOpt, {
  290 + saleType: '1'
  291 + }),
  292 + success: function(data) {
  293 + $goodsContainer.append(data);
  294 +
  295 + // 初始化filter&注册filter回调
  296 + filter.initFilter({
  297 + fCbFn: search,
  298 + hCbFn: function() {
  299 +
  300 + // 切换active状态到$pre上
  301 + $pre.addClass('active');
  302 + $pre.siblings('.filter').removeClass('active');
  303 +
  304 + $('#size-swiper-' + $pre.index()).show();
  305 + },
  306 + missStatus: true
  307 + });
  308 + }
  309 +});
  310 +lazyLoad($('.lazy'));
  311 +
  312 +$listNav.bind('contextmenu', function() {
  313 + return false;
  314 +});
  315 +
  316 +$listNav.on('touchend touchcancel', function(e) {
  317 + var $this = $(e.target).closest('li'),
  318 + nav, sortId, navType, $active;
  319 +
  320 + e.preventDefault();
  321 + if ($this.hasClass('filter')) {
  322 +
  323 + // 筛选面板切换状态
  324 + if ($this.hasClass('active')) {
  325 + filter.hideFilter();
  326 +
  327 + // 点击筛选钱的active项回复active
  328 + $pre.addClass('active');
  329 + $this.removeClass('active');
  330 + } else {
  331 + $pre = $this.siblings('.active');
  332 + $swiperSize.hide();
  333 + $pre.removeClass('active');
  334 + $this.addClass('active');
  335 + filter.showFilter();
  336 + }
  337 + } else {
  338 +
  339 + // 导航类别
  340 + navType = judgeType($this);
  341 +
  342 + nav = navInfo[navType];
  343 +
  344 + if (!($this.hasClass('active'))) {
  345 +
  346 + $active = $this.siblings('.active');
  347 +
  348 + $pre = $this; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
  349 +
  350 + if ($active.hasClass('filter')) {
  351 +
  352 + // 若之前active项为筛选,则隐藏筛选面板
  353 + filter.hideFilter();
  354 + } else {
  355 +
  356 + // 切换container显示
  357 + $goodsContainer.children('.container:not(.hide)').addClass('hide');
  358 +
  359 + switch (navType) {
  360 + case 'coat':
  361 + $coatGc.removeClass('hide');
  362 + break;
  363 +
  364 + case 'trouser':
  365 + $trouserGc.removeClass('hide');
  366 + break;
  367 +
  368 + case 'shoes':
  369 + $shoesgc.removeClass('hide');
  370 + break;
  371 + case 'other':
  372 + $othergc.removeClass('hide');
  373 + break;
  374 + default:
  375 + break;
  376 + }
  377 +
  378 + // 重置筛选项
  379 + filter.resetFilter();
  380 + defaultOpt = $.extend({}, storeOpt);
  381 + }
  382 +
  383 + $active.removeClass('active');
  384 + $this.addClass('active');
  385 + sortId = $this.data('id');
  386 + $swiperSize.hide();
  387 + $('#size-swiper-' + $this.index()).show();
  388 + swipers[$this.index()].onResize();
  389 + }
  390 +
  391 + if (nav.reload) {
  392 + search([{
  393 + type: 'sort',
  394 + id: sortId
  395 + }]);
  396 + }
  397 + }
  398 + e.stopPropagation();
  399 +});
  400 +
  401 +$swiperSize.on('touchend touchcancel', function(e) {
  402 + var $this = $(e.target).closest('li'),
  403 + index = $this.parents('.swiper-size').index(),
  404 + $parentType = $listNav.find('li').eq(index),
  405 + nav, sortId, sizeId, navType, $active;
  406 +
  407 + e.preventDefault();
  408 +
  409 + if (typeof $this === 'undefined' || $this.length === 0) {
  410 + return;
  411 + }
  412 +
  413 + // 导航类别
  414 + navType = judgeType($parentType);
  415 +
  416 + nav = navInfo[navType];
  417 +
  418 + if ($this.hasClass('active')) {
  419 + return;
  420 + } else {
  421 + nav.reload = true;
  422 + $active = $this.siblings('.active');
  423 + $pre = $parentType; // $pre为除筛选导航的其他导航项,若当前active的为筛选,则把$pre置为当前点击项
  424 + $active.removeClass('active');
  425 + $this.addClass('active');
  426 + sortId = $parentType.data('id');
  427 + sizeId = $this.data('id');
  428 + }
  429 +
  430 + if (nav.reload) {
  431 + search([{
  432 + type: 'sort',
  433 + id: sortId
  434 + }, {
  435 + type: 'size',
  436 + id: sizeId
  437 + }]);
  438 + }
  439 + e.stopPropagation();
  440 +});
  441 +
  442 +function scrollHandler() {
  443 +
  444 + // 当scroll到1/4$goodsContainer高度后继续请求下一页数据
  445 + if ($(window).scrollTop() + winH >
  446 + $(document).height() - 0.25 * $goodsContainer.height() - 50) {
  447 + if (typeof $pre !== 'undefined') {
  448 + search();
  449 + }
  450 + }
  451 +}
  452 +
  453 +// srcoll to load more
  454 +$(window).scroll(function() {
  455 + window.requestAnimationFrame(scrollHandler);
  456 +});
  457 +
  458 +// 初始请求最新第一页数据
  459 +search([{
  460 + type: 'sort',
  461 + id: $('.coat').data('id')
  462 +}]);
  463 +
  464 +$listNav.on('touchstart', 'li', function() {
  465 + $(this).addClass('bytouch');
  466 +}).on('touchend touchcancel', function() {
  467 + $listNav.find('li').removeClass('bytouch');
  468 +});
1 -/**  
2 - * 商品列表页  
3 - * @author: wsl<shuiling.wang@yoho.cn>  
4 - * @date: 2016/5/17  
5 - */  
6 -  
7 -var $ = require('yoho-jquery'),  
8 - Swiper = require('yoho-swiper');  
9 -  
10 -require('./search');  
11 -  
12 -if ($('.swiper-container .swiper-slide').length > 1) {  
13 - new Swiper('.swiper-container', {  
14 - lazyLoading: true,  
15 - lazyLoadingInPrevNext: true,  
16 - loop: true,  
17 - autoplay: 3000,  
18 - autoplayDisableOnInteraction: true,  
19 - paginationClickable: true,  
20 - pagination: '.banner-top .pagination-inner'  
21 - });  
22 -}  
1 -require('./sale'); 1 +/**
  2 + * 商品列表页
  3 + * @author: wsl<shuiling.wang@yoho.cn>
  4 + * @date: 2016/5/17
  5 + */
  6 +
  7 +var $ = require('yoho-jquery'),
  8 + Swiper = require('yoho-swiper');
  9 +
  10 +require('./sale/search');
  11 +
  12 +if ($('.swiper-container .swiper-slide').length > 1) {
  13 + new Swiper('.swiper-container', {
  14 + lazyLoading: true,
  15 + lazyLoadingInPrevNext: true,
  16 + loop: true,
  17 + autoplay: 3000,
  18 + autoplayDisableOnInteraction: true,
  19 + paginationClickable: true,
  20 + pagination: '.banner-top .pagination-inner'
  21 + });
  22 +}
@@ -6,22 +6,22 @@ @@ -6,22 +6,22 @@
6 var $ = require('yoho-jquery'), 6 var $ = require('yoho-jquery'),
7 ellipsis = require('yoho-mlellipsis'), 7 ellipsis = require('yoho-mlellipsis'),
8 lazyLoad = require('yoho-jquery-lazyload'), 8 lazyLoad = require('yoho-jquery-lazyload'),
9 - tip = require('../plugin/tip'),  
10 - filter = require('../plugin/filter'),  
11 - loading = require('../plugin/loading'); 9 + tip = require('../../plugin/tip'),
  10 + filter = require('../../plugin/filter'),
  11 + loading = require('../../plugin/loading');
12 12
13 var $goodsContainer = $('#goods-container'), 13 var $goodsContainer = $('#goods-container'),
14 - $ngc = $($goodsContainer.find('.new-goods')),  
15 - $dgc = $($goodsContainer.find('.discount-goods')),  
16 - $pgc = $($goodsContainer.find('.price-goods')),  
17 - $agc = $($goodsContainer.find('.all-goods')),  
18 - $sgc = $($goodsContainer.find('.sale-goods')); 14 + $ngc = $goodsContainer.find('.new-goods'),
  15 + $dgc = $goodsContainer.find('.discount-goods'),
  16 + $pgc = $goodsContainer.find('.price-goods'),
  17 + $agc = $goodsContainer.find('.all-goods'),
  18 + $sgc = $goodsContainer.find('.sale-goods');
19 19
20 var winH = $(window).height(), 20 var winH = $(window).height(),
21 noResult = '<p class="no-result">未找到相关搜索结果</p>'; 21 noResult = '<p class="no-result">未找到相关搜索结果</p>';
22 22
23 // 默认筛选条件 23 // 默认筛选条件
24 -var defaultOpt = require('./query-param'); 24 +var defaultOpt = require('../../common/query-param');
25 25
26 var $listNav = $('#list-nav'), 26 var $listNav = $('#list-nav'),
27 27
@@ -61,8 +61,8 @@ var $listNav = $('#list-nav'), @@ -61,8 +61,8 @@ var $listNav = $('#list-nav'),
61 $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项 61 $pre = $listNav.find('.active'), // 纪录进入筛选前的active项,初始为选中项
62 searching; 62 searching;
63 63
64 -require('./suspend-cart'); // 悬浮购物车  
65 -require('../common'); 64 +require('../../common/suspend-cart'); // 悬浮购物车
  65 +require('../../common');
66 66
67 ellipsis.init(); 67 ellipsis.init();
68 68
@@ -426,7 +426,7 @@ function scrollHandler() { @@ -426,7 +426,7 @@ function scrollHandler() {
426 // 当scroll到1/4$goodsContainer高度后继续请求下一页数据 426 // 当scroll到1/4$goodsContainer高度后继续请求下一页数据
427 if ($(window).scrollTop() + winH > 427 if ($(window).scrollTop() + winH >
428 $(document).height() - 0.25 * $goodsContainer.height() - 50) { 428 $(document).height() - 0.25 * $goodsContainer.height() - 50) {
429 - if (typeof($pre) !== 'undefined') { 429 + if (typeof $pre !== 'undefined') {
430 search(); 430 search();
431 } 431 }
432 } 432 }
@@ -9,7 +9,7 @@ var $ = require('yoho-jquery'), @@ -9,7 +9,7 @@ var $ = require('yoho-jquery'),
9 var $activityTime = $('.activity-time'), 9 var $activityTime = $('.activity-time'),
10 endTime = $activityTime.data('time-ms'); 10 endTime = $activityTime.data('time-ms');
11 11
12 -require('./search'); 12 +require('./sale/search');
13 13
14 lazyLoad($('img.lazy')); 14 lazyLoad($('img.lazy'));
15 15
1 -require('./search'); 1 +require('./sale/search');
  1 +@import "good";
  2 +@import "filter";
  3 +@import "suspend-cart";
@@ -10,12 +10,6 @@ @@ -10,12 +10,6 @@
10 @import "product/comments-consults"; 10 @import "product/comments-consults";
11 @import "product/product-description"; 11 @import "product/product-description";
12 @import "product/recommend-for-you"; 12 @import "product/recommend-for-you";
13 -@import "product/sale";  
14 -@import "product/special";  
15 -@import "product/special-detail";  
16 -@import "product/break-code";  
17 -@import "product/discount";  
18 -@import "product/good";  
19 -@import "product/filter";  
20 -@import "product/suspend-cart"; 13 +@import "product/index";
  14 +@import "common/index";
21 @import "cart/chose-panel"; 15 @import "cart/chose-panel";
  1 +@import "sale/index";
  1 +@import "break-code";
  2 +@import "discount";
  3 +@import "sale";
  4 +@import "special";
  5 +@import "special-detail";
1 .sale-page { 1 .sale-page {
2 overflow: hidden; 2 overflow: hidden;
  3 + background-color: #fff;
3 4
4 .banner-top .swiper-container { 5 .banner-top .swiper-container {
5 height: 200px; 6 height: 200px;