home.js
2.76 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
import wx from '../../utils/wx';
import event from '../../common/event';
import Yas from '../../common/yas';
import homeModel from '../../models/home/index';
import accountModel from '../../models/account/index';
import {getPhoneNumber, getUserInfoLogin} from '../../common/login';
// 获取应用实例
let app = getApp();
let router = global.router;
let yas;
Page({
data: {
userInfo: {},
isLogin: false,
hasUnionID: false,
infoNum: {}
},
getUserInfoLogin,
getPhoneNumber,
onLoad: function() {
event.on('user-login-success', this.loginSucess);
event.on('bind-auto-register-type-report', params => {
yas.report('YB_REGISTER_SUCCESS', params);
});
event.on('wx-union-id-update', () => {
this.setData({
hasUnionID: !!app.globalData.unionID
});
});
yas = new Yas(app);
},
onShow: function() {
this.setData({
hasUnionID: !!app.getUnionID()
});
if (app.getUid()) {
this.showUserInfo();
}
this.getInfoNum();
yas.pageOpenReport();
yas.report('YB_MAIN_TAB_C', {TAB_ID: 4});
},
loginSucess: function() {
this.showUserInfo();
this.getInfoNum();
},
getInfoNum: function() {
if (app.getUid()) {
homeModel.infoNum({app_type: app.getAppType()})
.then(res => {
if (res.code === 200) {
this.data.infoNum = res.data;
this.setData({
infoNum: this.data.infoNum,
});
}
});
}
},
toOrdersTap: function(e) {
if (!this.data.isLogin) {
return wx.showToast({
title: '请先完成登录/注册,再查看!',
icon: 'none',
duration: 2000
});
}
let type = parseInt(e.currentTarget.dataset.type);
const EVENTS = {
1: 'YB_MY_ORD', // 我的订单
2: 'YB_MY_TOPAY', // 待付款
3: 'YB_MY_TOSEND', // 待发货
4: 'YB_MY_TOREC', // 待收货
};
yas.report(EVENTS[type]);
router.go('orderList', {type});
},
toAddress: function() {
if (!this.data.isLogin) {
return wx.showToast({
title: '请先完成登录/注册,再查看!',
icon: 'none',
duration: 2000
});
}
router.go('address');
},
toService: function() {
router.go('service');
},
showUserInfo: function() {
const defaultAvatar = 'https://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif';
accountModel.getProfile().then(res => {
wx.hideLoading();
this.setData({
isLogin: true,
userInfo: {
phoneNum: res.data.mobile,
nickName: res.data.nickname || res.data.profile_name,
avatarUrl: res.data.head_ico || defaultAvatar
}
});
}).catch(() => {
wx.hideLoading();
});
}
});