togoin.js
8.73 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
var t = require("../../utils/common.js");
const app=getApp();
var os = app.globalData.setting;
var regeneratorRuntime = require('../../utils/runtime.js');
Page({
data: {
user:null,
show_bind:0,
imghots: os.imghost,
store_logo:'',
first_leader:'', //-- 邀请人 --
config2:null,
},
onLoad: function (options) {
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
getApp().globalData.isLoad_ad=1;
//--判断是否有接受到邀请人的ID--
if(options.first_leader){
this.setData({first_leader:options.first_leader});
}else if(getApp().globalData.first_leader){
this.setData({first_leader:getApp().globalData.first_leader});
}
var th=this;
app.getConfig(function (e) {
var logo=th.data.imghots+e.store_logo;
th.setData({ store: e,store_logo:logo});
})
//判断注册的条件
app.getConfig2(function (e) {
if(e.reg_type==1){
var arr=JSON.parse(e.reg_info);
if(arr['name_state']==1) th.data.name_need_go=1;
if(arr['birthday_state']==1) th.data.birth_need_go=1;
if(arr['idcard_state']==1) th.data.idcard_need_go=1;
if(arr['address_state']==1) th.data.address_need_go=1;
if(arr['pick_state']==1) th.data.pick_need_go=1;
if(arr['sex_state']==1) th.data.sex_need_go=1;
if(arr['introducer_state']==1) th.data.introducer_need_go=1;
}
},1)
},
//绑定手机号
getphone:function (e) {
//接下来写业务代码登录
e=e.detail;
if (e.encryptedData==undefined){
return app.my_warnning("登录需要授权手机号码!", 0, this);
that.setData({show_bind:0})
return false;
}
var th=this;
var sessionKey = getApp().globalData.sessionKey;
var openid = getApp().globalData.openid;
var r=getApp().globalData.getu;
th.save_the_data(r,e,sessionKey,openid)
},
//-- 会员授权 --
bindGetUserInfo: function(ee) {
var that = this;
//-- 点击授权 --
that.getUserProfile(function(res){
var user=res;
//--拿下code--
wx.login({
success: function (o) {
var dd = {
js_code:o.code,
store_id: os.stoid,
nickname: app.clear_word(app.globalData.getu.nickName),
head_pic: app.clear_word(app.globalData.getu.avatarUrl)
};
//-- 导购会员ID --
if(getApp().globalData.guide_id){
dd.guide_id=getApp().globalData.guide_id;
}
getApp().request.get("/api/weshop/users/openidandkey", {
data: dd,
success: function (e) {
if(e.data.code==0){
that.setData({user:user})
//如果有会员的话,没有sessionKey
if(!e.data.data.sessionKey){
getApp().showWarning("登录成功");
getApp().globalData.userInfo=e.data.data;
getApp().globalData.user_id=e.data.data.user_id;
getApp().globalData.openid = e.data.data.weapp_openid;
//把会员的信息存在内存
wx.setStorageSync("userinfo",e.data.data);
setTimeout(function () {
wx.navigateBack({ delta: 1}) //返回上一页
},1000)
}else{
getApp().globalData.sessionKey=e.data.data.sessionKey;
getApp().globalData.openid=e.data.data.openid;
that.setData({show_bind:1});
}
}else{
getApp().confirmBox(e.data.msg);
}
}
});
}
})
})
},
//-- 调整后的获取会员信息 --
getUserProfile:function(func){
var that=this;
wx.getUserProfile({
desc:'获取用户相关信息',
success:res=>{
console.log("getUserProfile",res);
//此处授权得到userInfo
getApp().globalData.getu = res.userInfo;
func(res.userInfo);
}
});
},
//暂不登录,返回上一页
cancle_bind:function () {
wx.navigateBack({ delta: 1})
},
close_pop:function(){
this.setData({show_bind:0})
},
show_bind_mobile:function(){
this.setData({show_bind:1})
},
save_the_data: async function (r,e,sessionKey,openid) {
var app=getApp(),a=app,th=this;
var dd = {
oauth: "miniapp",
nickname:a.clear_word(r.nickName),
head_pic: r.avatarUrl,
sex: r.gender,
terminal: "miniapp",
sessionKey: sessionKey,
openid:openid,
encryptedData: e.encryptedData,
iv: e.iv,
store_id: getApp().globalData.setting.stoid,
};
//--如果有邀请人的时候--
if(th.data.first_leader){
//判断一下分享人是不是分享商
await app.request.promiseGet("/api/weshop/users/get/" + os.stoid+"/"+th.data.first_leader,{}).then(res=>{
if(res.data.code==0){
var user= res.data.data;
if(user.is_distribut==1){
dd.first_leader=th.data.first_leader;
}
}
})
}
//-- 导购会员ID --
if(getApp().globalData.guide_id){
dd.guide_id=getApp().globalData.guide_id;
}
console.log("-----会员注册的信息-------");
console.log(dd);
app.request.get("/api/weshop/users/thirdLogin", {
data: dd,
success: function (e) {
if (e.data.code == 0) {
app.globalData.user_id = e.data.data.user_id;
} else {
return app.showWarning("授权登入失败!"+e.data.msg);
}
var need_go=0;
var tuser=e.data.data;
wx.setStorageSync("userinfo",e.data.data);
wx.setStorageSync("isAuth", !0), app.globalData.userInfo = e.data.data, app.globalData.userInfo.head_pic = t.getFullUrl(a.globalData.userInfo.head_pic);
//获取一下线下的真实资料
let url3 = '/api/weshop/users/getERPUser/';
url3 += os.stoid + "/" +tuser.user_id;
getApp().promiseGet(url3,{}).then(res=>{
if(res.data.code == 0) {
let t_user = res.data.data;
//如果有需要完善的信息没有完善,就需要跳转
if (!t_user['vipname'] && th.data.name_need_go) {
need_go = 1;
}
if (!t_user['birthday'] && th.data.birth_need_go) {
need_go = 1;
}
if (!t_user['idcard'] && th.data.idcard_need_go) {
need_go = 1;
}
if (!t_user['address'] && th.data.address_need_go) {
need_go = 1;
}
if (!t_user['pickup_id'] && th.data.pick_need_go) {
need_go = 1;
}
if (!t_user['sex'] && th.data.sex_need_go) {
need_go = 1;
}
if (!t_user['fromuser_id'] && th.data.introducer_need_go) {
need_go = 1;
}
if (need_go) {
getApp().goto("/packageA/pages/profile/profile");
} else {
wx.navigateBack({delta: 1})
}
}
})
},
failStatus: function (t) {
return app.my_warnning("授权登入失败,请稍后再试!", 0, that);
},
fail: function (t) {
return i.clearAuth(), i.alertLoginErrorAndGoHome(), !1;
}
});
},
bind_bnerr:function(e){
var _errImg = e.target.dataset.errorimg;
var _errObj = {};
_errObj[_errImg] = this.data.imghots+"/miniapp/images/logo.png";
this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
},
//-- 会员授权 --
bindUserInfo: function(ee) {
var that = this;
var user=ee.detail.userInfo;
//此处授权得到userInfo
getApp().globalData.getu = user;
//--拿下code--
wx.login({
success: function (o) {
var dd = {
js_code:o.code,
store_id: os.stoid,
nickname: app.clear_word(app.globalData.getu.nickName),
head_pic: app.clear_word(app.globalData.getu.avatarUrl)
};
//-- 导购会员ID --
if(getApp().globalData.guide_id){
dd.guide_id=getApp().globalData.guide_id;
}
getApp().request.get("/api/weshop/users/openidandkey", {
data: dd,
success: function (e) {
if(e.data.code==0){
that.setData({user:user})
//如果有会员的话,没有sessionKey
if(!e.data.data.sessionKey){
getApp().showWarning("登录成功");
getApp().globalData.userInfo=e.data.data;
getApp().globalData.user_id=e.data.data.user_id;
getApp().globalData.openid = e.data.data.weapp_openid;
//把会员的信息存在内存
wx.setStorageSync("userinfo",e.data.data);
setTimeout(function () {
wx.navigateBack({ delta: 1}) //返回上一页
},1000)
}else{
getApp().globalData.sessionKey=e.data.data.sessionKey;
getApp().globalData.openid=e.data.data.openid;
that.setData({show_bind:1});
}
}else{
getApp().confirmBox(e.data.msg);
}
}
});
}
})
}
})