|
|
|
@ -0,0 +1,196 @@ |
|
|
|
// pages/login/login.js
|
|
|
|
|
|
|
|
var network = require("../../utils/net.js"); |
|
|
|
var app = getApp(); |
|
|
|
var openID; |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取绑定客户ID及用户电话 参数1、appID 2、openID |
|
|
|
* 返回值globalCustomerID,WeixinUser_Phone |
|
|
|
* 成功调用获取cookie方法及判断是否绑定成功方法 |
|
|
|
*/ |
|
|
|
function GetBindCustomer(that) { |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/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; |
|
|
|
WeixinLogin(function (res) { |
|
|
|
IsBinded(app.globalData.openID); |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
/** |
|
|
|
* 判断是否绑定成功 参数openid |
|
|
|
* 返回值phoneNum |
|
|
|
* 成功调用是否关注公众号方法 |
|
|
|
*/ |
|
|
|
function IsBinded(openid) { |
|
|
|
let method = '/MainSystem/B3MiniProgramRpc/Rpcs/ManagerRpc/AccountRpc/IsBinded'; |
|
|
|
let params = [openid]; |
|
|
|
network.newRequestLoading(method, params, function (res) { |
|
|
|
if (res.result != "") { |
|
|
|
app.globalData.phoneNum = res.result; |
|
|
|
IsBindWeixinMP(app.globalData.phoneNum) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
// 判断是否关注公众号 参数phone 返回值bool 成功进入首页
|
|
|
|
function IsBindWeixinMP(phone) { |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP'; |
|
|
|
let params = [phone]; |
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
// res.result = false;
|
|
|
|
if (res.result == true) { |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/indexL/indexL', |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.showModal({ |
|
|
|
title: '提示', |
|
|
|
content: '请关注公众号', |
|
|
|
showCancel: false, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
// 获取cookie值 参数1、appID 2、openID
|
|
|
|
function WeixinLogin(successtion) { |
|
|
|
let method = '/MainSystem/MainSystem/Auth/WeixinLogin'; |
|
|
|
let params = [app.globalData.appID, app.globalData.openID]; |
|
|
|
network.newRequestLoading(method, params, function (res) { |
|
|
|
app.globalData.cookie = res.result; |
|
|
|
successtion(); |
|
|
|
}) |
|
|
|
} |
|
|
|
//绑定中转服务器客户对应信息 成功判断是否关注公众号
|
|
|
|
function Bind(that) { |
|
|
|
let userInfos = app.globalData.userInfo |
|
|
|
let method2 = "/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/Bind"; |
|
|
|
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: { |
|
|
|
phoneNum: "", |
|
|
|
index: 0, |
|
|
|
customerArray: [{ |
|
|
|
ID: 0, |
|
|
|
Name: "请选择所属客户" |
|
|
|
}], |
|
|
|
}, |
|
|
|
|
|
|
|
// 客户列表变更选项信息
|
|
|
|
listenerPickerSelected: function (e) { |
|
|
|
this.setData({ |
|
|
|
index: e.detail.value, |
|
|
|
}); |
|
|
|
app.globalData.globalCustomerID = this.data.customerArray[this.data.index].ID; |
|
|
|
}, |
|
|
|
|
|
|
|
// 页面生命周期函数
|
|
|
|
onShow: function () { |
|
|
|
//由登录页面进入详情页变更值为0;分享直接进入为1
|
|
|
|
app.globalData.shareInState = 0; |
|
|
|
var that = this; |
|
|
|
wx.login({ |
|
|
|
success: function (res) { |
|
|
|
let code = res.code; |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode'; |
|
|
|
let params = [app.globalData.appID, code]; |
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
app.globalData.openID = res.result; |
|
|
|
GetBindCustomer(that) |
|
|
|
}) |
|
|
|
} |
|
|
|
}); |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CustomerRpc/GetList'; |
|
|
|
let params = []; |
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
if (res.result.length > 0) { |
|
|
|
var lastArr = that.data.customerArray.concat(res.result) |
|
|
|
that.setData({ |
|
|
|
customerArray: lastArr, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// 电话输入框
|
|
|
|
getPhone: function (e) { |
|
|
|
let val = e.detail.value; |
|
|
|
this.data.phoneNum = val; |
|
|
|
}, |
|
|
|
|
|
|
|
// 获取授权 成功 绑定信息到客户服务器 回调函数绑定中转服务器
|
|
|
|
getUserInfo: function (e) { |
|
|
|
var that = this; |
|
|
|
if (e.detail.userInfo != null) { |
|
|
|
app.globalData.userInfo = e.detail.userInfo |
|
|
|
if (that.data.array[that.data.index].ID == 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择所属客户', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (this.data.phoneNum == "") { |
|
|
|
wx.showToast({ |
|
|
|
title: '请输入手机号码', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} else if (!(/^1[34578]\d{9}$/.test(this.data.phoneNum))) { |
|
|
|
wx.showToast({ |
|
|
|
title: '号码不正确', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} |
|
|
|
let userInfos = app.globalData.userInfo |
|
|
|
let method = '/MainSystem/B3MiniProgramRpc/Rpcs/ManagerRpc/AccountRpc/QinBindByPhone'; |
|
|
|
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.newRequestLoading(method, params, function (res) { |
|
|
|
if (res.result != null) { |
|
|
|
app.globalData.phoneNum = that.data.phoneNum; |
|
|
|
Bind(that) |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.showModal({ |
|
|
|
title: '授权提示', |
|
|
|
content: '请给予权限,不涉及个人隐私', |
|
|
|
showCancel: false |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|