Commit b1c88250 by zhangshengren

增加验证码

parent c8c8bb17
...@@ -3,6 +3,7 @@ App({ ...@@ -3,6 +3,7 @@ App({
globalData: { globalData: {
app_id: 'wx3722cae0d0b62fff', app_id: 'wx3722cae0d0b62fff',
url: 'https://test-es.checheng.com/api/', url: 'https://test-es.checheng.com/api/',
urlSpecial: 'https://test-es.checheng.com/api-weapp/',
name: '爱车估价助手', name: '爱车估价助手',
width: 0, width: 0,
height: 0, height: 0,
......
const app = getApp(); const app = getApp();
const utils = require('../../utils/util.js'); const utils = require('../../utils/util.js');
const { md5 } = require('../../utils/md5.js'); const {
md5
} = require('../../utils/md5.js');
Page({ Page({
...@@ -13,8 +15,17 @@ Page({ ...@@ -13,8 +15,17 @@ Page({
mileage: '', mileage: '',
city_id: '', city_id: '',
city_name: '', city_name: '',
phone: '' phone: '',
pre_phone: ''
}, },
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码',
startTime: '', startTime: '',
endTime: '', endTime: '',
provinceList: [], provinceList: [],
...@@ -31,10 +42,19 @@ Page({ ...@@ -31,10 +42,19 @@ Page({
onShow: function() { onShow: function() {
let _this = this let _this = this
if (this.timer) {
clearInterval(this.timer)
}
this.setData({ this.setData({
provinceList: app.globalData.provinceList, provinceList: app.globalData.provinceList,
province_index: wx.getStorageSync('province_index'), province_index: wx.getStorageSync('province_index'),
city_index: wx.getStorageSync('city_index') city_index: wx.getStorageSync('city_index'),
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码'
}, () => { }, () => {
if (_this.data.provinceList.length === 0) { if (_this.data.provinceList.length === 0) {
_this.getProvinceList() _this.getProvinceList()
...@@ -83,11 +103,11 @@ Page({ ...@@ -83,11 +103,11 @@ Page({
}, },
// 获取省份 // 获取省份
getProvinceList: function () { getProvinceList: function() {
let _this = this; let _this = this;
wx.request({ wx.request({
url: app.globalData.url + 'assess/provinces', url: app.globalData.url + 'assess/provinces',
success: function (res) { success: function(res) {
if (res.data && res.data.length > 0) { if (res.data && res.data.length > 0) {
let data = res.data let data = res.data
let arr = [] let arr = []
...@@ -212,14 +232,146 @@ Page({ ...@@ -212,14 +232,146 @@ Page({
// 输入手机号  // 输入手机号 
phoneInput: function(e) { phoneInput: function(e) {
let pre_phone = this.data.userForms.pre_phone
let phone = e.detail.value let phone = e.detail.value
if (pre_phone != phone) {
this.setData({
showSmsCode: true
})
} else if (pre_phone == phone) {
this.setData({
showSmsCode: false
})
wx.setStorageSync('phone', phone)
}
this.setData({ this.setData({
['userForms.phone']: phone ['userForms.phone']: phone
}) })
if (phone.length === 11) { // if (phone.length === 11) {
wx.setStorageSync('phone', phone) // wx.setStorageSync('phone', phone)
// }
},
// 输入验证码
smsCodeInput: function(e) {
let code = e.detail.value
this.setData({
inputSmsCode: code
})
},
// 倒计时
countDown: function() {
let _this = this;
_this.timer = setInterval(function() {
_this.data.totalTime--;
_this.data.btnText = _this.data.totalTime + '秒';
if (_this.data.totalTime < 0) {
clearInterval(_this.timer)
_this.setData({
totalTime: 120,
btnText: '重新获取'
})
} else {
_this.setData({
totalTime: _this.data.totalTime,
btnText: _this.data.btnText
})
} }
}, 1000)
},
// 发送短信验证码
sendSmsCode: function(e) {
let _this = this
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
let data = {
phone: this.data.userForms.phone
}
_this.setData({
disabled: true
}, () => {
wx.request({
url: app.globalData.urlSpecial + 'main-customers/get-new-sms',
data: data,
success: function(res) {
res = res.data
if (res.message === 'ok' && res.data && res.data.code) {
_this.setData({
smsCode: res.data.code,
}, () => {
_this.countDown();
})
} else if (res.message === 'ok' && res.data && res.data.error === 1) {
wx.showToast({
icon: 'none',
title: res.data.msg
})
_this.setData({
disabled: false
}, () => {})
}
},
fail: function(res) {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
})
})
}, },
// 获取手机号 // 获取手机号
...@@ -243,7 +395,7 @@ Page({ ...@@ -243,7 +395,7 @@ Page({
let phone = res.data.purePhoneNumber let phone = res.data.purePhoneNumber
_this.setData({ _this.setData({
['userForms.phone']: phone, ['userForms.phone']: phone,
showPhoneInput: true ['userForms.pre_phone']: phone,
}) })
wx.setStorageSync('phone', phone) wx.setStorageSync('phone', phone)
} else { } else {
...@@ -260,7 +412,7 @@ Page({ ...@@ -260,7 +412,7 @@ Page({
} else if (errMsg === 'getPhoneNumber:fail user deny') { } else if (errMsg === 'getPhoneNumber:fail user deny') {
this.setData({ this.setData({
['userForms.phone']: '', ['userForms.phone']: '',
showPhoneInput: true ['userForms.pre_phone']: '',
}) })
} }
}, },
...@@ -289,12 +441,12 @@ Page({ ...@@ -289,12 +441,12 @@ Page({
url: app.globalData.url + 'decode-phone', url: app.globalData.url + 'decode-phone',
data: data, data: data,
method: 'POST', method: 'POST',
success: function(res) { success: function (res) {
if (res.data.message !== '解密失败') { if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber let phone = res.data.purePhoneNumber
_this.setData({ _this.setData({
['userForms.phone']: phone, ['userForms.phone']: phone,
showPhoneInput: true ['userForms.pre_phone']: phone,
}) })
wx.setStorageSync('phone', phone) wx.setStorageSync('phone', phone)
} else { } else {
...@@ -365,6 +517,22 @@ Page({ ...@@ -365,6 +517,22 @@ Page({
return false; return false;
} }
if (!this.data.inputSmsCode) {
wx.showToast({
icon: 'none',
title: '请输入短信验证码!'
})
return false;
}
if ((this.data.inputSmsCode != this.data.smsCode)) {
wx.showToast({
icon: 'none',
title: '短信验证码不正确!'
})
return false;
}
this.terminalAvailable(app.globalData.tiantianpaiche_cityList, '天天拍车'); this.terminalAvailable(app.globalData.tiantianpaiche_cityList, '天天拍车');
let terminal_length = this.data.terminal_names.length; let terminal_length = this.data.terminal_names.length;
......
...@@ -68,6 +68,17 @@ ...@@ -68,6 +68,17 @@
<button bindgetphonenumber="getPhone" id="get-phone" openType="getPhoneNumber" size="mini" type="primary" wx:else>11位手机号</button> --> <button bindgetphonenumber="getPhone" id="get-phone" openType="getPhoneNumber" size="mini" type="primary" wx:else>11位手机号</button> -->
</view> </view>
</view> </view>
<view class="weui-cell weui-cell_input form-input-item">
<view class="weui-cell__hd">
<view class="weui-label">验 证 码</view>
</view>
<view class="weui-cell__bd">
<input bindinput="smsCodeInput" maxlength="6" class="weui-input text-right" placeholder="请输入短信验证码" type="digit" value="{{inputSmsCode}}"></input>
</view>
<view class="weui-cell__ft">
<button bindtap="sendSmsCode" id="get-smsCode" class="{{disabled ? 'disabled': ''}}" size="mini" type="primary" disabled="{{disabled}}">{{btnText}}</button>
</view>
</view>
</view> </view>
</view> </view>
<view class="weui-cell submit-section"> <view class="weui-cell submit-section">
......
...@@ -140,3 +140,20 @@ page { ...@@ -140,3 +140,20 @@ page {
color: #39424D; color: #39424D;
text-align: right; text-align: right;
} }
#get-smsCode {
display: block;
padding: 3px 5px;
margin-left: 30rpx;
width: 180rpx;
line-height: 2;
background: #fe560e;
color:#fff;
border-color: white;
font-size: 26rpx;
text-align: center;
}
button.disabled {
background: #cec5c0 !important;
}
\ No newline at end of file
...@@ -12,8 +12,16 @@ Page({ ...@@ -12,8 +12,16 @@ Page({
mileage: '', mileage: '',
city_id: '', city_id: '',
city_name: '', city_name: '',
phone: '' phone: '',
pre_phone: ''
}, },
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码',
startTime: '', startTime: '',
endTime: '', endTime: '',
provinceList: [], provinceList: [],
...@@ -61,10 +69,19 @@ Page({ ...@@ -61,10 +69,19 @@ Page({
onShow: function() { onShow: function() {
let _this = this let _this = this
if (this.timer) {
clearInterval(this.timer)
}
this.setData({ this.setData({
provinceList: app.globalData.provinceList, provinceList: app.globalData.provinceList,
province_index: wx.getStorageSync('province_index'), province_index: wx.getStorageSync('province_index'),
city_index: wx.getStorageSync('city_index') city_index: wx.getStorageSync('city_index'),
inputSmsCode: '',
smsCode: '',
disabled: false,
totalTime: 120,
timer: null,
btnText: '获取验证码'
}, () => { }, () => {
if (_this.data.provinceList.length === 0) { if (_this.data.provinceList.length === 0) {
_this.getProvinceList() _this.getProvinceList()
...@@ -241,19 +258,151 @@ Page({ ...@@ -241,19 +258,151 @@ Page({
}, },
// 输入手机号  // 输入手机号 
phoneInput: function(e) { phoneInput: function (e) {
let pre_phone = this.data.userForms.pre_phone
let phone = e.detail.value let phone = e.detail.value
if (pre_phone != phone) {
this.setData({
showSmsCode: true
})
} else if (pre_phone == phone) {
this.setData({
showSmsCode: false
})
wx.setStorageSync('phone', phone)
}
this.setData({ this.setData({
['userForms.phone']: phone ['userForms.phone']: phone
}) })
if (phone.length === 11) { // if (phone.length === 11) {
wx.setStorageSync('phone', phone) // wx.setStorageSync('phone', phone)
// }
},
// 输入验证码
smsCodeInput: function (e) {
let code = e.detail.value
this.setData({
inputSmsCode: code
})
},
// 倒计时
countDown: function () {
let _this = this;
_this.timer = setInterval(function () {
_this.data.totalTime--;
_this.data.btnText = _this.data.totalTime + '秒';
if (_this.data.totalTime < 0) {
clearInterval(_this.timer)
_this.setData({
totalTime: 120,
btnText: '重新获取'
})
} else {
_this.setData({
totalTime: _this.data.totalTime,
btnText: _this.data.btnText
})
}
}, 1000)
},
// 发送短信验证码
sendSmsCode: function (e) {
let _this = this
if (!this.data.userForms.specification_name) {
wx.showToast({
icon: 'none',
title: '请选择车型!'
})
return false;
}
if (!this.data.userForms.buy_time) {
wx.showToast({
icon: 'none',
title: '请选择上牌时间!'
})
return false;
}
if (!this.data.userForms.city_name) {
wx.showToast({
icon: 'none',
title: '请选择城市!'
})
return false;
}
if (!this.data.userForms.mileage) {
wx.showToast({
icon: 'none',
title: '请输入行驶里程!'
})
return false;
}
if (Number(this.data.userForms.mileage) > 100) {
wx.showToast({
icon: 'none',
title: '行驶里程不能超过100万公里!'
})
return false;
}
if (!this.data.userForms.phone) {
wx.showToast({
icon: 'none',
title: '请输入手机号码!'
})
return false;
}
let reg = /^1(3|4|5|7|8|9)\d{9}$/;
if (!reg.test(this.data.userForms.phone)) {
wx.showToast({
icon: 'none',
title: '手机号码格式不正确!'
})
return false;
}
let data = {
phone: this.data.userForms.phone
}
_this.setData({
disabled: true
}, () => {
wx.request({
url: app.globalData.urlSpecial + 'main-customers/get-new-sms',
data: data,
success: function (res) {
res = res.data
if (res.message === 'ok' && res.data && res.data.code) {
_this.setData({
smsCode: res.data.code,
}, () => {
_this.countDown();
})
} else if (res.message === 'ok' && res.data && res.data.error === 1) {
wx.showToast({
icon: 'none',
title: res.data.msg
})
_this.setData({
disabled: false
}, () => { })
} }
}, },
fail: function (res) {
wx.showToast({
icon: 'none',
title: '获取失败,请稍后重试!'
})
}
})
})
},
// 获取手机号 // 获取手机号
getPhone: function(e) { getPhone: function (e) {
let _this = this let _this = this
let errMsg = e.detail.errMsg let errMsg = e.detail.errMsg
if (errMsg === 'getPhoneNumber:ok') { if (errMsg === 'getPhoneNumber:ok') {
...@@ -268,11 +417,12 @@ Page({ ...@@ -268,11 +417,12 @@ Page({
url: app.globalData.url + 'decode-phone', url: app.globalData.url + 'decode-phone',
data: data, data: data,
method: 'POST', method: 'POST',
success: function(res) { success: function (res) {
if (res.data.message !== '解密失败') { if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber let phone = res.data.purePhoneNumber
_this.setData({ _this.setData({
['userForms.phone']: phone, ['userForms.phone']: phone,
['userForms.pre_phone']: phone,
}) })
wx.setStorageSync('phone', phone) wx.setStorageSync('phone', phone)
} else { } else {
...@@ -289,16 +439,16 @@ Page({ ...@@ -289,16 +439,16 @@ Page({
} else if (errMsg === 'getPhoneNumber:fail user deny') { } else if (errMsg === 'getPhoneNumber:fail user deny') {
this.setData({ this.setData({
['userForms.phone']: '', ['userForms.phone']: '',
showPhoneInput: true ['userForms.pre_phone']: '',
}) })
} }
}, },
// 重新获取code // 重新获取code
login: function(e) { login: function (e) {
let _this = this let _this = this
wx.login({ wx.login({
success: function(res) { success: function (res) {
if (res.errMsg === 'login:ok') { if (res.errMsg === 'login:ok') {
let data = { let data = {
code: res.code, code: res.code,
...@@ -307,7 +457,7 @@ Page({ ...@@ -307,7 +457,7 @@ Page({
wx.request({ wx.request({
url: app.globalData.url + 'user-code', url: app.globalData.url + 'user-code',
data: data, data: data,
success: function(res) { success: function (res) {
let data = { let data = {
session_key: res.data.session_key, session_key: res.data.session_key,
encrypted_data: e.detail.encryptedData, encrypted_data: e.detail.encryptedData,
...@@ -318,11 +468,12 @@ Page({ ...@@ -318,11 +468,12 @@ Page({
url: app.globalData.url + 'decode-phone', url: app.globalData.url + 'decode-phone',
data: data, data: data,
method: 'POST', method: 'POST',
success: function(res) { success: function (res) {
if (res.data.message !== '解密失败') { if (res.data.message !== '解密失败') {
let phone = res.data.purePhoneNumber let phone = res.data.purePhoneNumber
_this.setData({ _this.setData({
['userForms.phone']: phone, ['userForms.phone']: phone,
['userForms.pre_phone']: phone,
}) })
wx.setStorageSync('phone', phone) wx.setStorageSync('phone', phone)
} else { } else {
...@@ -339,6 +490,7 @@ Page({ ...@@ -339,6 +490,7 @@ Page({
} }
}) })
}, },
// 是否勾选 // 是否勾选
handleSelect: function(e) { handleSelect: function(e) {
let index = e.currentTarget.dataset.index; let index = e.currentTarget.dataset.index;
...@@ -431,6 +583,22 @@ Page({ ...@@ -431,6 +583,22 @@ Page({
return false; return false;
} }
if (!this.data.inputSmsCode) {
wx.showToast({
icon: 'none',
title: '请输入短信验证码!'
})
return false;
}
if ((this.data.inputSmsCode != this.data.smsCode)) {
wx.showToast({
icon: 'none',
title: '短信验证码不正确!'
})
return false;
}
if (this.data.terminal_names.length === 0) { if (this.data.terminal_names.length === 0) {
wx.showToast({ wx.showToast({
icon: 'none', icon: 'none',
......
...@@ -68,6 +68,17 @@ ...@@ -68,6 +68,17 @@
<button bindgetphonenumber="getPhone" id="get-phone" openType="getPhoneNumber" size="mini" type="primary" wx:else>11位手机号</button> --> <button bindgetphonenumber="getPhone" id="get-phone" openType="getPhoneNumber" size="mini" type="primary" wx:else>11位手机号</button> -->
</view> </view>
</view> </view>
<view class="weui-cell weui-cell_input form-input-item">
<view class="weui-cell__hd">
<view class="weui-label">验 证 码</view>
</view>
<view class="weui-cell__bd">
<input bindinput="smsCodeInput" maxlength="6" class="weui-input text-right" placeholder="请输入短信验证码" type="digit" value="{{inputSmsCode}}"></input>
</view>
<view class="weui-cell__ft">
<button bindtap="sendSmsCode" id="get-smsCode" class="{{disabled ? 'disabled': ''}}" size="mini" type="primary" disabled="{{disabled}}">{{btnText}}</button>
</view>
</view>
</view> </view>
</view> </view>
......
...@@ -238,3 +238,20 @@ page { ...@@ -238,3 +238,20 @@ page {
width: 202rpx; width: 202rpx;
height: 32rpx; height: 32rpx;
} }
#get-smsCode {
display: block;
padding: 3px 5px;
margin-left: 30rpx;
width: 180rpx;
line-height: 2;
background: #fe560e;
color:#fff;
border-color: white;
font-size: 26rpx;
text-align: center;
}
button.disabled {
background: #cec5c0 !important;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment