general-tabs-service.js
7.68 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
'use strict';
const _ = require('lodash');
const UserApi = require('./user-api');
const headerModel = require('../../../doraemon/models/header');
const MsgApi = require('./message');
const helpers = global.yoho.helpers;
const defaultAvatar = '//img10.static.yhbimg.com/headimg/' +
'2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
_homeNav(switcher) {
return [
{
title: '交易管理',
subNav: [
{name: '我的订单', href: '/home/orders',
catchs: ['/home/orders', '/home/index', '/home/orders/detail']},
{name: '我的收藏', href: '/home/favorite', catchs: ['/home/favorite/reduction']},
{name: '我的有货币', href: '/home/currency'},
{name: '我的红包', href: '/home/redenvelopes'},
{name: '我的优惠券', href: '/home/coupons'},
{name: '我的邀请好友', href: '/home/spread'},
{name: '我的礼品卡', href: '/home/megift'},
{name: '我的VIP', href: '/home/vip'}
]
},
{
title: '服务中心',
subNav: [
{name: '我的退/换货', href: '/home/returns'},
{name: '我的发票', href: '/home/invoice'},
{name: '我的咨询', href: '/home/consult'},
{name: '我的评论', href: '/home/comment'},
// {name: '我的投诉', href: '/home/complaints'},
{name: '我的消息', href: '/home/message', count: 0},
{
name: '在线客服',
href: switcher ?
'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409' : '/service/client',
isBlank: true
}
]
},
{
title: '个人信息管理',
subNav: [
{name: '编辑个人资料', href: '/home/user'},
{name: '账号安全', href: '/home/account', catchs: [
'/home/account/userpwd',
'/home/account/email',
'/home/account/mobile',
'/home/account/checkverifycode',
'/home/account/checkpassword',
'/home/account/verifypassword',
'/home/account/modifypwd',
'/home/account/sendemail',
'/home/account/checkemail',
'/home/account/modifyemail',
'/home/account/sendemailsuccess',
'/home/account/mailresult',
'/home/account/checkmobile',
'/home/account/checkmobilemsg',
'/home/account/sendmobilemsg',
'/home/account/modifymobile'
]},
{name: '地址管理', href: '/home/address'},
// {name: '兑换礼品卡', href: '/home/gift'} // @韩施超-产品让注释的
]
}
];
}
_getActiveNav(url, switcher, count) {
let that = this;
let mHomeNav = _.cloneDeep(that._homeNav(switcher));
let activeNav = null;
mHomeNav = mHomeNav.map((item) => {
item.subNav = item.subNav.map((nav) => {
let curMatchPath = url;
if (!nav.matchQuery && curMatchPath.indexOf('?') >= 0) { // 严格的路径匹配,包含后面的参数
curMatchPath = curMatchPath.substr(0, curMatchPath.indexOf('?'));
}
if (curMatchPath === nav.href) {
nav.active = true;
}
if (nav.name === '我的消息') {
nav.count = +count;
}
if (nav.catchs) {
let index = nav.catchs.indexOf(curMatchPath);
if (index > -1) {
nav.active = true;
nav.curHref = nav.catchs[index];
}
}
if (nav.active) {
activeNav = nav;
}
nav.href = nav.href.indexOf('http://') > -1 ? nav.href : helpers.urlFormat(nav.href);
return nav;
});
return item;
});
return {
homeNav: mHomeNav,
activeNav: activeNav
};
}
_getAvatar(uid) {
let userDataModel = new UserApi(this.ctx);
return userDataModel.getUserInfo(uid).then((result) => {
return _.get(result, 'data.head_ico', '') || defaultAvatar;
});
}
_msgCount(uid) {
let msgDataModel = new MsgApi(this.ctx);
return msgDataModel.unreadTotal(uid).then(result => _.get(result, 'data.total', 0));
}
_getTabsData(uid, channel) {
let that = this;
return Promise.props({
msg: that._msgCount(uid),
header: headerModel.requestHeaderData(channel),
avatar: that._getAvatar(uid)
});
}
getHomeNavNew(uid, channel, url, clientSwitcher) {
let navs = this._getActiveNav(url, clientSwitcher, 1);
let activeNav = navs.activeNav;
let bread = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}];
if (activeNav) {
bread.push({
name: '个人中心',
href: helpers.urlFormat('/home')
});
bread.push({
name: activeNav.name
});
// 订单详情
if (activeNav.curHref === '/home/orders/detail') {
Object.assign(_.last(bread), {
href: helpers.urlFormat('/home/orders')
});
bread.push({
name: '订单详情'
});
}
} else {
bread.push({
name: '个人中心'
});
}
return {
path: bread,
homeNav: navs.homeNav,
userThumb: defaultAvatar
};
}
getHomeNav(uid, channel, url, clientSwitcher) {
let that = this;
return that._getTabsData(uid, channel).then((result) => {
let navs = that._getActiveNav(url, clientSwitcher, result.msg);
let activeNav = navs.activeNav;
let bread = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}];
if (activeNav) {
bread.push({
name: '个人中心',
href: helpers.urlFormat('/home')
});
bread.push({
name: activeNav.name
});
// 订单详情
if (activeNav.curHref === '/home/orders/detail') {
Object.assign(_.last(bread), {
href: helpers.urlFormat('/home/orders')
});
bread.push({
name: '订单详情'
});
}
} else {
bread.push({
name: '个人中心'
});
}
return Object.assign({
path: bread,
homeNav: navs.homeNav,
userThumb: result.avatar
}, result.header);
});
}
};