加入表单验证

This commit is contained in:
fengachen
2021-10-19 15:37:14 +08:00
parent 27a0dc96b1
commit c13697c557
11 changed files with 745 additions and 280 deletions
+129 -9
View File
@@ -1,6 +1,10 @@
// pages/addCompany/addCompany.js
import signUpApi from '../../assets/js/http/signUp'
import {
dutyCode,
postcode
} from '../../utils/validate'
Page({
/**
@@ -8,31 +12,78 @@ Page({
*/
data: {
// 是否是国际研讨会报名的选择
prepage:''
prepage: '',
flag: false
},
// 返回选择单位
backCompanyList(){
backCompanyList() {
wx.navigateTo({
url: '../companyList/companyList',
})
},
// 确定
addCompany(e){
addCompany(e) {
const formData = e.detail.value
const that = this
console.log(formData);
// 企业名称
if (formData.companyName === '') {
wx.showToast({
title: '请输入企业名称',
icon: 'none',
duration: 800
})
return
}
// 信用代码
if (formData.dutyCode === '') {
wx.showToast({
title: '请输入信用代码',
icon: 'none',
duration: 800
})
return
}
// 公司地址
if (formData.companyAddress === '') {
wx.showToast({
title: '请输入公司地址',
icon: 'none',
duration: 800
})
return
}
// 邮编
if (formData.postalCode === '') {
wx.showToast({
title: '请输入邮编',
icon: 'none',
duration: 800
})
return
}
if(this.data.flag){
wx.showToast({
title: '信息输入有误',
icon: 'none',
duration: 800
})
return
}
const that = this
signUpApi.addCompanyNoLimit(formData).then(res => {
if(res.success){
if (res.success) {
wx.showToast({
title: res.message,
icon: "none",
duration: 800,
});
if(that.data.prepage === 'guoji' ){
if (that.data.prepage === 'guoji') {
wx.navigateTo({
url: '../signUpPageGuoji/signUpPageGuoji',
})
}else{
} else {
wx.navigateTo({
url: '../signUpPage/signUpPage',
})
@@ -43,12 +94,81 @@ Page({
})
},
// 信用代码验证
validateDutyCode(e) {
let value = e.detail.value
let {
message,
errmsg
} = e.currentTarget.dataset
if (value === '' || value === undefined) {
wx.showToast({
title: message,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
return
} else if (dutyCode(value)) {
this.setData({
flag: false
})
} else {
wx.showToast({
title: errmsg,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
}
},
// 邮编验证
validatePostCode(e) {
let value = e.detail.value
let {
message,
errmsg
} = e.currentTarget.dataset
if (value === '' || value === undefined) {
wx.showToast({
title: message,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
return
} else if (postcode(value)) {
this.setData({
flag: false
})
} else {
wx.showToast({
title: errmsg,
icon: 'none',
duration: 800
})
this.setData({
flag: true
})
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
prepage:options.prepage
prepage: options.prepage
})
},
@@ -100,4 +220,4 @@ Page({
onShareAppMessage: function () {
}
})
})
+10 -10
View File
@@ -6,7 +6,7 @@
<view class="wx-form-item">
<view class="wx-form-label validate">企业名称:</view>
<view class="wx-form-value">
<input name="companyName" placeholder="请输入企业名称" />
<input name="companyName" placeholder="请输入企业名称" maxlength="50" />
<text class="hint">请确保与发票抬头企业名称一致</text>
</view>
</view>
@@ -14,56 +14,56 @@
<view class="wx-form-item">
<view class="wx-form-label validate">信用代码:</view>
<view class="wx-form-value">
<input name="dutyCode" placeholder="请输入信用代码" />
<input name="dutyCode" name="postCode" bindblur="validateDutyCode" data-message='请输入信用代码' data-errmsg='请输入正确的信用代码' placeholder="请输入信用代码" maxlength="50" />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label validate">公司地址:</view>
<view class="wx-form-value">
<input name="companyAddress" placeholder="请输入公司地址" />
<input name="companyAddress" placeholder="请输入公司地址" maxlength="50" />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label">公司电话:</view>
<view class="wx-form-value">
<input name="companyPhone" placeholder="请输入公司电话" />
<input name="companyPhone" placeholder="请输入公司电话" maxlength="50" />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label">银行户名:</view>
<view class="wx-form-value">
<input name="bankAccountName" placeholder="请输入银行户名" />
<input name="bankAccountName" placeholder="请输入银行户名" maxlength="50" />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label validate">邮编:</view>
<view class="wx-form-value">
<input name="postalCode" placeholder="请输入邮编" />
<input name="postalCode" placeholder="请输入邮编" maxlength="6" type="number" bindblur="validatePostCode" data-message='请输入邮编' data-errmsg='请输入正确的邮编' />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label">银行账号:</view>
<view class="wx-form-value">
<input name="bankAccount" placeholder="请输入银行账号" />
<input name="bankAccount" placeholder="请输入银行账号" maxlength="50" type="number" />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label">开户行:</view>
<view class="wx-form-value">
<input name="openingBank" placeholder="请输入开户行" />
<input name="openingBank" placeholder="请输入开户行" maxlength="50" />
</view>
</view>
<view class="wx-form-item">
<view class="wx-form-label">备注:</view>
<view class="wx-form-value">
<textarea name="remarks" placeholder="请输入备注" name="remark" />
<textarea name="remarks" placeholder="请输入备注" name="remark" maxlength="200" />
</view>
</view>
@@ -72,4 +72,4 @@
</view>
</form>
</view>
</view>