|
|
|
@ -1,54 +1,58 @@ |
|
|
|
const app = getApp(); |
|
|
|
//引用封装好的加密解密js
|
|
|
|
// var Dec = require('../../utils/publicAES.js');
|
|
|
|
// console.log(Dec.Encrypt("需要加密的字符串"));
|
|
|
|
// console.log(Dec.Decrypt("需要解密的字符串"));
|
|
|
|
// pages/login/login.js
|
|
|
|
|
|
|
|
var network = require("../../utils/net.js"); |
|
|
|
|
|
|
|
var that = this; |
|
|
|
var openid; |
|
|
|
var Phone; |
|
|
|
var nickName; |
|
|
|
var gender; |
|
|
|
var province; |
|
|
|
var city; |
|
|
|
var country; |
|
|
|
var avatarUrl; |
|
|
|
var UnionId; |
|
|
|
var code; |
|
|
|
|
|
|
|
//获取openID 参数1、app.globalData.AppId 2、code
|
|
|
|
function getOpenId(successaction) { |
|
|
|
wx.login({ |
|
|
|
success: function(res) { |
|
|
|
code = res.code; |
|
|
|
var method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode'; |
|
|
|
var params = [app.globalData.AppId, code]; |
|
|
|
network.previousRequestLoading(method, params, function(res) { |
|
|
|
app.globalData.OpenId = res.result; |
|
|
|
successaction(app.globalData.OpenId) |
|
|
|
}) |
|
|
|
var app = getApp(); |
|
|
|
var openID; |
|
|
|
|
|
|
|
var isBindedPath = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountRpc/IsBinded'; |
|
|
|
var bindByPhone = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountRpc/XuBindByPhone'; |
|
|
|
var isBindWeixinPath = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP'; |
|
|
|
var getOpenIdByCode = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode'; |
|
|
|
var bindPath = "/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/Bind"; |
|
|
|
var getBindCustomer = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetBindCustomer'; |
|
|
|
var getCookie = '/MainSystem/MainSystem/Auth/WeixinLogin'; |
|
|
|
var getCustomerList = '/MainSystem/B3WeChatMiniProgram/Rpcs/CustomerRpc/GetList'; |
|
|
|
/** |
|
|
|
* 获取绑定客户ID及用户电话 参数1、appID 2、openID |
|
|
|
* 返回值globalCustomerID,WeixinUser_Phone |
|
|
|
* 成功调用获取cookie方法及判断是否绑定成功方法 |
|
|
|
*/ |
|
|
|
function GetBindCustomer(that) { |
|
|
|
let method = getBindCustomer; |
|
|
|
let params = [app.globalData.appID, app.globalData.openID]; |
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
if (res.result != null) { |
|
|
|
app.globalData.globalCustomerID = res.result.ID; |
|
|
|
app.globalData.phoneNum = res.result.WeixinUser_Phone; |
|
|
|
// 获取cookie值
|
|
|
|
WeixinLogin(function (res) { |
|
|
|
// 判断是否绑定成功 参数openid 返回值phoneNum
|
|
|
|
IsBinded(app.globalData.openID); |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//获取绑定的客户ID 参数1:appid, 参数2:openid 返回用户电话 客户ID 客户Name
|
|
|
|
function IsBind(openid, successaction) { |
|
|
|
var method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetBindCustomer'; |
|
|
|
var params = [app.globalData.AppId, openid]; |
|
|
|
network.previousRequestLoading(method, params, function(res) { |
|
|
|
app.globalData.CustomerId = res.result.ID; |
|
|
|
successaction(res.result.WeixinUser_Phone) |
|
|
|
/** |
|
|
|
* 判断是否绑定成功 参数openid |
|
|
|
* 返回值phoneNum |
|
|
|
* 成功调用是否关注公众号方法 |
|
|
|
*/ |
|
|
|
function IsBinded(openid) { |
|
|
|
let method = isBindedPath; |
|
|
|
let params = [openid]; |
|
|
|
network.transfer_request(method, params, function (res) { |
|
|
|
if (res.result != "") { |
|
|
|
app.globalData.phoneNum = res.result; |
|
|
|
// 判断是否关注公众号
|
|
|
|
IsBindWeixinMP(app.globalData.phoneNum) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
//绑定公众号 参数用户电话 返回true已关注 false未关注
|
|
|
|
// 判断是否关注公众号 参数phone 返回值bool 成功进入首页
|
|
|
|
function IsBindWeixinMP(phone) { |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP'; |
|
|
|
let method = isBindWeixinPath; |
|
|
|
let params = [phone]; |
|
|
|
network.previousRequestLoading(method, params, function(res) { |
|
|
|
//添加假数据。方便登录测试,提交版本需更正注释
|
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
// res.result = false;
|
|
|
|
if (res.result == true) { |
|
|
|
wx.switchTab({ |
|
|
|
@ -63,82 +67,138 @@ function IsBindWeixinMP(phone) { |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
// 获取cookie值 参数1、appID 2、openID
|
|
|
|
function WeixinLogin(successtion) { |
|
|
|
let method = getCookie; |
|
|
|
let params = [app.globalData.appID, app.globalData.openID]; |
|
|
|
network.transfer_request(method, params, function (res) { |
|
|
|
app.globalData.cookie = res.result; |
|
|
|
successtion(); |
|
|
|
}) |
|
|
|
} |
|
|
|
//绑定中转服务器客户对应信息 成功判断是否关注公众号
|
|
|
|
function Bind(that) { |
|
|
|
let userInfos = app.globalData.userInfo |
|
|
|
let method2 = bindPath; |
|
|
|
let params2 = [{ |
|
|
|
"AppId": app.globalData.appID, |
|
|
|
"OpenId": app.globalData.openID, |
|
|
|
"Phone": that.data.phoneNum, |
|
|
|
"NickName": userInfos.nickName, |
|
|
|
"Sex": userInfos.gender, |
|
|
|
"Province": userInfos.province, |
|
|
|
"City": userInfos.city, |
|
|
|
"Country": userInfos.country, |
|
|
|
"HeadImgUrl": userInfos.avatarUrl, |
|
|
|
"UnionId": "", |
|
|
|
"CustomerId": app.globalData.globalCustomerID |
|
|
|
}]; |
|
|
|
network.requestLoading(method2, params2, function (res) { |
|
|
|
if (res.result == true) { |
|
|
|
IsBindWeixinMP(app.globalData.phoneNum) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
Page({ |
|
|
|
data: { |
|
|
|
userInfo: "", |
|
|
|
array: [{ |
|
|
|
phoneNum: "", |
|
|
|
index: 0, |
|
|
|
customerArray: [{ |
|
|
|
ID: 0, |
|
|
|
Name: "请选择所属客户" |
|
|
|
}], |
|
|
|
index: 0, |
|
|
|
//根据customerID值判断是否隐藏选择框(默认显示)
|
|
|
|
showCustomerChoise: true, |
|
|
|
}, |
|
|
|
|
|
|
|
// 客户列表变更选项信息
|
|
|
|
listenerPickerSelected: function(e) { |
|
|
|
listenerPickerSelected: function (e) { |
|
|
|
this.setData({ |
|
|
|
index: e.detail.value, |
|
|
|
}); |
|
|
|
app.globalData.globalCustomerID = this.data.customerArray[this.data.index].ID; |
|
|
|
}, |
|
|
|
|
|
|
|
// 电话输入框
|
|
|
|
phoneNum: function(e) { |
|
|
|
Phone = e.detail.value |
|
|
|
app.globalData.Phone = Phone |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取所有客户列表
|
|
|
|
choiceCustomer: function(succession) { |
|
|
|
// 页面生命周期函数
|
|
|
|
onShow: function () { |
|
|
|
var that = this; |
|
|
|
var method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CustomerRpc/GetList'; |
|
|
|
var params = []; |
|
|
|
network.previousRequestLoading(method, params, function(res) { |
|
|
|
succession(); |
|
|
|
//由登录页面进入详情页变更值为0;分享直接进入为1
|
|
|
|
app.globalData.shareInState = 0; |
|
|
|
wx.login({ |
|
|
|
success: function (res) { |
|
|
|
let code = res.code; |
|
|
|
let method = getOpenIdByCode; |
|
|
|
let params = [app.globalData.appID, code]; |
|
|
|
// 获取openID
|
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
app.globalData.openID = res.result; |
|
|
|
// 获取绑定客户ID及用户电话
|
|
|
|
GetBindCustomer(that) |
|
|
|
}) |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 获取客户列表
|
|
|
|
let method = getCustomerList; |
|
|
|
let params = []; |
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
if (res.result.length > 0) { |
|
|
|
var lastArr = that.data.array.concat(res.result) |
|
|
|
var lastArr = that.data.customerArray.concat(res.result) |
|
|
|
that.setData({ |
|
|
|
array: lastArr, |
|
|
|
customerArray: lastArr, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 电话输入框
|
|
|
|
getPhone: function (e) { |
|
|
|
let val = e.detail.value; |
|
|
|
this.data.phoneNum = val; |
|
|
|
}, |
|
|
|
|
|
|
|
// 用户绑定按钮操作
|
|
|
|
getUserInfo: function(e) { |
|
|
|
// 获取授权 成功 绑定信息到客户服务器 回调函数绑定中转服务器
|
|
|
|
getUserInfo: function (e) { |
|
|
|
var that = this; |
|
|
|
if (e.detail.userInfo != null) { |
|
|
|
app.globalData.userInfo = e.detail.userInfo; |
|
|
|
nickName = app.globalData.userInfo.nickName; |
|
|
|
gender = app.globalData.userInfo.gender; |
|
|
|
province = app.globalData.userInfo.province; |
|
|
|
city = app.globalData.userInfo.city; |
|
|
|
country = app.globalData.userInfo.country; |
|
|
|
avatarUrl = app.globalData.userInfo.avatarUrl; |
|
|
|
//判断用户是否获取绑定信息
|
|
|
|
if (that.data.showCustomerChoise) { |
|
|
|
if (that.data.array[that.data.index].ID == 0) { |
|
|
|
wx.showToast({ |
|
|
|
image: '/imgs/avatar.png', |
|
|
|
title: '请选择所属客户', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} |
|
|
|
app.globalData.userInfo = e.detail.userInfo |
|
|
|
if (that.data.customerArray[that.data.index].ID == 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择所属客户', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (app.globalData.Phone == "") { |
|
|
|
if (this.data.phoneNum == "") { |
|
|
|
wx.showToast({ |
|
|
|
image: '/imgs/avatar.png', |
|
|
|
title: '手机号码不能为空', |
|
|
|
title: '请输入手机号码', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} else if (!(/^1[34578]\d{9}$/.test(app.globalData.Phone))) { |
|
|
|
} else if (!(/^1[34578]\d{9}$/.test(this.data.phoneNum))) { |
|
|
|
wx.showToast({ |
|
|
|
image: '/imgs/avatar.png', |
|
|
|
title: '号码不正确', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} |
|
|
|
let userInfos = app.globalData.userInfo |
|
|
|
let method = bindByPhone; |
|
|
|
let params = [{ |
|
|
|
"OpenId": app.globalData.openID, |
|
|
|
"Phone": this.data.phoneNum, |
|
|
|
"NickName": userInfos.nickName, |
|
|
|
"Sex": userInfos.gender, |
|
|
|
"Province": userInfos.province, |
|
|
|
"City": userInfos.city, |
|
|
|
"Country": userInfos.country, |
|
|
|
"HeadImgUrl": userInfos.avatarUrl, |
|
|
|
"UnionId": "" |
|
|
|
}]; |
|
|
|
network.transfer_request(method, params, function (res) { |
|
|
|
if (res.result != null) { |
|
|
|
app.globalData.phoneNum = that.data.phoneNum; |
|
|
|
// 判断是否绑定成功
|
|
|
|
Bind(that) |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.showModal({ |
|
|
|
title: '授权提示', |
|
|
|
@ -146,104 +206,5 @@ Page({ |
|
|
|
showCancel: false |
|
|
|
}) |
|
|
|
} |
|
|
|
var method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/Bind'; |
|
|
|
var params = [{ |
|
|
|
OpenId: openid, |
|
|
|
Phone: app.globalData.Phone, |
|
|
|
NickName: app.globalData.userInfo.nickName, |
|
|
|
Sex: app.globalData.userInfo.gender, |
|
|
|
Province: app.globalData.userInfo.province, |
|
|
|
City: app.globalData.userInfo.city, |
|
|
|
Country: app.globalData.userInfo.country, |
|
|
|
HeadImgUrl: app.globalData.userInfo.avatarUrl, |
|
|
|
UnionId: "", |
|
|
|
//请求新增参数
|
|
|
|
AppId: app.globalData.AppId, |
|
|
|
CustomerId: that.data.array[that.data.index].ID, |
|
|
|
}]; |
|
|
|
var storageCustomerID = that.data.array[that.data.index].ID; |
|
|
|
app.globalData.CustomerId = storageCustomerID; |
|
|
|
|
|
|
|
// 先绑定客户服务器
|
|
|
|
that.bindCustomerPreviousURL(function(res) { |
|
|
|
// 再绑定中转服务器
|
|
|
|
network.previousRequestLoading(method, params, function(res) { |
|
|
|
// 再判断是否关联公众号
|
|
|
|
IsBindWeixinMP(app.globalData.Phone); |
|
|
|
|
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 进入公众号绑定页面
|
|
|
|
bindPublicNumber: function(event){ |
|
|
|
wx.navigateTo({ |
|
|
|
url: '/pages/first/first?code=' + code, |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 绑定客户服务器
|
|
|
|
bindCustomerPreviousURL: function(successaction) { |
|
|
|
var method = '/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountRpc/XuBindByPhone'; |
|
|
|
var previousParams = [{ |
|
|
|
OpenId: openid, |
|
|
|
Phone: app.globalData.Phone, |
|
|
|
NickName: app.globalData.userInfo.nickName, |
|
|
|
Sex: app.globalData.userInfo.gender, |
|
|
|
Province: app.globalData.userInfo.province, |
|
|
|
City: app.globalData.userInfo.city, |
|
|
|
Country: app.globalData.userInfo.country, |
|
|
|
HeadImgUrl: app.globalData.userInfo.avatarUrl, |
|
|
|
UnionId: "", |
|
|
|
}]; |
|
|
|
network.requestLoading(method, previousParams, function(res) { |
|
|
|
successaction(res.result); |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 页面初始化 静默登录相关判断
|
|
|
|
onShow: function() { |
|
|
|
var that = this; |
|
|
|
this.choiceCustomer(function (res){ |
|
|
|
getOpenId(function (res) { |
|
|
|
openid = res; |
|
|
|
IsBind(openid, function (res) { |
|
|
|
app.globalData.Phone = res; |
|
|
|
if (res == "") { |
|
|
|
|
|
|
|
} else { |
|
|
|
//跳转到指定页面
|
|
|
|
IsBindWeixinMP(app.globalData.Phone) |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 用户点击右上角分享 |
|
|
|
*/ |
|
|
|
onShareAppMessage: function() { |
|
|
|
var that = this |
|
|
|
if (res.from === 'button') { |
|
|
|
// 来自页面内转发按钮
|
|
|
|
console.log(res.target) |
|
|
|
} |
|
|
|
return { |
|
|
|
title: '分享页面的标题', |
|
|
|
path: "/pages/login/login", |
|
|
|
//分享成功后执行
|
|
|
|
success: function(res) { |
|
|
|
console.log("--------------转发成功--------------------") |
|
|
|
}, |
|
|
|
|
|
|
|
fail: function(res) { |
|
|
|
console.log("--------------转发失败--------------------") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |