userCenter.js
16.6 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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
import api from '../../common/api.js';
import { getChannelCode, getGenderCode, getRecPosCode, getRecommandContentCode } from '../../utils/home';
import { parseBrandListData } from '../../utils/productListUtil';
import { shouldDiscardTap, getGoodDetailParam, getYHStorageSync } from '../../utils/util';
import router from '../../router/index.js'
// import { decodePhoneNumber, wechatLoginAction, getUnionID, decodeUnionId, openAuthorizeSettings, listen} from '../../utils/login';
// import {
// logEvent,
// YB_PAGE_OPEN_L,
// YB_MAIN_TAB_C,
// YB_MY_GRP_BUY,
// YB_MY_FAV
// } from '../../libs/analytics.js'
//userCenter.js
//获取应用实例
var app = getApp()
let PV_ID = new Date().getTime() + '';
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;
const { extend, Toast } = require('../../vendors/zanui/index');
Page(extend({},Toast,{
data: {
vipImg:'',
windowWidth,
windowHeight,
userInfo: {},
isLogin: false,
infoNum:{},
recommdData:[],
groupOrdersCount: 0,
hasUnionID: '',
isShowIndicator: false,
scrollTop: 0,
inviteInfo: {},
isWechatService: false,
wechatShareCode: ''
},
//事件处理函数
bindViewTap: function() {
// console.log('avatar tapped!!')
},
onLoad: function (options) {
this.setData({
hasUnionID: app.globalData.WXUnion_ID !== null && app.globalData.WXUnion_ID !== '' && app.globalData.WXUnion_ID !== undefined ? true:false,
})
// if (app.isLogin()) {
// this.data.isLogin = true;
// }else{
// this.setData({
// isLogin:false,
// })
// }
this.setData({
isLogin:false,
})
// new app.WeToast();
this.getRecommed();
//订阅登录完成通知
// listen(function (succeed) {
// if (succeed) {
// this.showUserInfo();
// this.getInfoNum();
// this.fetchInviteInfo();
// }
// }.bind(this))
},
onShow: function() {
// console.log("app.isLogin():", app.globalData.userInfo)
// if (app.isLogin()) {
// // this.data.isLogin = true;
// this.setData({
// isLogin: true,
// })
// this.showUserInfo();
// this.getInfoNum();
// this.getGroupOrdersCount();
// this.checkIsWechatCs();
// }else{
// this.setData({
// isLogin: false,
// })
// }
this.setData({
isLogin:false,
})
this.fetchInviteInfo();
// logEvent(YB_MAIN_TAB_C, { TAB_ID: 4 });
var pages = getCurrentPages()
var currentPage = pages[pages.length - 1]
var url = currentPage.route
// let params = {
// PAGE_NAME: 'userCenter',
// PAGE_PARAM: '',
// FROM_PAGE_NAME: '',
// FROM_PAGE_PARAM: '',
// PV_ID: PV_ID,
// PAGE_PATH: url
// };
// logEvent(YB_PAGE_OPEN_L, params);
},
onShareAppMessage: function(options) {
if (options.from == 'button' && options.target.id == 'wxRedPacket') {
return {
title: '有货有红包,最高可免单!',
path: `/page/subPackage/pages/redEnvelope/redEnvelope?shareCode=${this.data.wechatShareCode}`,
imageUrl: 'http://img11.static.yhbimg.com/goodsimg/2018/07/20/15/019b9a86ce32acec580ae17568cd99a1f2.png'
}
}
},
navToGoodsCollectPage: function () {
// logEvent(YB_MY_FAV, {});
if (!this.data.isLogin) {
tt.showToast({
title: "请先完成登录/注册,再查看!",
icon: 'none',
duration: 1500
});
return;
}
tt.navigateTo({
url: '../goodsCollect/goodsCollect',
})
},
navToAddressManagerPage:function(){
if (!this.data.isLogin) {
tt.showToast({
title: "请先完成登录/注册,再查看!",
icon: 'none',
duration: 1500
});
return;
}
tt.navigateTo({
url: './addressManager/addressManager?currentMode=modeEdit' + '&page_name=' + 'userCenter' + '&page_param=' + ''
})
},
selectComplete: function(json) {
// console.log(json)
},
navToOrders:function(e) {
if (!this.data.isLogin) {
tt.showToast({
title: "请先完成登录/注册,再查看!",
icon: 'none',
duration: 1500
});
return;
}
let index = parseInt(e.currentTarget.dataset.index);
// let params = {
// PAGE_NAME: 'userCenter',
// PAGE_PARAM: '',
// FROM_PAGE_NAME: '',
// FROM_PAGE_PARAM: '',
// };
// let YB_EVENT = '';
// if(index === 0){
// //我的订单
// YB_EVENT = 'YB_MY_ORD';
// }else if(index === 1){
// //待付款
// YB_EVENT = 'YB_MY_TOPAY';
// } else if (index === 2) {
// //待发货
// YB_EVENT = 'YB_MY_TOSEND';
// } else if (index === 3) {
// //待收货
// YB_EVENT = 'YB_MY_TOREC';
// }
// logEvent(YB_EVENT, params);
tt.navigateTo({
url: '../orders/orders?index=' + index + '&page_name=' + 'userCenter' + '&page_param=' + ''
})
},
/**
* 新的授权方式
*/
getUserInfo: function (e) {
router.go('bindPhoneNumber');
// console.log(tt);
// var that = this;
// // console.log(e);
// if (e.detail.errMsg === 'getUserInfo:ok'){
// decodeUnionId(app.getWechatThirdSession(),e,function (response){
// if (response.isHaveUnionID){
// that.setData({
// hasUnionID: true,
// });
// } else {
// // console.log("没有获取到unionid");
// }
// });
// } else {
// openAuthorizeSettings(function (response) {
// if (response.isHaveUnionID) {
// that.setData({
// hasUnionID: true,
// })
// };
// if (response.succeed === true) {
// that.showUserInfo();
// that.getInfoNum();
// } else {
// // console.log("根据unionid没有查询到uid,需要再次点击授权getPhoneNumber")
// }
// });
// }
},
getPhoneNumber: function (e) {
// var app = getApp()
// var that = this;
// // console.log('getPhoneNumber',e);
// if (e.detail.errMsg === 'getPhoneNumber:ok') {
// decodePhoneNumber(e.detail.iv, e.detail.encryptedData, '',function (result) {
// if (result.code != 200) {
// // console.log('result.code',result.code);
// tt.showToast({
// title: result.message,
// icon: 'none',
// duration: 1000,
// success (res) {
// that.loginAndRegisterTapped()
// },
// });
// } else {
// if (result.is_register){
// that.showZanToast({ title: '欢迎加入Yoho!Family!新人礼包已发放到个人中心-优惠券,请注意查收',success:function(){
// let uid = app.globalData.userInfo.uid > 0 ? app.globalData.userInfo.uid : 0;
// app.updateUid(uid)
// that.setData({ uid });
// that.showUserInfo();
// }},1500);
// } else {
// let uid = app.globalData.userInfo.uid > 0 ? app.globalData.userInfo.uid : 0;
// app.updateUid(uid)
// that.setData({ uid });
// that.showUserInfo();
// }
// }
// })
// } else {
// tt.navigateTo({
// url: '../bindPhoneNumber/bindPhoneNumber',
// })
// }
},
loginAndRegisterTapped:function() {
// console.log("loginAndRegisterTapped");
// let that = this;
// let app = getApp()
// if (tt.getSetting) {
// tt.getSetting({
// success: (res) => {
// // console.log("userInfo:", res.authSetting["scope.userInfo"])
// if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === false) {
// tt.showModal({
// title: '',
// content: '检测到您未打开微信用户信息授权,开启后即可进行登录',
// confirmText: "去开启",
// confirmColor: "#000000",
// success: function (res) {
// if (res.confirm) {
// tt.openSetting({
// success: (res) => {
// // console.log(res.authSetting["scope.userInfo"])
// if (res.authSetting["scope.userInfo"] !== null && res.authSetting["scope.userInfo"] !== undefined && res.authSetting["scope.userInfo"] === true) {
// getUnionID(app.getWechatThirdSession(), function (response) {
// if (response.succeed === true) {
// that.showUserInfo();
// that.getInfoNum();
// }
// })
// }
// }
// })
// } else {
// tt.navigateTo({
// url: '../bindPhoneNumber/bindPhoneNumber',
// })
// }
// }
// })
// } else {
// tt.navigateTo({
// url: '../bindPhoneNumber/bindPhoneNumber',
// })
// }
// }
// })
// } else {
// tt.showModal({
// title: '提示',
// content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
// })
// }
},
navToServiceFeedBack:function(){
tt.navigateTo({
url: 'serviceFeedBack/serviceFeedBack',
})
},
formSubmit: function (e) {
// console.log(e);
let formId = e.detail.formId;
let _self = this;
if (!app.getUid() || !formId || formId.length === 0) return;
//上报formId
let formIdParams = {
uid: app.getUid(),
openId: app.globalData.openID ? app.globalData.openID : getYHStorageSync('openID','userCenter'),
miniapp_type: app.globalData.miniapp_type,
formId: formId,
method: 'wechat.formId.add',
}
// console.log('params', formIdParams)
api.get({data:formIdParams})
},
/**
* 获取个人中心猜你喜欢数据
*/
getRecommed:function(){
let gender = getGenderCode(getApp().globalData.selectedChannel);
let yh_channel = getChannelCode(getApp().globalData.selectedChannel);
let param = {
method:"app.home.newPreference",
gender,
yh_channel,
rec_pos: 100004,
limit:30,
fromPage:"aFP_My",
}
api.get({data:param})
.then(json =>{
if (json && json.code && json.code == 200) {
// console.log('获取猜你喜欢数据成功');
// console.log(json);
let data = json.data.product_list;
data = parseBrandListData(data);
this.setData({
recommdData: data,
})
}
});
},
getInfoNum:function(){
let myUid = app.getUid();
if(!myUid){
myUid = app.globalData.userInfo.uid;
}
/**
* 获取用户数量
*/
let numParam = {
method: 'app.home.getInfoNum',
// uid: myUid ,
};
api.get({data:numParam})
.then(json => {
if (json && json.code && json.code == 200) {
this.data.infoNum = json.data;
this.setData({
infoNum: this.data.infoNum,
})
}
});
},
showUserInfo: function() {
// console.log("uid:", app.getUid())
if (app.getUid()) {
let param = {
method: "app.passport.profile",
uid: app.getUid()
}
api.get({data:param})
.then((json) => {
if (json && json.code && json.code == 200) {
this.data.userInfo = app.globalData.userInfo;
this.data.userInfo.nickName = json.data.nickname;
this.data.userInfo.avatarUrl = (!json.data.head_ico ? "images/mine_default_head.png" : this.formatImgUrl(json.data.head_ico))
this.setVipImg(json.data.vip_info.cur_level);
this.setData({
userInfo: this.data.userInfo,
isLogin:true
})
}else{
this.setData({
isLogin:false
})
}
})
.catch(error => {
// console.log(error);
this.setData({
isLogin: false
})
})
}
else {
let userInfo = app.globalData.userInfo;
this.setData({
userInfo
})
this.setData({
isLogin: false
})
}
},
getGroupOrdersCount:function(){
let myUid = app.getUid();
if (!myUid) {
myUid = app.globalData.userInfo.uid;
}
/**
* 获取拼团购订单数量
*/
let numParam = {
method: 'app.SpaceOrders.countGroupOrders',
uid: myUid
};
api.get({data:numParam})
.then(json => {
if (json && json.code && json.code == 200) {
this.data.groupOrdersCount = json.data.count;
this.setData({
groupOrdersCount: this.data.groupOrdersCount,
})
}
});
},
fetchInviteInfo: function() {
let params = {
method: 'app.invitecode.totalForMiniApp',
// method: 'app.invitecode.total',
};
api.get({data:params})
.then((json)=>{
if (json && json.code && json.code == 200) {
this.data.inviteInfo = json.data;
this.setData({
inviteInfo: this.data.inviteInfo,
})
}
})
.catch((error)=>{
});
},
setVipImg:function(e){
// console.log('current level'+e);
let img='';
if(e==1){
img = 'images/yin-vip@2x.png';
}else if(e == 2){
img = 'images/jin-vip@2x.png';
} else if (e == 3) {
img = 'images/baijin-vip@2x.png';
}
this.setData({
vipImg:img,
})
},
formatImgUrl: function(url) {
url = url.replace(new RegExp('{width}', 'gm'), '100').replace(new RegExp('{height}', 'gm'), '100').replace(new RegExp('{mode}', 'gm'), '1');
return url;
},
couponTapAction: function() {
if (!this.data.isLogin) {
tt.showToast({
title: "请先完成登录/注册,再查看!",
icon: 'none',
duration: 1500
});
return;
}
// console.log("点击优惠券事件");
tt.navigateTo({
url: '../../page/subPackage/pages/couponList/couponList',
})
},
navToGroupOrders:function() {
// logEvent(YB_MY_GRP_BUY,{});
if (!this.data.isLogin) {
tt.showToast({
title: "请先完成登录/注册,再查看!",
icon: 'none',
duration: 1500
});
return;
}
tt.navigateTo({
url: '../orders/groupOrders',
})
},
yohocoinTapAction: function() {
// console.log("click yohocoin action");
},
//============================copy me=======================//
hideModalTapped: function() {
hideModal(this);
},
getVerifyKeyBtnTapped: function() {
getVerifyCode(this, function(result){
// console.log(result);
})
},
phoneInputChanged: function (event) {
phoneInputChangedAction(event.detail.value, this)
},
bindBtnTapped: function() {
let that = this;
bindBtnAction(this, function(){
that.showUserInfo();
});
},
verifyCodeInputChanged: function(event) {
verifyCodeInputChangedAction(event.detail.value, this);
},
//============================copy me=======================//
scroll: function (e) {
var { scrollTop } = e.detail;
// console.log(e);
var isShow = scrollTop > windowHeight * 2 ? true : false;
if (isShow != this.data.isShowIndicator) {
this.setData({
isShowIndicator: isShow
});
}
},
backToTop: function () {
this.setData({
scrollTop: 0
})
},
navigateToLimitCodePage: function () {
if (!this.data.isLogin) {
tt.showToast({
title: "请先完成登录/注册,再查看!",
icon: 'none',
duration: 1500
});
return;
}
tt.navigateTo({
url: '../../page/subPackage/pages/limit/limit',
})
},
checkIsWechatCs: function() {
api.get({data:{
method: 'app.passport.checkIsWechatCs',
uid: app.getUid()
}})
.then(ret => {
if (ret && ret.code && ret.code == 200) {
this.setData({
isWechatService: ret.data.isWechatService == 'Y' ? true : false
});
if (ret.data.isWechatService == 'Y') {
this.getWechatShareCode();
}
}
});
},
getWechatShareCode: function() {
api.get({data:{
method: 'app.passport.getWechatShareCode',
uid: app.getUid()
}})
.then(ret => {
if (ret && ret.code && ret.code == 200) {
this.setData({
wechatShareCode: ret.data
});
}
});
}
}))