Authored by biao

optimise code

... ... @@ -12,12 +12,12 @@ const renderData = {
module: 'product'
};
const yhChannelMap = {
boys: 1,
girls: 2,
kids: 3,
lifestyle: 4
};
// const yhChannelMap = {
// boys: 1,
// girls: 2,
// kids: 3,
// lifestyle: 4
// };
// 奥莱首页控制器
exports.index = (req, res) => {
... ... @@ -64,9 +64,12 @@ exports.activityList = (req, res) => {
let type = req.query.type || 2;
let template = type === 2 ? 'outlet/will-end' : 'outlet/will-start';
let page = type === 2 ? 'outlet-will-end' : 'outlet-will-start';
let yhChannel = req.query.yh_channel || yhChannelMap[req.yoho.channel];
outletModel.getNearlyActivity(yhChannel, type, categoryId).then(result => {
if (!categoryId) {
throw new Error('No parent_id for OUTLET channel page!');
}
outletModel.getRecentActivity(type, categoryId).then(result => {
res.render(template, Object.assign({
page: page,
pageHeader: headerData,
... ...
... ... @@ -33,7 +33,7 @@ const getOutletResource = (channel, contentcode) => {
return resourcesProcess(result.data.list);
} else {
log.error('奥莱资源位接口返回状态码 不是 200');
return result;
return [];
}
});
};
... ... @@ -68,7 +68,7 @@ const getNavData = (categoryId) => {
return data;
} else {
log.error('奥莱导航接口返回状态码 不是 200', result);
return result;
return [];
}
});
};
... ... @@ -115,7 +115,7 @@ const convertActicityData = (data) => {
const getHomeActivity = (data) => {
var params = {
method: 'app.outlets.activityGet',
platform: 2,
platform: 2
};
return api.get('', sign.apiSign(_.assign(params, data))).then(res => {
... ... @@ -124,8 +124,7 @@ const getHomeActivity = (data) => {
};
exports.getContent = (categoryId, channel, code) => {
let floorsData = {},
params = {
let params = {
type: 0,
yh_channel: channel
};
... ... @@ -133,39 +132,43 @@ exports.getContent = (categoryId, channel, code) => {
const p = [getNavData(categoryId), getOutletResource(channel, code), getHomeActivity(params)];
return Promise.all(p).then(data => {
floorsData.nav = data[0] || [];
floorsData.content = data[1] || [];
floorsData.activity = {data: data[2]};
return floorsData;
return {
nav: data[0] || [],
content: data[1] || [],
activity: data[2]
};
});
};
exports.getActivity = (id) => {
return getActivityDetail(id).then(res => {
var data = {};
data.outletActivity = res;
data.productPool = res[0] && res[0].productPoolId || '';
data.saleType = 4;
return data;
return {
outletActivity: res,
productPool: res[0] || res[0].productPoolId || '',
saleType: 4
};
});
};
exports.getNearlyActivity = (channel, type, categoryId) => {
/**
* 获取即将开始或即将结束的活动列表
* @param {Number} type 标明是即将开始还是即将技术
* @param {String} categoryId 父级菜单id,用于标明当前页面是奥莱页面
* @return {Object} 活动列表数据
*/
exports.getRecentActivity = (type, categoryId) => {
var params = {
type: type
type: 0
};
return Promise.all([getNavData(categoryId), getHomeActivity(params)]).then(res => {
var data = {
return {
nav: res[0] || [],
activity: {
data: res[1]
}
activity: res[1]
};
return data;
});
};
... ...
<div class="outlet-page yoho-page">
{{> product/outlet/nav}}
{{# activity}}
{{#data}}
<a class="will-end-back" href="{{activityUrl}}" >
<img class="back-image" src="{{image coverUrl 640 300}}">
<div class="last-time"><i class="iconfont time-ico">&#xe603;</i><span>{{>product/outlet/countdown}}</span></div>
... ... @@ -11,6 +10,5 @@
<img class="logo" src="{{image logoUrl 150 100}}"></img>
</div>
</a>
{{/data}}
{{/ activity}}
</div>
... ...
<div class="active-list">
{{#data}}
<a class="back-ground-white {{#if hide}} hidden {{/if}}" href="{{activityUrl}}" >
<img class="back-image" src="{{image coverUrl 640 300}}">
<div class="center-square">
... ... @@ -9,6 +8,5 @@
{{>product/outlet/countdown}}
</div>
</a>
{{/data}}
</div>
<div class="more-activity hide"><p>更多精彩活动</p><span class="iconfont count-down-icon">&#xe609;</span></div>
... ...