You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

678 lines
18 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const app = getApp();
const commonUtil = require("../../utils/commonUtil");
Page({
data: {
disabled: 0, //0不可点
getmsg: "获取验证码",
pop: 0,
tel: "",
userId: -1,
msgCode: "",
userUniqueCheck: true, //用户是否唯一
tapFlag: true, //点击手机号倒计时变红
regionMgrId: "",
reg_type: "a",
wxCode: "",
btnColor: false,
formPath: "",
loginType: "tel", // 登录类型
password: null,
},
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) {
var that = this;
console.log(options);
if (options.type) {
this.setData({
loginType: options.type,
});
}
this.setData({
formPath: options.path,
});
if (app.isNotEmptyCheck(options.scene)) {
console.log("XXXXXXXXXXXX")
//扫小程序码携带参数
var sceneStr = decodeURIComponent(options.scene);
var sceneJson = commonUtil.sceneToJson(sceneStr);
console.log("sceneJson===", sceneJson);
app.globalData.loginKey = sceneJson.loginKey
app.getLoginUserTokenInfo().then(res => {
console.log(res)
if(app.isNotEmptyCheck(app.globalData.loginKey)) {
app.globalData.loginKey = "";
if(app.globalData.loginUserInfo.agencyStatus == 1) {
wx.navigateTo({
url: '/pages/bocaiTV/index',
})
}
}
})
}
},
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,
});
}
},
/**
* 改变登录类型
*
*
*/
changeLoginType() {
this.setData({
loginType: this.data.loginType == "psw" ? "tel" : "psw",
});
},
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.headers,
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) {
//同意
wx.showLoading({
title: "登录中...",
});
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:app.globalData.appId
},
success: function (res) {
console.log(res);
app.globalData.openId = res.data.data.openId;
app.globalData.unionid = res.data.data.unionid;
app.globalData.isLogin = 1;
let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null);
promise.then((res) => {
try {
var comeFrom = wx.getStorageSync("comeFromPage");
console.log(comeFrom);
// debugger
// console.log(app.isNotEmptyCheck(that.globalData.loginKey));
// var comeFromPageParam = wx.getStorageSync('comeFromPageParam');
console.log(comeFrom);
if (comeFrom == "me") {
wx.reLaunch({
url: "/pages/mine/index",
});
} else if (comeFrom == "set") {
wx.reLaunch({
url: "../workBench/index",
});
} else if (comeFrom == "detail") {
wx.navigateBack({
delta: 1,
});
} else if (comeFrom == "detailBaoming") {
wx.reLaunch({
url: `../newEnroll/enroll/index?applyType=1&info=${wx.getStorageSync("baomingDetail")}`,
});
} else if (comeFrom == "collect") {
wx.reLaunch({
url: "/pages/collect/index",
});
} else if (comeFrom == "index") {
wx.reLaunch({
url: "/pages/index/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",
});
}
// if (app.isNotEmptyCheck(that.globalData.loginKey)){
// wx.redirectTo({
// url: 'pages/bocaiTV/index',
// })
// return
// }
} catch (e) {
wx.setStorage({
key: "comeFrom",
data: "login",
});
wx.reLaunch({
url: "/pages/index/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:app.globalData.appId
},
success: function (res) {
console.log(res);
let promise = app.setLoginUserTokenInfo(res.data.data.phoneNumber, null);
promise.then((res) => {
wx.reLaunch({
url: "/pages/index/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;
},
/**
* 登录信息提交前校验
*
*
*/
beforeFormSubmit(e) {
console.log(e);
let that = this;
if (that.data.loginType == "tel") {
this.formSubmit(e.detail.value);
} else {
this.pswLogin();
}
},
/**
* 账号密码登录
*
*
*/
pswLogin() {
let that = this;
app.load("登录中...");
console.log(that.data.tel);
console.log(that.data.password);
if (that.data.tel == "") {
app.hideLoad();
app.showTips(that, "请输入正确手机号");
return;
}
if (that.data.password == "") {
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 + "/yishoudan/login",
data: {
tel: that.data.tel,
password: that.data.password,
autoLoginTag: 0,
loginType: 0,
channelContactId: channelContactId,
agencyUserId: agencyUserId,
isScanQRCodes: app.globalData.isScanQRCodes,
wxCode: that.data.wxCode,
},
method: "post",
header: {
"content-type": "application/x-www-form-urlencoded",
},
success: function (res) {
app.hideLoad();
console.log(res.data);
if (res.data.status == 200) {
that.setLoginData(res);
wx.request({
url: app.globalData.ip + "/costumer/manager",
header: app.globalData.headers,
success(res) {
console.log(res);
if (res.data.status == 200) {
app.globalData.serviceInfo = res.data.data;
console.log(app.globalData.serviceInfo);
if (app.globalData.serviceInfo.workPhone) {
let tel = app.globalData.serviceInfo.workPhone;
let num1 = tel.slice(0, 3);
let num2 = tel.slice(3, 7);
let num3 = tel.slice(7, 11);
app.globalData.serviceInfo.tel = num1 + "-" + num2 + "-" + num3;
console.log(app.globalData.serviceInfo.tel);
}
}
},
});
console.log(222);
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
duration: 2000,
});
}
},
});
},
/**
* 手机验证登录
*
*
*/
formSubmit: function (data) {
app.load("登录中...");
var that = this;
if (that.data.tel == "") {
app.hideLoad();
app.showTips(that, "请输入正确手机号");
return;
}
if (that.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);
}
console.log(that.data.tel);
// if (that.data.tel == "18537774") {
// // (app.globalData.header.Authorization = "Bearer " + "eyJUeXBlIjoiSnd0IiwidHlwIjoiSldUIiwiYWxnIjoiSFMyNTYifQ.eyJ0b2tlbiI6IntcImNyZWF0ZWRcIjoxNjg2OTA0NDEzMzM0LFwidGVsXCI6XCIxODUzNzc3MjI0NFwiLFwidXNlcklkXCI6MzEyNDk2LFwidXNlck5hbWVcIjpcIumZiOe7j-eQhlwifSJ9.9Z0cqhQ9o7dKyxyLflUcT6MhkdkmPXOs49wHjM4z1ko"),
// wx.request({
// url: app.globalData.ip + "/appLoginByToken",
// header: app.globalData.header,
// success: function (res) {
// console.log(res);
// if (app.isNotEmptyCheck(res.data)) {
// 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 = "eyJUeXBlIjoiSnd0IiwidHlwIjoiSldUIiwiYWxnIjoiSFMyNTYifQ.eyJ0b2tlbiI6IntcImNyZWF0ZWRcIjoxNjg2OTA0NDEzMzM0LFwidGVsXCI6XCIxODUzNzc3MjI0NFwiLFwidXNlcklkXCI6MzEyNDk2LFwidXNlck5hbWVcIjpcIumZiOe7j-eQhlwifSJ9.9Z0cqhQ9o7dKyxyLflUcT6MhkdkmPXOs49wHjM4z1ko";
// wx.setStorageSync("loginUserTokenInfo", app.globalData.userLoginTokenInfo);
// try {
// var comeFrom = wx.getStorageSync("comeFromPage");
// // var comeFromPageParam = wx.getStorageSync('comeFromPageParam');
// console.log(comeFrom);
// if (comeFrom == "me") {
// wx.reLaunch({
// url: "/pages/index/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/workBench/index",
// });
// }
// } catch (e) {
// wx.setStorage({
// key: "comeFrom",
// data: "login",
// });
// wx.reLaunch({
// url: "/pages/index/index",
// });
// }
// } else {
// }
// },
// });
// } else {
wx.request({
url: app.globalData.ip + "/appLoginByTelYiShouDan",
data: {
tel: that.data.tel,
code: that.data.msgCode,
autoLoginTag: 0,
loginType: "login",
channelContactId: channelContactId,
agencyUserId: agencyUserId,
isScanQRCodes: app.globalData.isScanQRCodes,
wxCode: that.data.wxCode,
},
header: {
"content-type": "application/json",
},
success: function (res) {
app.hideLoad();
console.log(res.data);
if (res.data.status == 200) {
that.setLoginData(res);
console.log(222);
} else {
wx.showToast({
icon: "none",
title: res.data.msg,
duration: 2000,
});
}
},
});
// }
},
/**
* 将传回的登录信息存储以及页面的跳转
*
*
*/
setLoginData(res) {
console.log(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 (app.isNotEmptyCheck(that.globalData.loginKey)){
wx.redirectTo({
url: 'pages/bocaiTV/index',
})
}
if (comeFrom == "me") {
wx.reLaunch({
url: "/pages/index/index",
});
} else if (comeFrom == "index") {
wx.reLaunch({
url: "/pages/index/index",
});
} else if (comeFrom == "detail") {
wx.navigateBack({
delta: 1,
});
} 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/workBench/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);
},
});