onLoad: function (e) {
var _this = this;
var xcxInfo = wx.getStorageSync(‘xcxInfo’);
var agent_id = decodeURIComponent(e.scene);//‘1’;
_this.setData({agent_id:agent_id});
if(!xcxInfo.wx_session){
wx.login({
success: function (res) {
var code = res.code;
var appid = app.globalData.appidd;
var SECRET = app.globalData.screctt;
if (code) {
wx.request({
url: ‘https://api.weixin.qq.com/sns/jscode2session?appid=’ + appid + ‘&secret=’ + SECRET + ‘&js_code=’ + code + ‘&grant_type=authorization_code’,
data: {},
method: ‘GET’,
success: function (req) {
var wx_openid = req.data.openid;
var wx_unionid = req.data.unionid;
var wx_session = req.data.session_key;
wx.setStorage({
key: “xcxInfo”,
data: {wx_openid: wx_openid, wx_unionid: wx_unionid, wx_session: wx_session },
success:function(d){
_this.request();
}
});
},
})
}
},
})
}else{
_this.request();
}
//var agent_id = ‘3’;
},
request:function(e){
var xcxInfo = wx.getStorageSync(‘xcxInfo’);
var openid = xcxInfo.wx_openid;
var _this = this;
var agent_id = _this.data.agent_id;
http.request({
method: ‘b2c.spread.getUser’,
openid: openid,
}, function (res) {
if(res.status==‘true’){
if(agent_id && agent_id!=‘undefined’){
if(res.userInfo.agent_id!=agent_id){
agent_id = res.userInfo.agent_id;
//获取代理商信息
http.request({
method: ‘b2c.spread.getAgentInfo’,
openid: openid,
agent_id:res.userInfo.agent_id,
}, function (res) {
_this.hideLoding();
_this.setData(res);
});
//该账号已经在其他公司注册
_this.setData({hadCode:‘true’});
return false;
}else{
_this.setData(res);
var placeholders = _this.data.userInfo.user_number;
var placeholder = 'http://m.imopark.com/insurance-car_info-2.html’+’?sn=’+placeholders//默认二维码生成文本
var size = _this.setCanvasSize();//动态设置画布大小
var initUrl = placeholder;
_this.createQrCode(initUrl, “mycanvas”, size.w, size.h);
//获取代理商信息
http.request({
method: ‘b2c.spread.getAgentInfo’,
openid: openid,
agent_id:res.userInfo.agent_id,
}, function (res) {
_this.hideLoding();
_this.setData(res);
});
}
}else{
agent_id = res.userInfo.agent_id;
_this.setData(res);
var placeholders = _this.data.userInfo.user_number;
var placeholder = 'http://m.imopark.com/insurance-car_info-2.html’+’?sn=’+placeholders//默认二维码生成文本
var size = _this.setCanvasSize();//动态设置画布大小
var initUrl = placeholder;
_this.createQrCode(initUrl, “mycanvas”, size.w, size.h);
//获取代理商信息
http.request({
method: ‘b2c.spread.getAgentInfo’,
openid: openid,
agent_id:res.userInfo.agent_id,
}, function (res) {
_this.hideLoding();
_this.setData(res);
});
}
wx.setStorage({ key: “member”, data: { agent_id: agent_id, openid: openid } })
}else if(res.status==‘1’){
if(agent_id && agent_id!=‘undefined’){
wx.redirectTo({
url: ‘…/register/register?agent_id=’+agent_id
})
}else{
wx.showModal({
title: ‘请扫码登陆!’,
success: function (res) {
_this.hideLoding();
if (res.confirm) {
wx.redirectTo({
url: ‘…/tips/index’,
})
}
}
})
}
}
});
},