address.js
3.3 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/8/17
* Time: 13:39
*/
'use strict';
const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const addressModel = require(`${mRoot}/address`); // 地址管理 MODEL
// const helpers = global.yoho.helpers;
/**
* 地址管理页面
* @param req
* @param res
* @param next
*/
exports.address = (req, res, next) => {
let responseData = {
module: 'home',
page: 'address',
pageHeader: headerModel.setNav({
navTitle: '地址管理'
}),
title: '地址管理'
};
addressModel.address({
uid: req.user.uid || 8039759 // TODO 待删除
}).then(result => {
res.render('address/index', Object.assign(responseData, result));
}).catch(next);
};
/**
* 地址编辑页面
* @param req
* @param res
* @param next
*/
exports.addressAct = (req, res, next) => {
let responseData = {
module: 'home',
page: 'address-act',
pageHeader: headerModel.setNav({
navTitle: '编辑地址'
}),
title: '编辑地址'
};
addressModel.address({
id: req.params.id,
uid: req.user.uid || 8039759 // TODO 待删除
}).then(result => {
res.render('address/address-act', Object.assign(responseData, result));
}).catch(next);
};
/**
* 修改地址或者添加新地址
* @param req
* @param res
* @param next
*/
exports.saveAddress = (req, res, next) => {
// TODO 开发完成后放开
// if (!req.body.uid) {
// res.json({
// code: 400,
// message: '用户不可用'
// });
// }
if (!req.body.address) {
res.json({
code: 401,
message: '请输入可用的地址信息'
});
}
if (!req.body.area_code) {
res.json({
code: 402,
message: '地区码不可用'
});
}
if (!req.body.consignee) {
res.json({
code: 403,
message: '请输入收件人姓名'
});
}
// TODO 开发完成后放开
// if (!req.body.email || !helpers.verifyEmail(req.body.email)) {
// res.json({
// code: 404,
// message: '输入的邮箱地址格式不正确'
// });
// }
addressModel.saveAddress({
uid: req.user.uid || 8039759, // TODO 待删除
address: req.body.address,
area_code: req.body.area_code,
consignee: req.body.consignee,
email: req.body.email,
id: req.body.id,
mobile: req.body.mobile,
zip_code: req.body.zip_code
}).then(result => {
res.json(result);
}).catch(next);
};
/**
* 删除地址
* @param req
* @param res
* @param next
*/
exports.delAddress = (req, res, next) => {
addressModel.delAddress({
id: req.body.id,
uid: req.user.uid || 8039759 // TODO 待删除
}).then(result => {
res.json(result);
}).catch(next);
};
/**
* 异步获取三级地址数据
* @param req
* @param res
* @param next
*/
exports.locationList = (req, res, next) => {
addressModel.locationList({
uid: req.user.uid || 8039759 // TODO 待删除
}).then(result => {
res.render('address/location-list', result);
}).catch(next);
};