Authored by zhangxiaoru

全部分类

@@ -59,7 +59,7 @@ const brandList = (req, res, next) => { @@ -59,7 +59,7 @@ const brandList = (req, res, next) => {
59 res.render('brand/brand-list', { 59 res.render('brand/brand-list', {
60 layout: false, 60 layout: false,
61 brandList: result.brandList 61 brandList: result.brandList
62 - }) 62 + });
63 }).catch(next); 63 }).catch(next);
64 }; 64 };
65 65
@@ -67,13 +67,13 @@ const categoryData = (req, res, next) => { @@ -67,13 +67,13 @@ const categoryData = (req, res, next) => {
67 let code; 67 let code;
68 let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1; 68 let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
69 69
70 - if (parseInt(gender) === 1) { 70 + if (parseInt(gender, 10) === 1) {
71 code = '7f885e9cab53231cff34ea236f3f1120'; 71 code = '7f885e9cab53231cff34ea236f3f1120';
72 } else { 72 } else {
73 code = 'a6f9dc00219eb7d08520a18864929a30'; 73 code = 'a6f9dc00219eb7d08520a18864929a30';
74 } 74 }
75 75
76 - brandModel.categoryData(code, gender).then(result => { 76 + brandModel.categoryData(code).then(result => {
77 res.render('brand/category', { 77 res.render('brand/category', {
78 layout: false, 78 layout: false,
79 categoryData: result.categoryData 79 categoryData: result.categoryData
@@ -96,8 +96,8 @@ const cateAll = (req, res, next) => { @@ -96,8 +96,8 @@ const cateAll = (req, res, next) => {
96 } 96 }
97 // showFooterTab: footerModel.getUrlData('category') 97 // showFooterTab: footerModel.getUrlData('category')
98 }); 98 });
99 - }).catch(next);  
100 -} 99 + }).catch(next);
  100 +};
101 101
102 module.exports = { 102 module.exports = {
103 index, 103 index,
@@ -277,29 +277,29 @@ const brandListData = (code, gender) => { @@ -277,29 +277,29 @@ const brandListData = (code, gender) => {
277 277
278 list.brandList = brandList; 278 list.brandList = brandList;
279 return list; 279 return list;
280 - })  
281 -} 280 + });
  281 +};
