添加时间校验

This commit is contained in:
wans 2021-05-12 17:20:00 +08:00
parent c115d0a8db
commit 549c9c3aef
3 changed files with 63 additions and 0 deletions

View File

@ -84,6 +84,11 @@
// 提交表单 // 提交表单
form.on('submit(submitForm)', function(formData) { form.on('submit(submitForm)', function(formData) {
// 校验时间
if(verifyDate(formData.field['estimateStart'],formData.field['estimateEnd']) == 1){
layer.msg('预计考试开始时间不能大于结束时间');
return;
}
top.dialog.confirm(top.dataMessage.commit, function(index) { top.dialog.confirm(top.dataMessage.commit, function(index) {
top.dialog.close(index); top.dialog.close(index);
var loadLayerIndex; var loadLayerIndex;
@ -101,6 +106,20 @@
return false; return false;
}); });
function verifyDate(value1,value2){
var v1 = new Date(Date.parse(value1.replace(/-/g,"/"))).getTime();
var v2 = new Date(Date.parse(value2.replace(/-/g,"/"))).getTime();
if( v1 < v2){
return -1;
}
if( v1 == v2){
return 0;
}
if( v1 > v2){
return 1;
}
}
$('.close').on('click', function() { $('.close').on('click', function() {
closeBox(); closeBox();
}); });

View File

@ -403,6 +403,15 @@
layer.msg('请至少选择一节课程'); layer.msg('请至少选择一节课程');
return; return;
} }
// 校验时间
if(verifyDate(formData.field['planStartTime'],formData.field['planEndTime']) == 1){
layer.msg('培训开始时间不能大于结束时间');
return;
}
if(verifyDate(formData.field['signUpStartTime'],formData.field['signUpEndTime']) == 1){
layer.msg('报名开始时间不能大于结束时间');
return;
}
formData.field['lessonList'] = lessonList; formData.field['lessonList'] = lessonList;
top.dialog.confirm(top.dataMessage.commit, function(index) { top.dialog.confirm(top.dataMessage.commit, function(index) {
top.dialog.close(index); top.dialog.close(index);
@ -435,6 +444,20 @@
parent.layer.close(parent.layer.getFrameIndex(window.name)); parent.layer.close(parent.layer.getFrameIndex(window.name));
} }
function verifyDate(value1,value2){
var v1 = new Date(Date.parse(value1.replace(/-/g,"/"))).getTime();
var v2 = new Date(Date.parse(value2.replace(/-/g,"/"))).getTime();
if( v1 < v2){
return -1;
}
if( v1 == v2){
return 0;
}
if( v1 > v2){
return 1;
}
}
$('.close').on('click', function() { $('.close').on('click', function() {
closeBox(); closeBox();
}); });

View File

@ -81,11 +81,13 @@
laydate.render({ laydate.render({
elem: '#estimateStart', elem: '#estimateStart',
format: 'yyyy-MM-dd', format: 'yyyy-MM-dd',
trigger: 'click',
value : estimateStart.substring(0,10) value : estimateStart.substring(0,10)
}); });
laydate.render({ laydate.render({
elem: '#estimateEnd', elem: '#estimateEnd',
format: 'yyyy-MM-dd', format: 'yyyy-MM-dd',
trigger: 'click',
value : estimateEnd.substring(0,10) value : estimateEnd.substring(0,10)
}); });
//判断审核状态0审核中 //判断审核状态0审核中
@ -109,6 +111,11 @@
// 提交表单 // 提交表单
form.on('submit(submitForm)', function(formData) { form.on('submit(submitForm)', function(formData) {
// 校验时间
if(verifyDate(formData.field['estimateStart'],formData.field['estimateEnd']) == 1){
layer.msg('预计考试开始时间不能大于结束时间');
return;
}
top.dialog.confirm(top.dataMessage.commit, function(index) { top.dialog.confirm(top.dataMessage.commit, function(index) {
top.dialog.close(index); top.dialog.close(index);
var loadLayerIndex; var loadLayerIndex;
@ -130,6 +137,20 @@
closeBox(); closeBox();
}); });
function verifyDate(value1,value2){
var v1 = new Date(Date.parse(value1.replace(/-/g,"/"))).getTime();
var v2 = new Date(Date.parse(value2.replace(/-/g,"/"))).getTime();
if( v1 < v2){
return -1;
}
if( v1 == v2){
return 0;
}
if( v1 > v2){
return 1;
}
}
function closeBox() { function closeBox() {
parent.layer.close(parent.layer.getFrameIndex(window.name)); parent.layer.close(parent.layer.getFrameIndex(window.name));
} }