user-service.js
13.5 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
/**
* 个人中心 编辑资料models
* @author: gaohongwei<hongwei.gao@yoho.cn>
* @date: 2016/8/16
*/
'use strict';
const api = global.yoho.API;
const userApi = require('./user-api');
const headerModel = require('../../../doraemon/models/header');
const configData = {
gender: [{
key: 'gender',
value: 1,
text: '男'
}, {
key: 'gender',
value: 2,
text: '女'
}],
income: [{
key: 'income',
value: 0,
text: '请选择'
}, {
key: 'income',
value: 1,
text: '1000以下'
}, {
key: 'income',
value: 2,
text: '1000-2999'
}, {
key: 'income',
value: 3,
text: '3000-5999'
}, {
key: 'income',
value: 4,
text: '6000-7999'
}, {
key: 'income',
value: 5,
text: '8000-10000'
}, {
key: 'income',
value: 6,
text: '10000以上'
}],
profession: [{
key: 'profession',
value: 1,
text: '已工作'
}, {
key: 'profession',
value: 2,
text: '大学生'
}, {
key: 'profession',
value: 3,
text: '中学生'
}, {
key: 'profession',
value: 4,
text: '其他'
}],
shoppingHabits: [{
type: 'radio',
key: 'shopping',
value: '1',
text: '目的型购物'
},
{
type: 'radio',
key: 'shopping',
value: '2',
text: '冲动型购物'
},
{
type: 'radio',
key: 'shopping',
value: '3',
text: '保守型购物'
}],
// 着装习惯
dressHabits: [{
type: 'checkbox',
key: 'dress[]',
index: 'dress-1',
value: '1',
text: '正装'
},
{
type: 'checkbox',
key: 'dress[]',
index: 'dress-2',
value: '2',
text: '商务'
},
{
type: 'checkbox',
key: 'dress[]',
index: 'dress-3',
value: '3',
text: '街头流行'
},
{
type: 'checkbox',
key: 'dress[]',
index: 'dress-4',
value: '4',
text: '运动休闲'
},
{
type: 'checkbox',
key: 'dress[]',
index: 'dress-5',
value: '5',
text: '文艺气质'
},
{
type: 'checkbox',
key: 'dress[]',
index: 'dress-6',
value: '6',
text: '甜美可爱'
},
{
type: 'checkbox',
key: 'dress[]',
index: 'dress-7',
value: '7',
text: '另类'
}]
};
const getDays = (year, month) => {
let m = (month - 1) % 7 % 2 ? 30 : 31,
y400 = year % 400 ? 28 : 29,
y100 = year % 100 ? 29 : y400,
y4 = year % 4 ? 28 : y100;
return month === 2 ? y4 : m;
};
const getBirthday = (birthday) => {
let year = parseInt(birthday.split('-')[0], 0),
month = parseInt(birthday.split('-')[1], 0),
day = parseInt(birthday.split('-')[2], 0),
nowYear = new Date().getFullYear(),
yearArr = [{value: 0, text: '年'}],
monthArr = [{value: 0, text: '月'}],
dayArr = [{value: 0, text: '日'}],
days = getDays(year, month);
for (let i = 1950; i <= nowYear; i++) {
let yearJson = {value: i, text: i};
if (i === year) {
yearJson.isChecked = true;
}
yearArr.push(yearJson);
}
for (let j = 1; j <= 12; j++) {
let monthJson = {value: j, text: j};
if (j === month) {
monthJson.isChecked = true;
}
monthArr.push(monthJson);
}
for (let k = 1; k <= days; k++) {
let dayJson = {value: k, text: k};
if (k === day) {
dayJson.isChecked = true;
}
dayArr.push(dayJson);
}
return {
yearArr: yearArr,
monthArr: monthArr,
dayArr: dayArr
};
};
const isEmpty = (value) => {
return (Array.isArray(value) && value.length === 0) ||
(Object.prototype.isPrototypeOf(value) && Object.keys(value).length === 0);
};
/**
* 联动取地区信息
*/
const getProviceCityInfo = (parentId, checkValue) => {
let addressInfo = userApi.getProviceCityInfo(parentId) || '',
res = [{value: 0}],
defaultText;
if (parentId.length === 2) {
defaultText = '请选择省份';
} else if (parentId.length === 4) {
defaultText = '请选择市';
} else {
defaultText = '请选择区县';
}
res[0].text = defaultText;
if (addressInfo.code === 200) {
for (let i = addressInfo.data.length - 1; i >= 0; i--) {
let addressJson = {
value: addressInfo.data.id,
text: addressInfo.data.caption
};
if (addressInfo.data.id === checkValue) {
addressJson.isChecked = true;
}
res.push(addressJson);
}
}
return res;
};
const getUserInfo = (channel, uid) => {
return api.all([
headerModel.requestHeaderData(channel),
userApi.getUserInfo(uid),
userApi.getUserContactInfo(uid),
userApi.getUserHabitsInfo(uid),
userApi.getUserLikeBrand(uid)
]).then(result => {
let finalResult = {},
headerData = {},
userInfo = {};
if (result[0].code === 200) {
headerData = result[0];
}
if (result[1].code === 200) {
let gender,
genderArr,
birthday,
birthdayJson,
yearArr,
monthArr,
dayArr,
profession,
professionArr,
income,
incomeArr;
userInfo = result[1].data || {};
if (userInfo) {
gender = userInfo.gender || 3;
birthday = userInfo.birthday || '';
profession = userInfo.profession || 0;
income = userInfo.income || 0;
}
genderArr = configData.gender;
for (let value of genderArr) {
if (value.value === parseInt(gender, 0)) {
value.isChecked = true;
}
}
professionArr = configData.profession;
for (let value of professionArr) {
if (value.value === parseInt(profession, 0)) {
value.isChecked = true;
}
}
incomeArr = configData.income;
for (let value of incomeArr) {
if (value.value === parseInt(income, 0)) {
value.isChecked = true;
}
}
birthdayJson = getBirthday(birthday);
yearArr = birthdayJson.yearArr;
monthArr = birthdayJson.monthArr;
dayArr = birthdayJson.dayArr;
finalResult.userPersonalInfo = {
subTitle: '会员信息',
firstBox: true,
submitId: 'base-info',
profileSrc: userInfo.head_ico,
email: {
labelText: '登录邮箱:',
value: userInfo.email || ''
},
name: [
{
labelText: '昵称:',
value: userInfo.nickname,
key: 'nickname',
tips: '与Yoho!业务或商家品牌冲突的昵称,Yoho!将有可能收回'
},
{
labelText: '真实姓名:',
value: userInfo.username,
key: 'username',
tips: '' // 4.8去掉该提示
}
],
gender: {
labelText: '性别:',
key: 'gender',
data: genderArr
},
birthday: {
labelText: '生日:',
key: 'birthday',
tips: '',
selects: [
{
key: 'year',
options: yearArr,
unit: '年'
},
{
key: 'month',
options: monthArr,
unit: '月'
},
{
key: 'day',
options: dayArr,
unit: '日'
}
]
},
profession: {
labelText: '职业:',
key: 'profession',
data: professionArr
},
income: {
labelText: '收入状况:',
key: 'income',
data: incomeArr
}
};
}
if (result[2].code === 200) {
let contactInfo = result[2].data || '',
areaCode = contactInfo.areaCode || '';
finalResult.contactInfo = {
subTitle: '联系信息',
submitId: 'contact-info',
region: {
labelText: '来自:',
selects: [
{
key: 'province',
options: getProviceCityInfo(0, areaCode.substr(0, 2))
},
{
key: 'city',
options: getProviceCityInfo(areaCode.substr(0, 2), areaCode.substr(0, 4))
},
{
key: 'areaCode',
options: getProviceCityInfo(areaCode.substr(0, 4), areaCode)
}
]
},
details: [{
labelText: '固定电话:',
key: 'phone',
value: contactInfo.phone || '',
tips: '如: 010-82831245'
},
{
labelText: '手机号码:',
key: 'mobile',
value: contactInfo.mobile || '',
tips: '填写手机号便于接收发货和收货通知'
},
{
labelText: 'QQ:',
key: 'qq',
value: contactInfo.qq || '',
tips: '填写QQ方便您的好友联系你'
},
{
longInput: true,
labelText: '联系地址:',
key: 'fullAddress',
value: contactInfo.fullAddress || '',
tips: '请填写详细地址'
},
{
labelText: '邮编:',
key: 'zipCode',
value: contactInfo.zipCode || '',
tips: '请输入收货人所在地邮编号'
}]
};
}
if (result[3].code === 200) {
let habitsInfo = result[3].data || '',
dressHabitArr,
shoppingHabitArr;
shoppingHabitArr = configData.shoppingHabits;
if (isEmpty(habitsInfo.data) && habitsInfo.data.shopping) {
for (let value of shoppingHabitArr) {
if (value.value === parseInt(habitsInfo.data.shopping, 0)) {
value.isChecked = true;
}
}
}
dressHabitArr = configData.dressHabits;
if (isEmpty(habitsInfo.dress) && habitsInfo.data.dress) {
for (let value of dressHabitArr) {
if (value.value === parseInt(habitsInfo.data.dress, 0)) {
value.isChecked = true;
}
}
}
finalResult.habbit = {
subTitle: '购物&着装习惯',
submitId: 'shopping-info',
details: [
{
labelText: '购物习惯:',
data: shoppingHabitArr
},
{
labelText: '着装习惯:',
data: dressHabitArr
}
]
};
}
if (result[4].code === 200) {
// let brandInfo = result[4].data || '';
// finalResult.favorite = {
// subTitle: '喜爱品牌',
// submitId: 'favorite-brand',
// likebrand: (substr($userLikeBrandInfo['likeBrandStr'], 0, 1) == ',') ?
// $userLikeBrandInfo['likeBrandStr'] : ',' . $userLikeBrandInfo['likeBrandStr'],
// favoriteBrands: $userLikeBrandInfo['favBrands'],
// hotBrands: $userLikeBrandInfo['hotBrands'],
// }
}
finalResult.headerData = headerData;
finalResult.meEditPage = true;
return finalResult;
});
};
module.exports = {
getUserInfo
};