【bug】时间的校验

This commit is contained in:
fengachen
2021-11-04 11:21:25 +08:00
parent 3a87b256d4
commit 33bb8f954f
3 changed files with 75 additions and 31 deletions
+16 -11
View File
@@ -3,7 +3,8 @@ import signUpApi from '../../assets/js/http/signUp'
import MeetingApi from '../../assets/js/http/meetingApi' import MeetingApi from '../../assets/js/http/meetingApi'
import { import {
phoneReg, phoneReg,
postcode postcode,
compareDate
} from '../../utils/validate' } from '../../utils/validate'
Page({ Page({
/** /**
@@ -245,15 +246,20 @@ Page({
}) })
return return
} }
// 是否住酒店 // 校验时间
// if (formData.checkInHotel === '') { if(formData.arrivalTime && formData.departureTime){
// wx.showToast({ let flag = compareDate(formData.arrivalTime,formData.departureTime)
// title: '请选择是否住酒店', if(flag){
// icon: 'none', // 抵达时间大于离开时间
// duration: 2000 wx.showToast({
// }) title: '抵达时间不能大于离开时间',
// return icon:'none',
// } duration:2000
})
return
}
}
wx.showLoading({ wx.showLoading({
title: '加载中', title: '加载中',
mask:true mask:true
@@ -378,7 +384,6 @@ Page({
this.setData({ this.setData({
meetingId:options.meetingId meetingId:options.meetingId
}) })
wx.setStorage({ wx.setStorage({
key:'meetingId', key:'meetingId',
data:options.meetingId data:options.meetingId
+50 -20
View File
@@ -3,7 +3,8 @@ import MeetingApi from "../../assets/js/http/meetingApi"
import signUpApi from "../../assets/js/http/signUp" import signUpApi from "../../assets/js/http/signUp"
import { import {
phoneReg, phoneReg,
postcode postcode,
compareDate
} from '../../utils/validate' } from '../../utils/validate'
import { import {
baseUrl, baseUrl,
@@ -167,8 +168,8 @@ Page({
let value = e.detail.value let value = e.detail.value
this.setData({ this.setData({
needHotel: value, needHotel: value,
inHotelTime:'请选择入住酒店时间', inHotelTime: '请选择入住酒店时间',
outHotelTime:'请选择离店时间' outHotelTime: '请选择离店时间'
}) })
}, },
@@ -177,7 +178,7 @@ Page({
let value = e.detail.value let value = e.detail.value
this.setData({ this.setData({
needPick: value, needPick: value,
arrivalTime:'请选择抵达时间' arrivalTime: '请选择抵达时间'
}) })
}, },
// 是否送站 // 是否送站
@@ -185,7 +186,7 @@ Page({
let value = e.detail.value let value = e.detail.value
this.setData({ this.setData({
needSend: value, needSend: value,
departureTime:'请选择离开时间' departureTime: '请选择离开时间'
}) })
}, },
// 缴费方式选择 // 缴费方式选择
@@ -216,14 +217,15 @@ Page({
speakerBool: false, speakerBool: false,
cooperatieBool: false, cooperatieBool: false,
guestBool: false, guestBool: false,
guestType:''
}) })
} }
}, },
// 是否住酒店 参会人与内部企业 清除抵达时间 离开时间 // 是否住酒店 参会人与内部企业 清除抵达时间 离开时间
needHotelNot(){ needHotelNot() {
this.setData({ this.setData({
arrivalTime:'请选择抵达时间', arrivalTime: '请选择抵达时间',
departureTime:'请选择离开时间' departureTime: '请选择离开时间'
}) })
}, },
// 选择参会单位 // 选择参会单位
@@ -312,10 +314,10 @@ Page({
console.log(validateArr[0].type); console.log(validateArr[0].type);
this.setData({ this.setData({
guestType: validateArr[0].type, guestType: validateArr[0].type,
haveMeals:'', haveMeals: '',
needHotel:'', needHotel: '',
needPick:'', needPick: '',
needSend:'' needSend: ''
}) })
switch (validateArr[0].type) { switch (validateArr[0].type) {
case '1': case '1':
@@ -635,7 +637,7 @@ Page({
// 离店时间 // 离店时间
if ((formData.outHotelTime === '' || formData.outHotelTime === null || formData.outHotelTime === undefined ) && this.data.needHotel === '1' && this.data.guestType === '1') { if ((formData.outHotelTime === '' || formData.outHotelTime === null || formData.outHotelTime === undefined) && this.data.needHotel === '1' && this.data.guestType === '1') {
wx.showToast({ wx.showToast({
title: '请选择离店时间', title: '请选择离店时间',
icon: 'none', icon: 'none',
@@ -643,6 +645,18 @@ Page({
}) })
return return
} }
if (formData.inHotelTime && formData.outHotelTime) {
let flag = compareDate(formData.inHotelTime, formData.outHotelTime)
if (flag) {
// 入住酒店时间大于离店时间
wx.showToast({
title: '入住酒店时间不能大于离店时间',
icon: 'none',
duration: 2000
})
return
}
}
// 房型 // 房型
if (formData.roomLayout === '' && this.data.needHotel === '1' && this.data.guestType === '1') { if (formData.roomLayout === '' && this.data.needHotel === '1' && this.data.guestType === '1') {
@@ -664,7 +678,7 @@ Page({
return return
} }
// 抵达时间 // 抵达时间
if (this.data.identity === '1' && this.data.needPick === '1' && this.data.guestType !== '4' && (formData.arrivalTime === '' || formData.arrivalTime === null || formData.arrivalTime === undefined )) { if (this.data.identity === '1' && this.data.needPick === '1' && this.data.guestType !== '4' && (formData.arrivalTime === '' || formData.arrivalTime === null || formData.arrivalTime === undefined)) {
wx.showToast({ wx.showToast({
title: '请选择抵达时间', title: '请选择抵达时间',
icon: 'none', icon: 'none',
@@ -702,7 +716,7 @@ Page({
} }
// 离开时间 // 离开时间
if (this.data.identity === '1' && this.data.needSend === '1' && this.data.guestType !== '4' && (formData.departureTime === '' || formData.departureTime === null || formData.departureTime === undefined) ) { if (this.data.identity === '1' && this.data.needSend === '1' && this.data.guestType !== '4' && (formData.departureTime === '' || formData.departureTime === null || formData.departureTime === undefined)) {
wx.showToast({ wx.showToast({
title: '请选择离开时间', title: '请选择离开时间',
icon: 'none', icon: 'none',
@@ -710,6 +724,19 @@ Page({
}) })
return return
} }
// 校验时间
if (formData.arrivalTime && formData.departureTime) {
let flag = compareDate(formData.arrivalTime, formData.departureTime)
if (flag) {
// 抵达时间大于离开时间
wx.showToast({
title: '抵达时间不能大于离开时间',
icon: 'none',
duration: 2000
})
return
}
}
// 离开站 // 离开站
if (this.data.identity === '1' && this.data.needSend === '1' && this.data.guestType !== '4' && formData.departureStation === '') { if (this.data.identity === '1' && this.data.needSend === '1' && this.data.guestType !== '4' && formData.departureStation === '') {
wx.showToast({ wx.showToast({
@@ -729,6 +756,9 @@ Page({
}) })
return return
} }
// 会议id // 会议id
if (this.data.selectedMeeting.id) { if (this.data.selectedMeeting.id) {
formData.meetingId = this.data.selectedMeeting.id formData.meetingId = this.data.selectedMeeting.id
@@ -794,18 +824,18 @@ Page({
} }
} }
}) })
}else{ } else {
wx.showToast({ wx.showToast({
title: res.message, title: res.message,
icon:'none', icon: 'none',
duration:2000 duration: 2000
}) })
} }
}).catch(err => { }).catch(err => {
wx.showToast({ wx.showToast({
title: err.message, title: err.message,
icon:'none', icon: 'none',
duration:2000 duration: 2000
}) })
}) })
}, },
+9
View File
@@ -90,3 +90,12 @@ export function money(s) {
export function dutyCode(s) { export function dutyCode(s) {
return /^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/.test(s) return /^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/.test(s)
} }
export function compareDate(date1, date2) {
let Date1 = new Date(date1);
let Date2 = new Date(date2);
if (Date1.getTime() > Date2.getTime()) {
return true
} else {
return false
}
}