加入表单验证
This commit is contained in:
+186
-16
@@ -1,6 +1,11 @@
|
||||
// pages/addPerson/addPerson.js
|
||||
|
||||
import signUpApi from '../../assets/js/http/signUp'
|
||||
import {
|
||||
isEmail,
|
||||
phoneReg,
|
||||
postcode
|
||||
} from '../../utils/validate'
|
||||
Page({
|
||||
|
||||
/**
|
||||
@@ -8,39 +13,204 @@ Page({
|
||||
*/
|
||||
data: {
|
||||
// 上一个页面选中的企业
|
||||
selectedCompany:{},
|
||||
selectedCompany: {},
|
||||
// 是否是国际研讨会的选择
|
||||
prepage:""
|
||||
prepage: "",
|
||||
data: false
|
||||
},
|
||||
// 返回联系人列表
|
||||
backPersonList(){
|
||||
// 返回联系人列表
|
||||
backPersonList() {
|
||||
wx.navigateTo({
|
||||
url: '../personList/personList',
|
||||
})
|
||||
},
|
||||
// 邮编验证
|
||||
validateEmail(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 (isEmail(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
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
// 手机号验证
|
||||
validatePhone(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 (phoneReg(value)) {
|
||||
this.setData({
|
||||
flag: false
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: errmsg,
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
this.setData({
|
||||
flag: true
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
// 添加参会人
|
||||
addPerson(e){
|
||||
|
||||
addPerson(e) {
|
||||
|
||||
const that = this
|
||||
console.log(that.data.prepage);
|
||||
console.log(e);
|
||||
const formData = e.detail.value
|
||||
console.log(formData);
|
||||
// 姓名
|
||||
if (formData.companyName === '') {
|
||||
wx.showToast({
|
||||
title: '请输入企业名称',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
// 邮政编码
|
||||
if (formData.postalCode === '') {
|
||||
wx.showToast({
|
||||
title: '请输入邮编',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
// 手机号
|
||||
if (formData.phone === '') {
|
||||
wx.showToast({
|
||||
title: '请输入手机号',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
// 性别
|
||||
if (formData.gender === '') {
|
||||
wx.showToast({
|
||||
title: '请选择性别',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
// 通讯地址
|
||||
if (formData.contactAddress === '') {
|
||||
wx.showToast({
|
||||
title: '请输入通讯地址',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
// 邮箱
|
||||
if (formData.email === '') {
|
||||
wx.showToast({
|
||||
title: '请输入邮箱',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
if (this.data.flag) {
|
||||
wx.showToast({
|
||||
title: '信息输入有误',
|
||||
icon: 'none',
|
||||
duration: 800
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 参数需要传入公司id
|
||||
formData.companyId = this.data.selectedCompany.id
|
||||
|
||||
signUpApi.addPersonNoLimit(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',
|
||||
})
|
||||
@@ -57,11 +227,11 @@ Page({
|
||||
const that = this
|
||||
// 从缓存中拿 上个页面选中的企业
|
||||
wx.getStorage({
|
||||
key:'selectedCompany',
|
||||
key: 'selectedCompany',
|
||||
success(res) {
|
||||
that.setData({
|
||||
selectedCompany:JSON.parse(res.data),
|
||||
prepage:options.prepage
|
||||
selectedCompany: JSON.parse(res.data),
|
||||
prepage: options.prepage
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -115,4 +285,4 @@ Page({
|
||||
onShareAppMessage: function () {
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -6,39 +6,39 @@
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label">企业名称:</view>
|
||||
<view class="wx-form-value">
|
||||
<input disabled name="companyName" value="{{selectedCompany.companyName}}" placeholder="请输入企业名称" />
|
||||
<input disabled name="companyName" maxlength="50" value="{{selectedCompany.companyName}}" placeholder="请输入企业名称" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label validate">姓名:</view>
|
||||
<view class="wx-form-value">
|
||||
<input name="name" placeholder="请输入姓名" />
|
||||
<input name="name" 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="请输入邮政编码" type="number" maxlength="6" bindblur="validatePostCode" data-message='请输入邮政编码' data-errmsg="请输入正确的邮政编码" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label validate">手机号:</view>
|
||||
<view class="wx-form-value">
|
||||
<input name="phone" placeholder="请输入手机号" />
|
||||
<input name="phone" placeholder="请输入手机号" type="number" bindblur="validatePhone" data-message='请输入手机号' data-errmsg="请输入正确的手机号" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label">职务:</view>
|
||||
<view class="wx-form-value">
|
||||
<input name="post" placeholder="请输入职务" />
|
||||
<input name="post" placeholder="请输入职务" maxlength="50" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label validate">性别:</view>
|
||||
<view class="wx-form-value">
|
||||
@@ -54,14 +54,14 @@
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label validate">通讯地址:</view>
|
||||
<view class="wx-form-value">
|
||||
<input name="contactAddress" placeholder="请输入通讯地址" />
|
||||
<input name="contactAddress" placeholder="请输入通讯地址" maxlength="50" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="wx-form-item">
|
||||
<view class="wx-form-label validate">邮箱:</view>
|
||||
<view class="wx-form-value">
|
||||
<input name="email" placeholder="请输入邮箱" />
|
||||
<input name="email" bindblur="validateEmail" data-message='请输入邮箱' data-errmsg="请输入正确的邮箱" placeholder="请输入邮箱" maxlength="50" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user