index.js
4.08 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
// index.js
import wx from '../../utils/wx';
import accountModel from '../../models/account/index';
import indexModel from '../../models/home/coupon/index';
import Yas from '../../common/yas';
import goMiniApp from '../../router/jump-to-miniapp';
let app = getApp();
let yas;
Page({
data: {
notLogin: true, // 默认未登录
discountCoupon: 0,
experienceCoupon: 0,
coinNum: 0,
userInfo: {
phoneNum: '',
avatarUrl: '',
defaultAvatar: false,
nickName: '',
vipImg: '',
growth: 0
},
myQrCodeUrl: 'https://m.yohobuy.com/home/user/qrcode'
},
onLoad: function() {
yas = new Yas(app); // 实例化埋点
yas.pageOpenReport();
},
onShow: function() {
app = app || getApp();
this.showBindUserInfo();
},
showBindUserInfo: function() {
app = app || getApp();
if (!(app && app.getUid())) {
setTimeout(() => {
this.setData({notLogin: true});
}, 10);
indexModel.indexData({uid: '1000000000'}).then(res => {
this.setData({
discountCoupon: 0,
experienceCoupon: 0
});
});
return Promise.resolve({code: 401, data: [], message: '未登录'});
}
accountModel.getProfile().then((res) => {
let defaultAvatar = '../../static/images/icons/default-avatar.png';
let resUserInfo = res.data || {};
let vip_level = resUserInfo.vip_info.cur_level
let vipImg = this.setVipImg(vip_level)
this.setData({
notLogin: false,
userInfo: Object.assign({}, this.data.userInfo, app.globalData.userInfo, {
nickName: resUserInfo.nickname,
avatarUrl: resUserInfo.head_ico || defaultAvatar,
phoneNum: resUserInfo.mobile,
defaultAvatar: (resUserInfo.head_ico || defaultAvatar) === defaultAvatar,
growth: resUserInfo.vip_info.cur_growth,
vipImg
})
});
})
accountModel.getCoinTotal().then((res) => {
if (res.code !== 200) {
return Promise.reject();
}
this.setData({
coinNum: res.data && res.data.total || 0
});
}).catch(() => {})
indexModel.experienceCount().then((res) => {
if (res.code !== 200) {
return Promise.reject();
}
let experienceCoupon = res && res.data && res.data.couponQty;
this.setData({
experienceCoupon
});
}).catch(() => { })
indexModel.discountCount().then((res) => {
if (res.code !== 200) {
return Promise.reject();
}
let discountCoupon = res && res.data && res.data.couponQty;
this.setData({
discountCoupon
});
}).catch(() => { })
},
setVipImg: function (e) {
let img = '';
if (e == 1) {
img = '../../static/images/my/silver@3x.png';
} else if (e == 2) {
img = '../../static/images/my/gold@3x.png';
} else if (e == 3) {
img = '../../static/images/my/platinum@3x.png';
}
return img
},
//点击我的二维码
tapMyQRCode() {
let url = '../webview/webview?url=' + this.data.myQrCodeUrl;
wx.navigateTo({
url,
})
},
tapNavItem: function({target}) {
let that = this
let type = target.dataset.type;
if (!type) {
return;
}
const funcs = {
order: () => {
goMiniApp({
app: 'yohobuy',
page: 'orders'
});
},
couponList:() => {
global.router.go('couponList')
},
yohoCoin: () => {
global.router.go('yohoCoin', { coinTotal: that.data.coinNum});
},
experience: () => {
global.router.go('experience');
},
setting: () => {
global.router.go('setting');
}
};
funcs[type] && funcs[type]();
}
});