outlet.js
2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* 奥莱页面
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const outletModel = require('../models/outlet');
const headerModel = require('../../../doraemon/models/header');
const yhChannelEmpty = 0;
const willEndActivity = {
type: 2,
template: 'outlet/will-end',
page: 'outlet-will-end'
};
const willStartActivity = {
type: 3,
template: 'outlet/will-start',
page: 'outlet-will-start'
};
// 奥莱首页控制器
exports.index = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '奥莱',
navBtn: false
});
let categoryId = req.query.category_id;
let yhChannel = req.query.yh_channel || yhChannelEmpty;
let contentcode = req.query.content_code;
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.newoutlet","params":${JSON.stringify(req.query)}}`;
req.ctx(outletModel).getContent(categoryId, yhChannel, contentcode).then(result => {
res.render('outlet', Object.assign({
localCss: true,
pageHeader: headerData,
title: '奥莱 | Yoho!Buy有货 | 潮流购物逛不停',
}, result));
}).catch(next);
};
// 奥莱活动详情页
exports.activityDetail = (req, res, next) => {
req.ctx(outletModel).getActivity(req.query.id).then(result => {
let headerData = headerModel.setNav({
navTitle: result.activityTitle,
navBtn: false
});
res.render('outlet/activity', Object.assign({
localCss: true,
page: 'outlet-detail',
pageHeader: headerData,
pageFooter: true,
_noLazy: true
}, result));
}).catch(next);
};
// 奥莱活动倒计时时间
exports.activityTime = (req, res, next) => {
req.ctx(outletModel).getActivityTime(req.query).then(times => {
res.json(times);
}).catch(next);
};
// 奥莱活动频道列表页
exports.activityList = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '奥莱',
navBtn: false
});
let categoryId = req.query.category_id;
let type = req.query.type || willEndActivity.type;
let template;
let page;
if (!categoryId) {
throw new Error('No parent_id for OUTLET channel page!');
}
// 根据请求的类型确定要渲染的是即将结束页面还是上线预告页面
if (parseInt(type, 10) === willEndActivity.type) {
template = willEndActivity.template;
page = willEndActivity.page;
} else {
template = willStartActivity.template;
page = willStartActivity.page;
}
req.ctx(outletModel).getRecentActivity(type, categoryId).then(result => {
res.render(template, Object.assign({
page: page,
pageHeader: headerData,
pageFooter: true
}, result));
}).catch(next);
};