//index.js
|
|
const app = getApp();
|
|
|
|
var network = require("../../utils/net.js");
|
|
|
|
var isBindedPath = '/MainSystem/B3MiniProgramRpc/XuRpcs/Employee/AccountRpc/IsBinded';
|
|
var isBindByPhone = '/MainSystem/B3MiniProgramRpc/XuRpcs/Employee/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';
|
|
|
|
function WeixinLogin() {
|
|
let method = app.globalData.LoginPath;
|
|
let params = [app.globalData.AppId, app.globalData.OpenId];
|
|
|
|
network.transfer_request(method, params, function(res) {
|
|
app.globalData.DecryptCookie = res.result;
|
|
})
|
|
}
|
|
|
|
function IsBindWeixinMP(phone) {
|
|
|
|
let method = isBindWeixinPath
|
|
let params = [phone];
|
|
network.requestLoading(method, params, function(res) {
|
|
res.result = true;
|
|
if (res.result == true) {
|
|
|
|
WeixinLogin()
|
|
|
|
wx.switchTab({
|
|
url: '/pages/main/main',
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '请关注公众号',
|
|
showCancel: false,
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
function Bind(page) {
|
|
let userInfos = app.globalData.UserInfo
|
|
let method = bindPath;
|
|
let params = [{
|
|
"AppId": app.globalData.AppId,
|
|
"OpenId": app.globalData.OpenId,
|
|
"Phone": page.data.phoneNum,
|
|
"NickName": userInfos.nickName,
|
|
"Sex": userInfos.gender,
|
|
"Province": userInfos.province,
|
|
"City": userInfos.city,
|
|
"Country": userInfos.country,
|
|
"HeadImgUrl": userInfos.avatarUrl,
|
|
"UnionId": "",
|
|
"CustomerId": app.globalData.CustomerId
|
|
}];
|
|
network.requestLoading(method, params, function (res) {
|
|
if (res.result == true) {
|
|
IsBindWeixinMP(app.globalData.PhoneNum)
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
Page({
|
|
data: {
|
|
userInfo: "", //用户信息
|
|
phoneNum: ""
|
|
},
|
|
|
|
getPhoneNum: function(e) {
|
|
let val = e.detail.value;
|
|
this.data.phoneNum = val;
|
|
},
|
|
|
|
onLoad: function(options) {
|
|
|
|
},
|
|
|
|
onShow: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function() {
|
|
var that = this;
|
|
var shareObj = {
|
|
title: "", // 默认是小程序的名称(可以写slogan等)
|
|
path: '/pages/index/index', // 默认是当前页面,必须是以‘/’开头的完整路径
|
|
imgUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
|
|
success: function(res) {
|
|
if (res.errMsg == 'shareAppMessage:ok') {
|
|
|
|
}
|
|
},
|
|
fail: function() { // 转发失败之后的回调
|
|
if (res.errMsg == 'shareAppMessage:fail cancel') { // 用户取消转发
|
|
wx.showToast({
|
|
title: '取消转发',
|
|
})
|
|
} else if (res.errMsg == 'shareAppMessage:fail') { // 转发失败,其中 detail message 为详细失败信息
|
|
wx.showToast({
|
|
title: '转发失败,重新分享',
|
|
})
|
|
}
|
|
},
|
|
complete: function() {
|
|
|
|
}
|
|
};
|
|
return shareObj;
|
|
},
|
|
|
|
getUserInfo: function(e) {
|
|
var that = this;
|
|
if (e.detail.userInfo != null) {
|
|
app.globalData.UserInfo = e.detail.userInfo
|
|
|
|
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 = isBindByPhone;
|
|
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) {
|
|
app.globalData.PhoneNum = that.data.PhoneNum;
|
|
Bind(that)
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '授权提示',
|
|
content: '请给予权限,不涉及个人隐私',
|
|
showCancel: false
|
|
})
|
|
}
|
|
}
|
|
})
|