|
|
|
@ -4,23 +4,13 @@ var network = require("../../utils/net.js"); |
|
|
|
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'; |
|
|
|
var getCurrentID ="/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountRpc/GetCurrentCustomerID" |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取绑定客户ID及用户电话 参数1、appID 2、openID |
|
|
|
* 返回值globalCustomerID,WeixinUser_Phone |
|
|
|
* 成功调用获取cookie方法及判断是否绑定成功方法 |
|
|
|
*/ |
|
|
|
function GetBindCustomer(that) { |
|
|
|
let method = getBindCustomer; |
|
|
|
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) { |
|
|
|
@ -28,54 +18,16 @@ function GetBindCustomer(that) { |
|
|
|
app.globalData.phoneNum = res.result.WeixinUser_Phone; |
|
|
|
// 获取cookie值
|
|
|
|
WeixinLogin(function (res) { |
|
|
|
// 判断是否绑定成功 参数openid 返回值phoneNum
|
|
|
|
IsBinded(app.globalData.openID); |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/homePage/homePage', |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
/** |
|
|
|
* 判断是否绑定成功 参数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) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
// 判断是否关注公众号 参数phone 返回值bool 成功进入首页
|
|
|
|
function IsBindWeixinMP(phone) { |
|
|
|
let method = isBindWeixinPath; |
|
|
|
let params = [phone]; |
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
// res.result = false;
|
|
|
|
// 取消获取当前用户的ID值
|
|
|
|
setCurrentCustomerID(); |
|
|
|
|
|
|
|
if (res.result == true) { |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/homePage/homePage', |
|
|
|
}) |
|
|
|
} else { |
|
|
|
wx.showModal({ |
|
|
|
title: '提示', |
|
|
|
content: '请关注公众号', |
|
|
|
showCancel: false, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
// 跳转前获取客户自己的ID 存储后在创建订单时 基本信息带出使用
|
|
|
|
function setCurrentCustomerID (){ |
|
|
|
let method = getCurrentID; |
|
|
|
let method = "/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountRpc/GetCurrentCustomerID"; |
|
|
|
let params = []; |
|
|
|
network.transfer_request(method, params, function (res) { |
|
|
|
console.log("当前客户信息==" + res.result); |
|
|
|
@ -92,12 +44,14 @@ function WeixinLogin(successtion) { |
|
|
|
successtion(); |
|
|
|
}) |
|
|
|
} |
|
|
|
//绑定中转服务器客户对应信息 成功判断是否关注公众号
|
|
|
|
function Bind(that) { |
|
|
|
|
|
|
|
//2次绑定第二次 绑定客户 要有先后
|
|
|
|
function XuBindByPhone(that) { |
|
|
|
let userInfos = app.globalData.userInfo |
|
|
|
let method2 = bindPath; |
|
|
|
let method2 = "/MainSystem/B3MiniProgramRpc/XuRpcs/Customer/AccountRpc/XuBindByPhone"; |
|
|
|
let params2 = [{ |
|
|
|
"AppId": app.globalData.appID, |
|
|
|
"UserName": that.data.userName, |
|
|
|
"Password": that.data.psw, |
|
|
|
"OpenId": app.globalData.openID, |
|
|
|
"Phone": that.data.phoneNum, |
|
|
|
"NickName": userInfos.nickName, |
|
|
|
@ -107,31 +61,25 @@ function Bind(that) { |
|
|
|
"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) |
|
|
|
network.newRequestLoading(method2, params2, function (res) { |
|
|
|
if (res.result != null) { |
|
|
|
WeixinLogin(function () { |
|
|
|
wx.switchTab({ |
|
|
|
url: '/pages/homePage/homePage', |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
Page({ |
|
|
|
data: { |
|
|
|
phoneNum: "", |
|
|
|
code: "", |
|
|
|
userName: "", |
|
|
|
psw: "", |
|
|
|
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; |
|
|
|
phoneNum: "", |
|
|
|
}, |
|
|
|
|
|
|
|
// 页面生命周期函数
|
|
|
|
@ -140,7 +88,7 @@ Page({ |
|
|
|
wx.login({ |
|
|
|
success: function (res) { |
|
|
|
let code = res.code; |
|
|
|
let method = getOpenIdByCode; |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode'; |
|
|
|
let params = [app.globalData.appID, code]; |
|
|
|
// 获取openID
|
|
|
|
network.requestLoading(method, params, function (res) { |
|
|
|
@ -150,21 +98,20 @@ Page({ |
|
|
|
}) |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// 获取客户列表
|
|
|
|
let method = getCustomerList; |
|
|
|
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, |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
//获取企业编号
|
|
|
|
getCode: function (e) { |
|
|
|
this.data.code = e.detail.value; |
|
|
|
}, |
|
|
|
//获取用户名
|
|
|
|
getUserName: function (e) { |
|
|
|
this.data.userName = e.detail.value; |
|
|
|
}, |
|
|
|
//获取密码
|
|
|
|
getPSW: function (e) { |
|
|
|
this.data.psw = e.detail.value; |
|
|
|
}, |
|
|
|
// 电话输入框
|
|
|
|
getPhone: function (e) { |
|
|
|
let val = e.detail.value; |
|
|
|
@ -176,12 +123,6 @@ Page({ |
|
|
|
var that = this; |
|
|
|
if (e.detail.userInfo != null) { |
|
|
|
app.globalData.userInfo = e.detail.userInfo |
|
|
|
if (that.data.customerArray[that.data.index].ID == 0) { |
|
|
|
wx.showToast({ |
|
|
|
title: '请选择所属客户', |
|
|
|
}) |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (this.data.phoneNum == "") { |
|
|
|
wx.showToast({ |
|
|
|
title: '请输入手机号码', |
|
|
|
@ -194,8 +135,10 @@ Page({ |
|
|
|
return false; |
|
|
|
} |
|
|
|
let userInfos = app.globalData.userInfo |
|
|
|
let method = bindByPhone; |
|
|
|
let method = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/BindCustomerCode'; |
|
|
|
let params = [{ |
|
|
|
"AppId": app.globalData.appID, |
|
|
|
"CustomerCode": this.data.code, |
|
|
|
"OpenId": app.globalData.openID, |
|
|
|
"Phone": this.data.phoneNum, |
|
|
|
"NickName": userInfos.nickName, |
|
|
|
@ -208,9 +151,8 @@ Page({ |
|
|
|
}]; |
|
|
|
network.transfer_request(method, params, function (res) { |
|
|
|
if (res.result != null) { |
|
|
|
app.globalData.phoneNum = that.data.phoneNum; |
|
|
|
// 判断是否绑定成功
|
|
|
|
Bind(that) |
|
|
|
app.globalData.globalCustomerID = res.result; |
|
|
|
XuBindByPhone(that); |
|
|
|
} |
|
|
|
}) |
|
|
|
} else { |
|
|
|
|