加入表单验证
This commit is contained in:
+223
-46
@@ -1,72 +1,180 @@
|
||||
// pages/signUpPage/signUpPage.js
|
||||
import signUpApi from '../../assets/js/http/signUp'
|
||||
import {
|
||||
phoneReg,
|
||||
postcode
|
||||
} from '../../utils/validate'
|
||||
Page({
|
||||
/**
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
// 参会身份
|
||||
identifyList:[
|
||||
{value: '2', name: '参会人'},
|
||||
{value: '1', name: '嘉宾'},
|
||||
{value: '3', name: '内部企业'},
|
||||
identifyList: [{
|
||||
value: '2',
|
||||
name: '参会人'
|
||||
},
|
||||
{
|
||||
value: '1',
|
||||
name: '嘉宾'
|
||||
},
|
||||
{
|
||||
value: '3',
|
||||
name: '内部企业'
|
||||
},
|
||||
],
|
||||
// 缴费方式
|
||||
paymentMethodList:[
|
||||
{value: '1', name: '汇款'},
|
||||
{value: '2', name: '线上缴费'},
|
||||
{value: '3', name: '打包'},
|
||||
paymentMethodList: [{
|
||||
value: '1',
|
||||
name: '汇款'
|
||||
},
|
||||
{
|
||||
value: '2',
|
||||
name: '线上缴费'
|
||||
},
|
||||
{
|
||||
value: '3',
|
||||
name: '打包'
|
||||
},
|
||||
],
|
||||
// 是否需要发票
|
||||
needInvoiceList:[
|
||||
{value: '0', name: '不需要'},
|
||||
{value: '1', name: '增值税普通发票'},
|
||||
{value: '2', name: '增值税专用发票'},
|
||||
needInvoiceList: [{
|
||||
value: '0',
|
||||
name: '不需要'
|
||||
},
|
||||
{
|
||||
value: '1',
|
||||
name: '增值税普通发票'
|
||||
},
|
||||
{
|
||||
value: '2',
|
||||
name: '增值税专用发票'
|
||||
},
|
||||
],
|
||||
// 是否住酒店
|
||||
needCheckInHotel:[
|
||||
{value: '1', name: '是'},
|
||||
{value: '0', name: '否'},
|
||||
needCheckInHotel: [{
|
||||
value: '1',
|
||||
name: '是'
|
||||
},
|
||||
{
|
||||
value: '0',
|
||||
name: '否'
|
||||
},
|
||||
],
|
||||
// 是否选择发票的选中的索引
|
||||
index:-1,
|
||||
index: -1,
|
||||
// 抵达时间
|
||||
arrivalTime:'请选择抵达时间',
|
||||
arrivalTime: '请选择抵达时间',
|
||||
// 离开时间
|
||||
departureTime:'请选择离开时间',
|
||||
departureTime: '请选择离开时间',
|
||||
// 选中的参会单位
|
||||
selectedCompany:{},
|
||||
selectedCompany: {},
|
||||
// 选中的联系人
|
||||
selectedPerson:{},
|
||||
selectedPerson: {},
|
||||
// 选中的邮寄联系人
|
||||
selectedPostPerson:{},
|
||||
selectedPostPerson: {},
|
||||
// 选中的会议
|
||||
selectedMeeting:{}
|
||||
selectedMeeting: {},
|
||||
// 是否正确填写信息
|
||||
flag: false
|
||||
},
|
||||
// 是否需要发票的选择
|
||||
needInvoiceChange(e){
|
||||
needInvoiceChange(e) {
|
||||
this.setData({
|
||||
index:e.detail.value
|
||||
index: e.detail.value
|
||||
})
|
||||
},
|
||||
// 抵达时间选择
|
||||
bindDateChangeArriveTime(e){
|
||||
bindDateChangeArriveTime(e) {
|
||||
this.setData({
|
||||
arrivalTime:e.detail.value
|
||||
arrivalTime: e.detail.value
|
||||
})
|
||||
},
|
||||
// 离开时间选择
|
||||
bindDateChangeLeaveTime(e){
|
||||
bindDateChangeLeaveTime(e) {
|
||||
this.setData({
|
||||
departureTime:e.detail.value
|
||||
departureTime: e.detail.value
|
||||
})
|
||||
},
|
||||
// 确定
|
||||
formSubmit(e){
|
||||
formSubmit(e) {
|
||||
console.log(e);
|
||||
const formData = Object.assign({}, e.detail.value)
|
||||
|
||||
if (this.data.flag) {
|
||||
wx.showToast({
|
||||
title: '信息输入有误',
|
||||
icon: 'error',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 参会身份验证
|
||||
if (formData.identity === '') {
|
||||
wx.showToast({
|
||||
title: '请选择参会身份',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 缴费方式
|
||||
if (formData.payMode === '') {
|
||||
wx.showToast({
|
||||
title: '请选择缴费方式',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 是否需要发票
|
||||
if (formData.needInvoice === -1) {
|
||||
wx.showToast({
|
||||
title: '请选择发票',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 邮寄联系人
|
||||
if (formData.postContactId === undefined) {
|
||||
wx.showToast({
|
||||
title: '请选择邮寄联系人',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 邮寄地址
|
||||
if (formData.postContactAddress === '') {
|
||||
wx.showToast({
|
||||
title: '请输入邮寄地址',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 邮编
|
||||
if (formData.postCode === '') {
|
||||
wx.showToast({
|
||||
title: '请输入邮编',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
// 是否住酒店
|
||||
if (formData.checkInHotel === '') {
|
||||
wx.showToast({
|
||||
title: '请选择是否住酒店',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const formData = Object.assign({},e.detail.value)
|
||||
// 会议id
|
||||
formData.meetingId = this.data.selectedMeeting.id
|
||||
formData.meetingId = this.data.selectedMeeting.id
|
||||
// 参会人id
|
||||
formData.companyContactId = this.data.selectedPerson.id
|
||||
// 邮寄联系人id
|
||||
@@ -78,7 +186,7 @@ Page({
|
||||
console.log(formData);
|
||||
|
||||
signUpApi.signUpMeeting(formData).then(res => {
|
||||
if(res.success){
|
||||
if (res.success) {
|
||||
// 成功 清除缓存 跳转报名成功页面
|
||||
wx.removeStorage({
|
||||
key: 'selectedCompany',
|
||||
@@ -91,7 +199,7 @@ Page({
|
||||
})
|
||||
wx.removeStorage({
|
||||
key: 'currentMeetingInfo',
|
||||
success(){
|
||||
success() {
|
||||
// 跳转报名成功页面
|
||||
wx.navigateTo({
|
||||
url: '../signUpSuccess/signUpSuccess',
|
||||
@@ -102,19 +210,19 @@ Page({
|
||||
})
|
||||
},
|
||||
// 选择参会单位
|
||||
selectCompany(){
|
||||
selectCompany() {
|
||||
wx.navigateTo({
|
||||
url: '../companyList/companyList',
|
||||
})
|
||||
},
|
||||
// 选择参会人
|
||||
selectPerson(e){
|
||||
selectPerson(e) {
|
||||
console.log(this.data.selectedCompany);
|
||||
if(!!this.data.selectedCompany.id){
|
||||
if (!!this.data.selectedCompany.id) {
|
||||
wx.navigateTo({
|
||||
url: `../personList/personList?companyId=${this.data.selectedCompany.id}&selectType=${e.currentTarget.dataset.selecttype}`,
|
||||
})
|
||||
}else{
|
||||
} else {
|
||||
wx.showToast({
|
||||
title: '请先选择参会单位',
|
||||
icon: "none",
|
||||
@@ -134,44 +242,113 @@ Page({
|
||||
// 从缓存中拿选中的企业
|
||||
const that = this
|
||||
wx.getStorage({
|
||||
key:'selectedCompany',
|
||||
key: 'selectedCompany',
|
||||
success(res) {
|
||||
that.setData({
|
||||
selectedCompany:JSON.parse(res.data)
|
||||
selectedCompany: JSON.parse(res.data)
|
||||
})
|
||||
}
|
||||
})
|
||||
// 从缓存中拿选中的联系人
|
||||
wx.getStorage({
|
||||
key:'selectedPerson',
|
||||
key: 'selectedPerson',
|
||||
success(res) {
|
||||
that.setData({
|
||||
selectedPerson:res.data
|
||||
selectedPerson: res.data
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// 从缓存中拿选中的邮寄联系人
|
||||
wx.getStorage({
|
||||
key:'selectedPostPerson',
|
||||
key: 'selectedPostPerson',
|
||||
success(res) {
|
||||
that.setData({
|
||||
selectedPostPerson:res.data
|
||||
selectedPostPerson: res.data
|
||||
})
|
||||
}
|
||||
})
|
||||
// 从缓存中拿选中的会议的信息
|
||||
|
||||
wx.getStorage({
|
||||
key:'currentMeetingInfo',
|
||||
key: 'currentMeetingInfo',
|
||||
success(res) {
|
||||
console.log(res,'meetingInfo');
|
||||
console.log(res, 'meetingInfo');
|
||||
that.setData({
|
||||
selectedMeeting:res.data
|
||||
selectedMeeting: res.data
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 手机号验证
|
||||
validatePhone(e) {
|
||||
console.log(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
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
// 邮编验证
|
||||
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
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
|
||||
Reference in New Issue
Block a user