282 282
283 -const categoryData = (code, gender) => { 283 +const categoryData = (code) => {
284 284
285 return _getResourcesData(code).then(result => { 285 return _getResourcesData(code).then(result => {
286 - let categoryData = {}; 286 + let category = {};
287 let list = {}; 287 let list = {};
288 288
289 if (result) { 289 if (result) {
290 _.forEach(result, function(data) { 290 _.forEach(result, function(data) {
291 if (data.template_name === 'recommend_content_five') { 291 if (data.template_name === 'recommend_content_five') {
292 - categoryData.list = data.data.list; 292 + category.list = data.data.list;
293 } else if (data.template_name === 'focus') { 293 } else if (data.template_name === 'focus') {
294 - categoryData.focusData = data; 294 + category.focusData = data;
295 } 295 }
296 }); 296 });
297 } 297 }
298 298
299 - list.categoryData = categoryData; 299 + list.categoryData = category;
300 return list; 300 return list;
301 }); 301 });
302 -} 302 +};
303 303
304 const getCateData = (channel) => { 304 const getCateData = (channel) => {
305 return api.get('', { 305 return api.get('', {
@@ -321,12 +321,12 @@ const getCateData = (channel) => { @@ -321,12 +321,12 @@ const getCateData = (channel) => {
321 return result.data; 321 return result.data;
322 }).then((list) => { 322 }).then((list) => {
323 return _processCateData(list, channel); 323 return _processCateData(list, channel);
324 - });  
325 -} 324 + });
  325 +};
326 326
327 module.exports = { 327 module.exports = {
328 indexData, 328 indexData,
329 brandListData, 329 brandListData,
330 categoryData, 330 categoryData,
331 getCateData 331 getCateData
332 -};  
  332 +};
1 -/**  
2 - * 分类  
3 - * @author: xuqi<qi.xu@yoho.cn>  
4 - * @date: 2015/10/14  
5 - */  
6 -  
7 -var $ = require('yoho-jquery');  
8 -var FastClick = require('yoho-fastclick');  
9 -  
10 -var $nav = $('.category-nav'),  
11 - $search = $('#search-input'),  
12 - $categoryContainer = $('.category-container'),  
13 - $contents = $categoryContainer.children('.content'),  
14 - $subLevelItem = $categoryContainer.find('.sub-level li'),  
15 - $primaryItem = $categoryContainer.find('.primary-level li');  
16 -  
17 -require('../common');  
18 -  
19 -$(function() {  
20 - FastClick.attach(document.body);  
21 -});  
22 -  
23 -function resetHeight() {  
24 - var h = document.body.scrollHeight - $search.outerHeight() - $nav.outerHeight();  
25 -  
26 - $contents.height(h);  
27 -}  
28 -resetHeight();  
29 -  
30 -$search.focus(function() {  
31 - $(this).blur();  
32 -});  
33 -$nav.on('contextmenu', function() {  
34 - return false;  
35 -});  
36 -$('.category-container').on('contextmenu', function() {  
37 - return false;  
38 -});  
39 -  
40 -$nav.on('touchend touchcancel', function(e) {  
41 - var $this = $(e.target).closest('li'),  
42 - selector = '.' + $this.data('channel');  
43 -  
44 - if ($this.hasClass('focus')) {  
45 - return;  
46 - }  
47 -  
48 - $nav.find('li.focus').removeClass('focus');  
49 - $this.addClass('focus');  
50 -  
51 - $contents.addClass('hide');  
52 - $contents.filter(selector).removeClass('hide');  
53 -});  
54 -  
55 -$categoryContainer.on('click', function(e) {  
56 - var $this = $(e.target),  
57 - $subLevel,  
58 - $cur, index;  
59 -  
60 - $cur = $this.closest('.p-level-item');  
61 -  
62 - // 第一次单击右则空白处,出现冒泡  
63 - if ($(e.target).closest('.sub-level').length <= 0) {  
64 - e.preventDefault();  
65 - }  
66 -  
67 - if ($this[0] && $this[0].tagName === 'LI' && $this.find('a').attr('href')) {  
68 - location.href = $this.find('a').attr('href');  
69 - }  
70 -  
71 - if ($this[0] && $this[0].tagName === 'A' && $this.attr('href')) {  
72 - location.href = $this.attr('href');  
73 - }  
74 -  
75 - if ($cur.length > 0) {  
76 - index = $cur.index();  
77 - $subLevel = $this.closest('.content').find('.sub-level');  
78 -  
79 - if ($this.hasClass('focus')) {  
80 - return;  
81 - }  
82 -  
83 - $this.closest('.primary-level').children('.focus').removeClass('focus');  
84 - $this.addClass('focus');  
85 -  
86 - $subLevel.not('.hide').addClass('hide');  
87 - $subLevel.eq(index).removeClass('hide');  
88 - }  
89 -});  
90 -  
91 -$categoryContainer.find('.primary-level').on('touchstart touchend touchcancel', 'li', function() {  
92 - $primaryItem.removeClass('highlight');  
93 - $(this).addClass('highlight');  
94 -}).on('touchend touchcancel', 'li', function() {  
95 - $(this).removeClass('highlight');  
96 -});  
97 -  
98 -$categoryContainer.find('.sub-level').on('touchstart', 'li', function() {  
99 - $subLevelItem.removeClass('highlight');  
100 - $(this).addClass('highlight');  
101 -}).on('touchend touchcancel', 'li', function() {  
102 - $(this).removeClass('highlight');  
103 -});  
104 -  
105 -$nav.on('touchstart', 'li', function() {  
106 - $nav.find('li').removeClass('bytouch');  
107 - $(this).addClass('bytouch');  
108 -}).on('touchend touchcancel', 'li', function() {  
109 - $nav.find('li').removeClass('bytouch');  
110 -}); 1 +/**
  2 + * 分类
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/14
  5 + */
  6 +
  7 +var $ = require('yoho-jquery');
  8 +var FastClick = require('yoho-fastclick');
  9 +
  10 +var $nav = $('.category-nav'),
  11 + $search = $('#search-input'),
  12 + $categoryContainer = $('.category-container'),
  13 + $contents = $categoryContainer.children('.content'),
  14 + $subLevelItem = $categoryContainer.find('.sub-level li'),
  15 + $primaryItem = $categoryContainer.find('.primary-level li');
  16 +
  17 +require('../common');
  18 +
  19 +$(function() {
  20 + FastClick.attach(document.body);
  21 +});
  22 +
  23 +function resetHeight() {
  24 + var h = document.body.scrollHeight - $search.outerHeight() - $nav.outerHeight();
  25 +
  26 + $contents.height(h);
  27 +}
  28 +resetHeight();
  29 +
  30 +$search.focus(function() {
  31 + $(this).blur();
  32 +});
  33 +$nav.on('contextmenu', function() {
  34 + return false;
  35 +});
  36 +$('.category-container').on('contextmenu', function() {
  37 + return false;
  38 +});
  39 +
  40 +$nav.on('touchend touchcancel', function(e) {
  41 + var $this = $(e.target).closest('li'),
  42 + selector = '.' + $this.data('channel');
  43 +
  44 + if ($this.hasClass('focus')) {
  45 + return;
  46 + }
  47 +
  48 + $nav.find('li.focus').removeClass('focus');
  49 + $this.addClass('focus');
  50 +
  51 + $contents.addClass('hide');
  52 + $contents.filter(selector).removeClass('hide');
  53 +});
  54 +
  55 +$categoryContainer.on('click', function(e) {
  56 + var $this = $(e.target),
  57 + $subLevel,
  58 + $cur, index;
  59 +
  60 + $cur = $this.closest('.p-level-item');
  61 +
  62 + // 第一次单击右则空白处,出现冒泡
  63 + if ($(e.target).closest('.sub-level').length <= 0) {
  64 + e.preventDefault();
  65 + }
  66 +
  67 + if ($this[0] && $this[0].tagName === 'LI' && $this.find('a').attr('href')) {
  68 + location.href = $this.find('a').attr('href');
  69 + }
  70 +
  71 + if ($this[0] && $this[0].tagName === 'A' && $this.attr('href')) {
  72 + location.href = $this.attr('href');
  73 + }
  74 +
  75 + if ($cur.length > 0) {
  76 + index = $cur.index();
  77 + $subLevel = $this.closest('.content').find('.sub-level');
  78 +
  79 + if ($this.hasClass('focus')) {
  80 + return;
  81 + }
  82 +
  83 + $this.closest('.primary-level').children('.focus').removeClass('focus');
  84 + $this.addClass('focus');
  85 +
  86 + $subLevel.not('.hide').addClass('hide');
  87 + $subLevel.eq(index).removeClass('hide');
  88 + }
  89 +});
  90 +
  91 +$categoryContainer.find('.primary-level').on('touchstart touchend touchcancel', 'li', function() {
  92 + $primaryItem.removeClass('highlight');
  93 + $(this).addClass('highlight');
  94 +}).on('touchend touchcancel', 'li', function() {
  95 + $(this).removeClass('highlight');
  96 +});
  97 +
  98 +$categoryContainer.find('.sub-level').on('touchstart', 'li', function() {
  99 + $subLevelItem.removeClass('highlight');
  100 + $(this).addClass('highlight');
  101 +}).on('touchend touchcancel', 'li', function() {
  102 + $(this).removeClass('highlight');
  103 +});
  104 +
  105 +$nav.on('touchstart', 'li', function() {
  106 + $nav.find('li').removeClass('bytouch');
  107 + $(this).addClass('bytouch');
  108 +}).on('touchend touchcancel', 'li', function() {
  109 + $nav.find('li').removeClass('bytouch');
  110 +});