Browse Source

登录页

master
chenxuhui 7 years ago
parent
commit
47ee9e7e50
8 changed files with 424 additions and 6 deletions
  1. +1
    -0
      app.js
  2. +1
    -0
      app.json
  3. +274
    -0
      pages/login/login.js
  4. +5
    -0
      pages/login/login.json
  5. +42
    -0
      pages/login/login.wxml
  6. +87
    -0
      pages/login/login.wxss
  7. +12
    -4
      utils/dateTimeUtil.js
  8. +2
    -2
      utils/net.js

+ 1
- 0
app.js View File

@ -22,5 +22,6 @@ App({
baseUrl: "https://miniprogram.food988.com/Rest.aspx",
TransferBaseUrl: "https://miniprogram.food988.com/RequestTransfer.aspx",
CustomerId: "",
}
})

+ 1
- 0
app.json View File

@ -1,5 +1,6 @@
{
"pages": [
"pages/login/login",
"pages/homePage/homePage",
"pages/message/message",
"pages/mine/mine",


+ 274
- 0
pages/login/login.js View File

@ -0,0 +1,274 @@
// 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 GetDriverByIdCard = "/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetDriverByIdCard"
var GetDriverByOpenId = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetDriverByOpenId'
var isBindedPath = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/IsBinded';
var GetBindDriverName = '/MainSystem/B3MiniProgramRpc/XuRpcs/Driver/AccountRpc/GetBindDriverName'
//获取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)
})
}
//绑定公众号 参数用户电话 返回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: {
array: [],
index: 0,
idCard: "",
customerList: [{
ID: 0,
Name: "请选择所属客户"
}],
customerIndex: 0,
},
// 绑定客户
listenerPickerSelected: function (e) {
this.setData({
customerIndex: e.detail.value,
});
},
// 姓名
getDriverName: function (e) {
app.globalData.UserName = e.detail.value
},
// 手机号码
getPhone: function (e) {
Phone = e.detail.value;
app.globalData.Phone = Phone;
},
// 身份证
getIDCardNum: function (e) {
var that = this
if (e.detail.value.length == 18) {
Idcard = e.detail.value;
var method = GetDriverByIdCard;
var params = ["服务号", Idcard];
network.requestLoading(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,
})
}
wx.login({
success: function (res) {
var method = XuBindDriver;
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,
}];
app.globalData.CustomerId = that.data.array[that.data.index].ID;
network.requestLoading(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) {
successaction(res.result);
});
},
onShow: function () {
var that = this;
that.choiceCustomer();
getOpenId(function (res) {
openid = res;
IsBind(openid, function (res) {
app.globalData.Phone = res;
if (res == "") {
} else {
IsBindWeixinMP(app.globalData.Phone)
}
})
})
},
})

+ 5
- 0
pages/login/login.json View File

@ -0,0 +1,5 @@
{
"navigationBarBackgroundColor": "white",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "业务员登录"
}

+ 42
- 0
pages/login/login.wxml View File

@ -0,0 +1,42 @@
<!--pages/login/login.wxml-->
<view class='containerView'>
<view class='customerChooseView'>
<view class='keyView'>绑定客户</view>
<view class='valueView'>
<picker class="{{customerIndex==0 ? 'pickerPlaceHolder' : 'pickerSelected'}}" mode="selector" range="{{customerList}}" value="{{customerList[customerIndex].Name}}" range-key="Name" bindchange="listenerPickerSelected">
<text>{{customerList[customerIndex].Name}}</text>
</picker>
</view>
</view>
<view class='lineView'></view>
<view class='customerChooseView'>
<view class='keyView'>身份证号码</view>
<view class='valueView'>
<input class='imput_phone' bindinput='getIDCardNum' type='number' maxlength='18' placeholder='请输入身份证号码' placeholder-style='color:rgb(202, 202, 202)'></input>
</view>
</view>
<view class='lineView'></view>
<view class='customerChooseView'>
<view class='keyView'>姓 名</view>
<view class='valueView'>
<input class='imput_phone' bindinput='getDriverName' type='text' placeholder='请输入姓名' placeholder-style='color:rgb(202, 202, 202)'></input>
</view>
</view>
<view class='lineView'></view>
<view class='customerChooseView'>
<view class='keyView'>手机号码</view>
<view class='valueView'>
<input class='imput_phone' bindinput='getPhone' type='number' maxlength='11' placeholder='请输入手机号' placeholder-style='color:rgb(202, 202, 202)'></input>
</view>
</view>
<view class='lineView'></view>
</view>
<button class='btn_btn' plain="true" style='border:none' open-type="getUserInfo" bindgetuserinfo="getUserInfo"><image class='currentImage' src="/imgs/bindImage.png" mode='widthFix'></image></button>
<official-account class="wxmp"></official-account>

