|
|
const app = getApp()
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
disabled: 0, //0不可点
|
|
|
getmsg: "获取验证码",
|
|
|
pop: 0,
|
|
|
tel: '',
|
|
|
userId: -1,
|
|
|
msgCode: '',
|
|
|
userUniqueCheck: true,//用户是否唯一
|
|
|
tapFlag:true, //点击手机号倒计时变红
|
|
|
regionMgrId:'',
|
|
|
reg_type:'a',
|
|
|
wxCode: '',
|
|
|
btnColor:false,
|
|
|
switch1Checked: false,
|
|
|
},
|
|
|
switch1Change: function (e) {
|
|
|
console.log("radio发生change事件,携带value值为:", e.detail.value);
|
|
|
console.log(e.detail.value);
|
|
|
|
|
|
var check = this.data.switch1Checked;
|
|
|
if (check) {
|
|
|
this.data.switch1Checked = false;
|
|
|
console.log("已取消选中");
|
|
|
wx.showToast({
|
|
|
title: "请先阅读并同意《服务协议》及《隐私政策》",
|
|
|
icon: "none",
|
|
|
duration: 2000,
|
|
|
});
|
|
|
} else {
|
|
|
this.data.switch1Checked = true;
|
|
|
console.log("已选中");
|
|
|
}
|
|
|
this.setData({
|
|
|
switch1Checked: this.data.switch1Checked,
|
|
|
});
|
|
|
|
|
|
// if(!e.detail.value){
|
|
|
|
|
|
// }
|
|
|
},
|
|
|
wxLogin() {
|
|
|
var that = this;
|
|
|
wx.login({
|
|
|
success(res) {
|
|
|
if (res.code) {
|
|
|
that.setData({
|
|
|
wxCode: res.code
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
console.log('获取code失败!' + res.errMsg)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
onLoad: function (options) {
|
|
|
},
|
|
|
onShow: function () {
|
|
|
// app.dialog("通知","请注意","知道了")
|
|
|
this.wxLogin();
|
|
|
},
|
|
|
changeBtn:function(e){
|
|
|
var myreg = /^[1][3456789][0-9]{9}$/;
|
|
|
if (myreg.test(e.detail.value)) {
|
|
|
console.log("验证码变色");
|
|
|
this.setData({
|
|
|
disabled: '1',
|
|
|
btnColor:true,
|
|
|
tel: e.detail.value
|
|
|
})
|
|
|
} else {
|
|
|
this.setData({
|
|
|
btnColor:false,
|
|
|
disabled: 0
|
|
|
})
|
|
|
}
|
|
|
|
|
|
},
|
|
|
showCha: function (e) {
|
|
|
var myreg = /^[1][3456789][0-9]{9}$/;
|
|
|
console.log(e.detail.value);
|
|
|
if (e.target.dataset.tel == 1) {
|
|
|
// && this.data.tapFlag
|
|
|
if (myreg.test(e.detail.value)) {
|
|
|
console.log("验证码变色");
|
|
|
this.setData({
|
|
|
disabled: 1,
|
|
|
btnColor:true,
|
|
|
tel: e.detail.value
|
|
|
})
|
|
|
} else {
|
|
|
this.setData({
|
|
|
btnColor:false,
|
|
|
disabled: 0
|
|
|
})
|
|
|
}
|
|
|
} else {
|
|
|
this.setData({
|
|
|
msgCode: e.detail.value
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
sendMsg: function () {
|
|
|
console.log(this.data.tel);
|
|
|
var that = this;
|
|
|
|
|
|
that.setData({
|
|
|
btnColor:false,
|
|
|
disabled: 0
|
|
|
})
|
|
|
|
|
|
that.getCode();
|
|
|
var timer = 1;
|
|
|
if (timer == 1) {
|
|
|
timer = 0
|
|
|
var time = 60
|
|
|
var inter = setInterval(function () {
|
|
|
that.setData({
|
|
|
getmsg: time + "s",
|
|
|
btnColor:false,
|
|
|
disabled: 0,
|
|
|
tapFlag:false
|
|
|
})
|
|
|
time--
|
|
|
if (time < 0) {
|
|
|
timer = 1
|
|
|
clearInterval(inter)
|
|
|
that.setData({
|
|
|
getmsg: "重新获取",
|
|
|
btnColor:true,
|
|
|
disabled: 1,
|
|
|
tapFlag:true
|
|
|
})
|
|
|
}
|
|
|
}, 1000)
|
|
|
}
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
getCode: function () {
|
|
|
var that = this;
|
|
|
wx.request({
|
|
|
url: app.globalData.ip + '/commons/sendMsgCode',
|
|
|
data: {
|
|
|
tel: that.data.tel
|
|
|
},
|
|
|
header: app.globalData.header,
|
|
|
method: "GET",
|
|
|
success: function (res) {
|
|
|
console.log("发送短信验证码");
|
|
|
console.log(res);
|
|
|
if (res.data.status == 200) {
|
|
|
} else if (res.data.status == 9999) {
|
|
|
app.dialogNotLogin();
|
|
|
} else {
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
getPhoneNumber(e) {
|
|
|
var that = this;
|
|
|
console.log(e)
|
|
|
console.log(e.detail.errMsg)
|
|
|
|
|
|
if ("getPhoneNumber:ok" == e.detail.errMsg) {//同意
|
|
|
var iv = e.detail.iv;
|
|
|
var encryptedData = e.detail.encryptedData;
|
|
|
wx.checkSession({
|
|
|
success () {
|
|
|
//session_key 未过期,并且在本生命周期一直有效
|
|
|
wx.request({
|
|
|
url: app.globalData.ip + '/getWechatTel',
|
|
|
data: {
|
|
|
code: that.data.wxCode,
|
|
|
iv: iv,
|
|
|
encryptedData: encryptedData,
|
|
|
type: "yishoudan",
|
|
|
appId:'wxd7aba642f7fd77fd'
|
|
|
},
|
|
|
success: function (res) {
|
|
|
console.log(res);
|
|
|
app.globalData.openId = res.data.data.openId;
|
|
|
app.globalData.unionid = res.data.data.unionid;
|
|
|
let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null);
|
|
|
promise.then(res => {
|
|
|
wx.reLaunch({
|
|
|
url: '/pages/me/index'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
|
|
|
},
|
|
|
fail: function (res) {
|
|
|
console.log("获取用户手机号错误");
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
fail () {
|
|
|
// session_key 已经失效,需要重新执行登录流程
|
|
|
wx.login({
|
|
|
success(res) {
|
|
|
if (res.code) {
|
|
|
console.log(res.code);
|
|
|
//发起网络请求
|
|
|
wx.request({
|
|
|
url: app.globalData.ip + '/getWechatTel',
|
|
|
data: {
|
|
|
code: res.code,
|
|
|
iv: iv,
|
|
|
encryptedData: encryptedData,
|
|
|
type: "dtdl",
|
|
|
appId:'wxd7aba642f7fd77fd'
|
|
|
},
|
|
|
success: function (res) {
|
|
|
console.log(res);
|
|
|
|
|
|
let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null);
|
|
|
promise.then(res => {
|
|
|
wx.reLaunch({
|
|
|
url: '/pages/me/index'
|
|
|
})
|
|
|
})
|
|
|
|
|
|
},
|
|
|
fail: function (res) {
|
|
|
console.log("获取用户手机号错误");
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
console.log('获取手机号失败!' + res.errMsg)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
|
|
|
} else {//拒绝
|
|
|
try {
|
|
|
wx.setStorageSync('comeFromPage', 'me');
|
|
|
} catch (e) {
|
|
|
console.log("0-页面跳转,设置参数错误:", e);
|
|
|
}
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/login/index',
|
|
|
})
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
formSubmit: function () {
|
|
|
|
|
|
app.load("登录中...");
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
|
console.log(this.data.tel)
|
|
|
|
|
|
if (this.data.tel == '') {
|
|
|
app.hideLoad();
|
|
|
app.showTips(that, '请输入正确手机号');
|
|
|
return;
|
|
|
}
|
|
|
if (this.data.msgCode == '') {
|
|
|
app.hideLoad();
|
|
|
app.showTips(that, '验证码不能为空');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
var channelContactId = '';
|
|
|
try {
|
|
|
var value = wx.getStorageSync('fromQrCodeChannelContactId')
|
|
|
if (value) {
|
|
|
console.log("fromQrCodeChannelContactId:======", value);
|
|
|
channelContactId = value;
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.log("获取缓存设置的参数错误:", e);
|
|
|
}
|
|
|
|
|
|
var agencyUserId = '';
|
|
|
try {
|
|
|
var value = wx.getStorageSync('storageSyncAgencyUserId')
|
|
|
if (value) {
|
|
|
console.log("storageSyncAgencyUserId======", value);
|
|
|
agencyUserId = value;
|
|
|
}
|
|
|
} catch (e) {
|
|
|
console.log("获取缓存设置的参数错误:", e);
|
|
|
}
|
|
|
|
|
|
wx.request({
|
|
|
url: app.globalData.ip + '/appLoginByTelYiShouDan',
|
|
|
data: {
|
|
|
tel: that.data.tel,
|
|
|
code: that.data.msgCode,
|
|
|
channelContactId: channelContactId,
|
|
|
agencyUserId: agencyUserId,
|
|
|
autoLoginTag: 0,
|
|
|
loginType: 'login',
|
|
|
isScanQRCodes: app.globalData.isScanQRCodes,
|
|
|
wxCode: that.data.wxCode,
|
|
|
appId:'wxd7aba642f7fd77fd'
|
|
|
},
|
|
|
header: {
|
|
|
'content-type': 'application/json'
|
|
|
},
|
|
|
success: function (res) {
|
|
|
app.hideLoad();
|
|
|
|
|
|
console.log(res.data);
|
|
|
|
|
|
if (res.data.status == 200) {
|
|
|
that.setLoginData(res);
|
|
|
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
icon: "none",
|
|
|
title: res.data.msg,
|
|
|
duration: 2000
|
|
|
})
|
|
|
}
|
|
|
|
|
|
}
|
|
|
})
|
|
|
//console.log('form发生了submit事件,携带数据为:', e.detail.value)
|
|
|
},
|
|
|
setLoginData(res) {
|
|
|
app.globalData.user = res.data.data.user;
|
|
|
app.globalData.sessionId = res.data.data.sessionId;
|
|
|
app.globalData.headers.Cookie = "JSESSIONID=" + res.data.data.sessionId;
|
|
|
app.globalData.headers2.Cookie = "JSESSIONID=" + res.data.data.sessionId;
|
|
|
app.globalData.isLogin = true;
|
|
|
app.globalData.agencyStatus = res.data.data.agencyStatus;
|
|
|
app.globalData.loginUserInfo = res.data.data;
|
|
|
//登录设置缓存
|
|
|
app.globalData.userLoginTokenInfo.tel = res.data.data.tel;
|
|
|
app.globalData.userLoginTokenInfo.token = null;
|
|
|
wx.setStorageSync("loginUserTokenInfo", app.globalData.userLoginTokenInfo);
|
|
|
|
|
|
console.log(111);
|
|
|
try {
|
|
|
var comeFrom = wx.getStorageSync("comeFromPage");
|
|
|
// var comeFromPageParam = wx.getStorageSync('comeFromPageParam');
|
|
|
console.log(comeFrom);
|
|
|
if (comeFrom == "me") {
|
|
|
wx.reLaunch({
|
|
|
url: "/pages/me/index",
|
|
|
});
|
|
|
} else if (comeFrom == "index") {
|
|
|
wx.reLaunch({
|
|
|
url: "/pages/index/index",
|
|
|
});
|
|
|
} else if (comeFrom == "detail") {
|
|
|
wx.navigateBack({
|
|
|
delta: 1,
|
|
|
});
|
|
|
|
|
|
// wx.reLaunch({
|
|
|
// url: "/pages/detail/index?storeJobId=" + comeFromPageParam.storeJobId
|
|
|
// })
|
|
|
} else if (comeFrom == "collect") {
|
|
|
wx.reLaunch({
|
|
|
url: "/pages/collect/index",
|
|
|
});
|
|
|
} else if (comeFrom == "BillInfo") {
|
|
|
// console.log(wx.getStorageSync('QRBillInfo'));
|
|
|
// console.log(JSON.stringify(wx.getStorageSync('QRBillInfo')));
|
|
|
wx.reLaunch({
|
|
|
url: "/pages/wodeBillDetail/index?info=" + JSON.stringify(wx.getStorageSync("QRBillInfo")),
|
|
|
});
|
|
|
wx.removeStorageSync("QRBillInfo");
|
|
|
} else {
|
|
|
wx.setStorage({
|
|
|
key: "comeFrom",
|
|
|
data: "login",
|
|
|
});
|
|
|
wx.reLaunch({
|
|
|
url: "/pages/index/index",
|
|
|
});
|
|
|
}
|
|
|
} catch (e) {
|
|
|
wx.setStorage({
|
|
|
key: "comeFrom",
|
|
|
data: "login",
|
|
|
});
|
|
|
wx.reLaunch({
|
|
|
url: "/pages/index/index",
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
ohShitfadeOut() {
|
|
|
var fadeOutTimeout = setTimeout(() => {
|
|
|
this.setData({ popErrorMsg: '', pop: 0 });
|
|
|
clearTimeout(fadeOutTimeout);
|
|
|
}, 3000);
|
|
|
},
|
|
|
|
|
|
})
|