Authored by 郝肖肖

默认选中tab

@@ -8,6 +8,13 @@ @@ -8,6 +8,13 @@
8 const mRoot = '../models'; 8 const mRoot = '../models';
9 const plusstarModel = require(`${mRoot}/plusstar`); 9 const plusstarModel = require(`${mRoot}/plusstar`);
10 const headerModel = require('../../../doraemon/models/header'); // 头部model 10 const headerModel = require('../../../doraemon/models/header'); // 头部model
  11 +let channels = {
  12 + boys: 1,
  13 + girl: 2,
  14 + kids: 3,
  15 + lifestyle: 4
  16 +};
  17 +
11 /** 18 /**
12 * 潮流优选首页 19 * 潮流优选首页
13 */ 20 */
@@ -15,6 +22,7 @@ exports.index = (req, res, next) => { @@ -15,6 +22,7 @@ exports.index = (req, res, next) => {
15 let isApp = req.query.app_version || req.query.appVersion || false; 22 let isApp = req.query.app_version || req.query.appVersion || false;
16 let parameter = {}; 23 let parameter = {};
17 let title = '潮流优选'; 24 let title = '潮流优选';
  25 + let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || 1;
18 26
19 if (isApp === false) { 27 if (isApp === false) {
20 parameter = { 28 parameter = {
@@ -25,7 +33,7 @@ exports.index = (req, res, next) => { @@ -25,7 +33,7 @@ exports.index = (req, res, next) => {
25 }; 33 };
26 } 34 }
27 35
28 - plusstarModel.getAllChannels({}).then(result => { 36 + plusstarModel.getAllChannels({gender: gender}).then(result => {
29 res.render('plusstar/index', Object.assign({ 37 res.render('plusstar/index', Object.assign({
30 page: 'plusstar-index', 38 page: 'plusstar-index',
31 result: result, 39 result: result,
@@ -9,23 +9,29 @@ const productProcess = require('../../../utils/product-process'); @@ -9,23 +9,29 @@ const productProcess = require('../../../utils/product-process');
9 * @return {[array]} 9 * @return {[array]}
10 */ 10 */
11 const getAllChannels = (params) => { 11 const getAllChannels = (params) => {
12 - params = params || {}; 12 + let gender = params.gender - 1 || 0;
13 13
14 - return api.get('', Object.assign({ 14 + return api.get('', {
15 method: 'app.blk.getAllChannels' 15 method: 'app.blk.getAllChannels'
16 - }, params)).then(result => { 16 + }).then(result => {
17 let data = {channel: []}; 17 let data = {channel: []};
18 18
19 if (result.code !== 200) { 19 if (result.code !== 200) {
20 return data; 20 return data;
21 } 21 }
22 22
  23 + if (gender === 3 && result.data.length === 3) {
  24 + // 1:男,2:女,3:童装,4:创意生活
  25 + // 如果为3,说明童装没有配置,只配置了创意生活。所以要减一
  26 + gender = 2;
  27 + }
  28 +
23 _.forEach(result.data, (res, index) => { 29 _.forEach(result.data, (res, index) => {
24 data.channel.push({ 30 data.channel.push({
25 id: res.channel_id, 31 id: res.channel_id,
26 mame: res.channel_name, 32 mame: res.channel_name,
27 code: res.content_code, 33 code: res.content_code,
28 - focus: index === 0 ? true : false 34 + focus: index === gender ? true : false
29 }); 35 });
30 }); 36 });
31 37
@@ -35,16 +35,10 @@ plusstar = { @@ -35,16 +35,10 @@ plusstar = {
35 }); 35 });
36 36
37 // start -- 默认选中 37 // start -- 默认选中
38 - switch (window.cookie('_Channel')) {  
39 - case 'girls':  
40 - $liDom = $('.plusstar-page .tab-nav ul li:eq(1)');  
41 - break;  
42 - case 'lifestyle':  
43 - $liDom = $('.plusstar-page .tab-nav ul li:eq(2)');  
44 - break;  
45 - default:  
46 - $liDom = $('.plusstar-page .tab-nav ul li:eq(0)');  
47 - break; 38 + $liDom = $tabUlDom.find('li.focus');
  39 + if ($liDom.length <= 0) {
  40 + // 默认第一个
  41 + $liDom = $('.plusstar-page .tab-nav ul li:eq(0)');
48 } 42 }
49 $tabUlDom.find('li').removeClass('focus'); 43 $tabUlDom.find('li').removeClass('focus');
50 $liDom.addClass('focus'); 44 $liDom.addClass('focus');