+ 87
- 0
pages/login/login.wxss View File

@ -0,0 +1,87 @@
/* pages/login/login.wxss */
.containerView{
margin-left: 30rpx;
margin-right: 30rpx;
height: 480rpx;
margin-top: 25%;
display: flex;
flex-direction: column;
}
.customerChooseView{
height: 120rpx;
width: 100%;
display: flex;
flex-direction: row;
font-size: 20px;
color: black;
}
.keyView{
padding-top: 60rpx;
width: 40%;
height: 100%;
}
.valueView{
padding-top: 60rpx;
width: 60%;
height: 100%;
}
.pickerPlaceHolder{
color:rgb(202, 202, 202);
}
.pickerSelected{
color: black;
}
.lineView {
height: 1rpx;
background-color: #dbdbdb;
}
.imageView {
height: 80px;
width: 100%;
margin-top: 30px;
position: relative;
align-items: center;
justify-content: center;
box-sizing: content-box;
}
/* .currentImage {
width: 100%;
height: 100%;
} */
.btnTextView {
position: absolute;
width: 100%;
top:0;
line-height: 65px;
text-align: center;
}
.btnText {
color: white;
font-size: 34rpx;
}
.btn_btn {
font-size: 40rpx;
color: white;
margin-top: 10%;
padding: 0, auto;
display: block;
border: none;
background: transparent;
}
.currentImage {
width: 100%;
height: 80px;
}

+ 12
- 4
utils/dateTimeUtil.js View File

@ -1,10 +1,16 @@
function formatymdERTDate(str) {
return "/Date(" + Date.parse(new Date(str.replace(/\-/g, "/") + " 00:00:00")) + "+0800)/"
}
function getERTDate() {
return "/Date(" + Date.parse(new Date()) + "+0800)/"
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}
/**
* 时间戳转化为年
* number: 传入时间戳
@ -15,7 +21,7 @@ function formatTimeTwo(number, format) {
var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
var returnArr = [];
var date = new Date(number*1);
var date = new Date(number * 1);
returnArr.push(date.getFullYear());
returnArr.push(formatNumber(date.getMonth() + 1));
returnArr.push(formatNumber(date.getDate()));
@ -31,5 +37,7 @@ function formatTimeTwo(number, format) {
}
module.exports = {
formatTimeTwo: formatTimeTwo
formatTimeTwo: formatTimeTwo,
formatymdERTDate: formatymdERTDate,
getERTDate: getERTDate
}

+ 2
- 2
utils/net.js View File

@ -49,7 +49,7 @@ function requestLoading(method, params, successaction) {
}
// 中转服务器,跳转请求
function transferRequestLoading(method, params, successaction) {
function transfer_request(method, params, successaction) {
wx.showLoading({
title: "加载中",
})
@ -97,5 +97,5 @@ function transferRequestLoading(method, params, successaction) {
module.exports = {
request: request,
requestLoading: requestLoading,
transferRequestLoading: transferRequestLoading,
transfer_request: transfer_request,
}

Loading…
Cancel
Save