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

303 lines
8.5 KiB

// pages/login/login.js
var ID;
var Idcard = "";
var openid;
var Phone;
var nickName;
var gender;
var province;
var city;
var country;
var avatarUrl;
var UnionId;
const app = getApp()
var network = require("../../utils/net.js")
var getOpenIdByCode = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetMiniOpenIdByCode';
var getCustomerList = '/MainSystem/B3WeChatMiniProgram/Rpcs/CustomerRpc/GetList';
var getBindCustomer = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/GetBindCustomer';
var isBindWeixinPath = '/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/IsBindWeixinMP';
// 直接请求青花瓷服务器获取绑定信息的返回
var bindPath = "/MainSystem/B3WeChatMiniProgram/Rpcs/CommonRpc/Bind";
// var XuBindDriver = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/XuBindDriver'
var bindByPhone = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/XuBindByPhone';
var GetDriverByIdCard = "/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetDriverByIdCard"
var GetDriverByOpenId = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetDriverByOpenId'
var isBindedPath = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/IsBinded';
//获取openID 参数1、app.globalData.AppId 2、code
function getOpenId(successaction) {
wx.login({
success: function(res) {
var code = res.code;
var method = getOpenIdByCode;
var params = [app.globalData.AppId, code];
network.requestLoading(method, params, function(res) {
app.globalData.OpenId = res.result;
successaction(app.globalData.OpenId)
})
}
})
}
//获取绑定的客户ID 参数1:appid, 参数2:openid 返回用户电话 客户ID 客户Name
function IsBind(openid, successaction) {
var method = getBindCustomer;
var params = [app.globalData.AppId, openid];
network.requestLoading(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.Phone = res.result;
// 判断是否关注公众号
IsBindWeixinMP(app.globalData.Phone)
}
})
}
//绑定公众号 参数用户电话 返回true已关注 false未关注
function IsBindWeixinMP(phone) {
let method = isBindWeixinPath;
let params = [phone];
network.requestLoading(method, params, function(res) {
//添加假数据。方便登录测试,提交版本需更正注释
// res.result = false;
if (res.result == true) {
wx.switchTab({
url: '/pages/homePage/homePage',
})
} else {
wx.showModal({
title: '提示',
content: '请关注公众号',
showCancel: false,
})
}
})
}
Page({
data: {
idCard: "",
customerList: [{
ID: 0,
Name: "请选择所属客户"
}],
customerIndex: 0,
},
// 绑定客户
listenerPickerSelected: function(e) {
this.setData({
customerIndex: e.detail.value,
});
app.globalData.CustomerId = this.data.customerList[this.data.customerIndex].ID;
},
// // 姓名
// getDriverName: function(e) {
// app.globalData.UserName = e.detail.value
// },
// 手机号码
getPhone: function(e) {
Phone = e.detail.value;
app.globalData.Phone = Phone;
},
// 身份证
// getIDCardNum: function(e) {
// if (!app.globalData.CustomerId) {
// wx: wx.showModal({
// title: '提示',
// content: '请先绑定客户',
// });
// return;
// }
// var that = this;
// if (e.detail.value.length == 18) {
// Idcard = e.detail.value;
// var method = GetDriverByIdCard;
// var params = [1, Idcard];
// network.transfer_request(method, params, function(res) {
// //res就是我们请求接口返回的数据
// if (res.result != null) {
// app.globalData.UserName = res.result.Name,
// app.globalData.Phone = res.result.Telephone;
// that.setData({
// name: res.result.Name,
// phoneNum: res.result.Telephone,
// })
// }
// })
// }
// },
// 获取所有客户列表
choiceCustomer: function() {
var that = this;
var method = getCustomerList;
var params = [];
network.requestLoading(method, params, function(res) {
if (res.result.length > 0) {
var lastArr = that.data.customerList.concat(res.result)
that.setData({
customerList: lastArr,
})
}
})
},
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.customerList[that.data.customerIndex].ID == 0) {
wx.showToast({
image: '/imgs/ddpc.png',
title: '请选择所属客户',
})
return false;
}
// 判断电话号码信息
if (app.globalData.Phone == "") {
wx.showToast({
image: '/imgs/ddpc.png',
title: '手机号码不能为空',
})
return false;
}
if (!(/^1[34578]\d{9}$/.test(app.globalData.Phone))) {
wx.showToast({
image: '/imgs/ddpc.png',
title: '号码不正确',
})
return false;
}
// 判断用户姓名
// if (app.globalData.UserName == "") {
// wx.showToast({
// image: '/imgs/ddpc.png',
// title: '用户姓名不能为空',
// })
// return false;
// }
// 判断身份证信息
// if ((Idcard.length < 18) || (Idcard.length > 18)) {
// wx.showToast({
// image: '/imgs/ddpc.png',
// title: '身份证号不正确',
// })
// return false;
// }
} else {
wx.showModal({
title: '授权提示',
content: '请给予权限,不涉及个人隐私',
showCancel: false,
})
return false;
}
var method = bindByPhone;
let params = [{
"OpenId": app.globalData.OpenId,
"Phone": app.globalData.Phone,
"NickName": nickName,
"Sex": gender,
"Province": province,
"City": city,
"Country": country,
"HeadImgUrl": avatarUrl,
"UnionId": ""
}];
// var params = [{
// // "Domain_ID": that.data.array[that.data.index].ID,
// "Driver_Name": app.globalData.UserName,
// "Phone": app.globalData.Phone,
// "IdCard": Idcard,
// "OpenId": app.globalData.OpenId,
// "NickName": nickName,
// "Sex": gender,
// "Province": province,
// "City": city,
// "Country": country,
// "HeadImgUrl": avatarUrl,
// "UnionId": " "
// }];
var transferParams = [{
"OpenId": app.globalData.OpenId,
"Phone": app.globalData.Phone,
"NickName": nickName,
"Sex": gender,
"Province": province,
"City": city,
"Country": country,
"HeadImgUrl": avatarUrl,
"UnionId": " ",
//请求新增参数
"AppId": app.globalData.AppId,
"CustomerId": that.data.customerList[that.data.customerIndex].ID,
}];
network.transfer_request(method, params, function(res) {
app.globalData.Phone = that.data.phoneNum;
//绑定中转服务器客户对应信息 成功判断是否关注公众号
that.bingDriverInTransferServer(transferParams, function(res) {
IsBindWeixinMP(app.globalData.Phone)
});
})
},
bingDriverInTransferServer: function(params, successaction) {
var that = this;
var method = bindPath;
network.requestLoading(method, params, function(res) {
if (res.result == true) {
successaction();
}
});
},
onShow: function() {
var that = this;
that.choiceCustomer();
getOpenId(function(res) {
openid = res;
IsBind(openid, function(res) {
app.globalData.Phone = res;
if (res == "") {
} else {
// 判断是否绑定成功 参数openid 返回值phoneNum
IsBinded(openid);
}
})
})
},
})