时间改成年月日,人数和场次验证

This commit is contained in:
Leo_Ding 2025-09-23 19:20:38 +08:00
parent ee188bd4a2
commit d02c845016

View File

@ -334,17 +334,7 @@
name: '结束时间', name: '结束时间',
reg: /^.+$/, reg: /^.+$/,
errMsg: '结束时间不能空' errMsg: '结束时间不能空'
}, }
num: {
name: '申请场次',
reg: /^[1-9]\d*$/,
errMsg: '申请场次不能空且是正整数'
},
counter: {
name: '申请人数',
reg: /^[1-9]\d*$/,
errMsg: '申请人数不能空且是正整数'
},
}, },
// userName: '', // userName: '',
// userPhone: "15189809052", // userPhone: "15189809052",
@ -431,8 +421,8 @@
const year = now.getFullYear(); const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0'); const month = (now.getMonth() + 1).toString().padStart(2, '0');
this.startTime = `${year}-${month}`; this.startTime = `${year}${month}`;
this.endTime = `${year}-${month}`; this.endTime = `${year}${month}`;
this.startTimePickerValue = this.startTime; this.startTimePickerValue = this.startTime;
this.endTimePickerValue = this.endTime; this.endTimePickerValue = this.endTime;
} else { } else {
@ -441,9 +431,9 @@
const year = now.getFullYear(); const year = now.getFullYear();
const month = (now.getMonth() + 1).toString().padStart(2, '0'); const month = (now.getMonth() + 1).toString().padStart(2, '0');
const day = now.getDate().toString().padStart(2, '0'); const day = now.getDate().toString().padStart(2, '0');
this.borrowTimeData = `${year}-${month}-${day} ` this.borrowTimeData = `${year}${month}${day} `
this.startTime = `09:00`; this.startTime = `09时00分`;
this.endTime = `10:00`; this.endTime = `10时00分`;
this.startTimePickerValue = this.startTime; this.startTimePickerValue = this.startTime;
this.endTimePickerValue = this.endTime; this.endTimePickerValue = this.endTime;
} }
@ -579,7 +569,7 @@
const year = date.getFullYear(); const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0');
this.startTime = `${year}-${month}`; this.startTime = `${year}${month}`;
this.startTimePickerValue = this.startTime; this.startTimePickerValue = this.startTime;
} else { } else {
// //
@ -599,9 +589,9 @@
borrowTimeConfirm(e) { borrowTimeConfirm(e) {
console.log(e) console.log(e)
if (this.pickerType === 1) { if (this.pickerType === 1) {
this.startTime = `${e.value[0]}:${e.value[1]}` this.startTime = `${e.value[0]}${e.value[1]}`
} else { } else {
this.endTime = `${e.value[0]}:${e.value[1]}` this.endTime = `${e.value[0]}${e.value[1]}`
} }
this.noIsSelfStudy = false this.noIsSelfStudy = false
}, },
@ -612,7 +602,7 @@
const year = date.getFullYear(); const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0');
this.endTime = `${year}-${month}`; this.endTime = `${year}${month}`;
this.endTimePickerValue = this.endTime; this.endTimePickerValue = this.endTime;
} else { } else {
// //
@ -634,40 +624,9 @@
const year = date.getFullYear(); const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0'); const day = String(date.getDate()).padStart(2, '0');
this.borrowTimeData = `${year}-${month}-${day}`; this.borrowTimeData = `${year}${month}${day}`;
this.borrowTimeShow = false this.borrowTimeShow = false
}, },
adjustEndTime() {
console.log(this.startTime)
const [startH, startM] = this.startTime.split(':').map(Number);
let [endH, endM] = this.endTime.split(':').map(Number);
const startTotal = startH * 60 + startM;
let endTotal = endH * 60 + endM;
if (endTotal <= startTotal) {
endTotal = startTotal + 60;
endH = Math.floor(endTotal / 60);
endM = endTotal % 60;
this.endTime = `${endH.toString().padStart(2, '0')}:${endM.toString().padStart(2, '0')}`;
this.endTimeValue = `${endH}:${endM}`;
this.endTimePickerValue = this.endTime;
}
},
validateTime() {
const [startH, startM] = this.startTime.split(':').map(Number);
const [endH, endM] = this.endTime.split(':').map(Number);
const duration = (endH * 60 + endM) - (startH * 60 + startM);
if (duration < 30) {
uni.showToast({
title: '最少预订30分钟',
icon: 'none'
});
this.adjustEndTime();
}
},
/** /**
* 验证对象属性是否为空Promise版 * 验证对象属性是否为空Promise版
* @param {Object} obj - 要验证的对象 * @param {Object} obj - 要验证的对象
@ -762,9 +721,9 @@
userPhone: this.userPhone, userPhone: this.userPhone,
userAddress: this.userAddress, userAddress: this.userAddress,
userCardId: this.userCardId, userCardId: this.userCardId,
startTime: this.isSelfStudy ? this.startTime : startTime: this.isSelfStudy ? this.startTime.replace('年','-').replace('月','') :
`${this.borrowTimeData} ${this.startTime}`, `${this.borrowTimeData.replace('年','-').replace('月','-').replace('日','')} ${this.startTime.replace('时',':').replace('分','')}`,
endTime: this.isSelfStudy ? this.endTime : `${this.borrowTimeData} ${this.endTime}`, endTime: this.isSelfStudy ? this.endTime.replace('年','-').replace('月','') : `${this.borrowTimeData.replace('年','-').replace('月','-').replace('日','')} ${this.endTime.replace('时',':').replace('分','')}`,
counter: this.counter, counter: this.counter,
num: this.num, num: this.num,
// applyType:this.applyType // applyType:this.applyType
@ -789,15 +748,25 @@
concatName: this.concatName, concatName: this.concatName,
concatPhone: this.concatPhone, concatPhone: this.concatPhone,
companyName: this.companyName, companyName: this.companyName,
startTime: this.isSelfStudy ? this.startTime : startTime: this.isSelfStudy ? this.startTime.replace('年','-').replace('月','') :
`${this.borrowTimeData} ${this.startTime}`, `${this.borrowTimeData.replace('年','-').replace('月','-').replace('日','')} ${this.startTime.replace('时',':').replace('分','')}`,
endTime: this.isSelfStudy ? this.endTime : `${this.borrowTimeData} ${this.endTime}`, endTime: this.isSelfStudy ? this.endTime.replace('年','-').replace('月','') : `${this.borrowTimeData.replace('年','-').replace('月','-').replace('日','')} ${this.endTime.replace('时',':').replace('分','')}`,
counter: this.counter, counter: this.counter,
num: this.num, num: this.num,
stampUrl: this.stampUrl, stampUrl: this.stampUrl,
// applyType:this.applyType // applyType:this.applyType
} }
await this.validateObject(userApplyInfo, this.applyRules) const applyRules=Object.assign(this.applyRules,{num: {
name: '申请场次',
reg: /^[1-9]\d*$/,
errMsg: '申请场次不能空且是正整数'
},
counter: {
name: '申请人数',
reg: /^[1-9]\d*$/,
errMsg: '申请人数不能空且是正整数'
},})
await this.validateObject(userApplyInfo, applyRules)
const applyInfo = Object.assign(bookingInfo, userApplyInfo) const applyInfo = Object.assign(bookingInfo, userApplyInfo)
await this.validateBorrowTime(applyInfo) await this.validateBorrowTime(applyInfo)
const app = getApp() const app = getApp()