Authored by biao

optimise code

@@ -12,12 +12,12 @@ const renderData = { @@ -12,12 +12,12 @@ const renderData = {
12 module: 'product' 12 module: 'product'
13 }; 13 };
14 14
15 -const yhChannelMap = {  
16 - boys: 1,  
17 - girls: 2,  
18 - kids: 3,  
19 - lifestyle: 4  
20 -}; 15 +// const yhChannelMap = {
  16 +// boys: 1,
  17 +// girls: 2,
  18 +// kids: 3,
  19 +// lifestyle: 4
  20 +// };
21 21
22 // 奥莱首页控制器 22 // 奥莱首页控制器
23 exports.index = (req, res) => { 23 exports.index = (req, res) => {
@@ -64,9 +64,12 @@ exports.activityList = (req, res) => { @@ -64,9 +64,12 @@ exports.activityList = (req, res) => {
64 let type = req.query.type || 2; 64 let type = req.query.type || 2;
65 let template = type === 2 ? 'outlet/will-end' : 'outlet/will-start'; 65 let template = type === 2 ? 'outlet/will-end' : 'outlet/will-start';
66 let page = type === 2 ? 'outlet-will-end' : 'outlet-will-start'; 66 let page = type === 2 ? 'outlet-will-end' : 'outlet-will-start';
67 - let yhChannel = req.query.yh_channel || yhChannelMap[req.yoho.channel];  
68 67
69 - outletModel.getNearlyActivity(yhChannel, type, categoryId).then(result => { 68 + if (!categoryId) {
  69 + throw new Error('No parent_id for OUTLET channel page!');
  70 + }
  71 +
  72 + outletModel.getRecentActivity(type, categoryId).then(result => {
70 res.render(template, Object.assign({ 73 res.render(template, Object.assign({
71 page: page, 74 page: page,
72 pageHeader: headerData, 75 pageHeader: headerData,
@@ -33,7 +33,7 @@ const getOutletResource = (channel, contentcode) => { @@ -33,7 +33,7 @@ const getOutletResource = (channel, contentcode) => {
33 return resourcesProcess(result.data.list); 33 return resourcesProcess(result.data.list);
34 } else { 34 } else {
35 log.error('奥莱资源位接口返回状态码 不是 200'); 35 log.error('奥莱资源位接口返回状态码 不是 200');
36 - return result; 36 + return [];
37 } 37 }
38 }); 38 });
39 }; 39 };
@@ -68,7 +68,7 @@ const getNavData = (categoryId) => { @@ -68,7 +68,7 @@ const getNavData = (categoryId) => {
68 return data; 68 return data;
69 } else { 69 } else {
70 log.error('奥莱导航接口返回状态码 不是 200', result); 70 log.error('奥莱导航接口返回状态码 不是 200', result);
71 - return result; 71 + return [];
72 } 72 }
73 }); 73 });
74 }; 74 };
@@ -115,7 +115,7 @@ const convertActicityData = (data) => { @@ -115,7 +115,7 @@ const convertActicityData = (data) => {
115 const getHomeActivity = (data) => { 115 const getHomeActivity = (data) => {
116 var params = { 116 var params = {
117 method: 'app.outlets.activityGet', 117 method: 'app.outlets.activityGet',
118 - platform: 2, 118 + platform: 2
119 }; 119 };
120 120
121 return api.get('', sign.apiSign(_.assign(params, data))).then(res => { 121 return api.get('', sign.apiSign(_.assign(params, data))).then(res => {
@@ -124,8 +124,7 @@ const getHomeActivity = (data) => { @@ -124,8 +124,7 @@ const getHomeActivity = (data) => {
124 }; 124 };
125 125
126 exports.getContent = (categoryId, channel, code) => { 126 exports.getContent = (categoryId, channel, code) => {
127 - let floorsData = {},  
128 - params = { 127 + let params = {
129 type: 0, 128 type: 0,
130 yh_channel: channel 129 yh_channel: channel
131 }; 130 };
@@ -133,39 +132,43 @@ exports.getContent = (categoryId, channel, code) => { @@ -133,39 +132,43 @@ exports.getContent = (categoryId, channel, code) => {
133 const p = [getNavData(categoryId), getOutletResource(channel, code), getHomeActivity(params)]; 132 const p = [getNavData(categoryId), getOutletResource(channel, code), getHomeActivity(params)];
134 133
135 return Promise.all(p).then(data => { 134 return Promise.all(p).then(data => {
136 - floorsData.nav = data[0] || [];  
137 - floorsData.content = data[1] || [];  
138 - floorsData.activity = {data: data[2]};  
139 135
140 - return floorsData; 136 + return {
  137 + nav: data[0] || [],
  138 + content: data[1] || [],
  139 + activity: data[2]
  140 + };
141 }); 141 });
142 }; 142 };
143 143
144 144
145 exports.getActivity = (id) => { 145 exports.getActivity = (id) => {
146 return getActivityDetail(id).then(res => { 146 return getActivityDetail(id).then(res => {
147 - var data = {};  
148 147
149 - data.outletActivity = res;  
150 - data.productPool = res[0] && res[0].productPoolId || '';  
151 - data.saleType = 4;  
152 - return data; 148 + return {
  149 + outletActivity: res,
  150 + productPool: res[0] || res[0].productPoolId || '',
  151 + saleType: 4
  152 + };
153 }); 153 });
154 }; 154 };
155 155
156 -exports.getNearlyActivity = (channel, type, categoryId) => { 156 +/**
  157 + * 获取即将开始或即将结束的活动列表
  158 + * @param {Number} type 标明是即将开始还是即将技术
  159 + * @param {String} categoryId 父级菜单id,用于标明当前页面是奥莱页面
  160 + * @return {Object} 活动列表数据
  161 + */
  162 +exports.getRecentActivity = (type, categoryId) => {
157 var params = { 163 var params = {
158 - type: type 164 + type: 0
159 }; 165 };
160 166
161 return Promise.all([getNavData(categoryId), getHomeActivity(params)]).then(res => { 167 return Promise.all([getNavData(categoryId), getHomeActivity(params)]).then(res => {
162 - var data = { 168 +
  169 + return {
163 nav: res[0] || [], 170 nav: res[0] || [],
164 - activity: {  
165 - data: res[1]  
166 - } 171 + activity: res[1]
167 }; 172 };
168 -  
169 - return data;  
170 }); 173 });
171 }; 174 };
1 <div class="outlet-page yoho-page"> 1 <div class="outlet-page yoho-page">
2 {{> product/outlet/nav}} 2 {{> product/outlet/nav}}
3 {{# activity}} 3 {{# activity}}
4 - {{#data}}  
5 <a class="will-end-back" href="{{activityUrl}}" > 4 <a class="will-end-back" href="{{activityUrl}}" >
6 <img class="back-image" src="{{image coverUrl 640 300}}"> 5 <img class="back-image" src="{{image coverUrl 640 300}}">
7 <div class="last-time"><i class="iconfont time-ico">&#xe603;</i><span>{{>product/outlet/countdown}}</span></div> 6 <div class="last-time"><i class="iconfont time-ico">&#xe603;</i><span>{{>product/outlet/countdown}}</span></div>
@@ -11,6 +10,5 @@ @@ -11,6 +10,5 @@
11 <img class="logo" src="{{image logoUrl 150 100}}"></img> 10 <img class="logo" src="{{image logoUrl 150 100}}"></img>
12 </div> 11 </div>
13 </a> 12 </a>
14 - {{/data}}  
15 {{/ activity}} 13 {{/ activity}}
16 </div> 14 </div>
1 <div class="active-list"> 1 <div class="active-list">
2 -{{#data}}  
3 <a class="back-ground-white {{#if hide}} hidden {{/if}}" href="{{activityUrl}}" > 2 <a class="back-ground-white {{#if hide}} hidden {{/if}}" href="{{activityUrl}}" >
4 <img class="back-image" src="{{image coverUrl 640 300}}"> 3 <img class="back-image" src="{{image coverUrl 640 300}}">
5 <div class="center-square"> 4 <div class="center-square">
@@ -9,6 +8,5 @@ @@ -9,6 +8,5 @@
9 {{>product/outlet/countdown}} 8 {{>product/outlet/countdown}}
10 </div> 9 </div>
11 </a> 10 </a>
12 -{{/data}}  
13 </div> 11 </div>
14 <div class="more-activity hide"><p>更多精彩活动</p><span class="iconfont count-down-icon">&#xe609;</span></div> 12 <div class="more-activity hide"><p>更多精彩活动</p><span class="iconfont count-down-icon">&#xe609;</span></div>