欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

页面校验-新建项目

程序员文章站 2022-05-01 20:13:31
...
$(document).ready(
	function() {
			var flag = true;
		$('#changeform').submit(function() {
			var projectScValNull = true;
			var s ="";
			var parent_id = $("#parent_id").val();
			var projectTypeId02 = $("#projectTypeId").find("option:selected").attr("code");
			var users = $("input[name=userTypeIdAndUserId]");
			
			var typeCode = $("#projectTypeId").find("option:selected").attr("code");
			
			for(var i=0;i<users.length;i++){
				s += users[i].value+",";
			}
			$("#type_user").val(s) ;
			var errors = '';
			if(flag == false){
				errors = errors + "不能重复提交!\n";
				alert("不能重复提交!\n");
			}
			
			var startdate = $("input[name='name']").val();
			if (startdate == null || startdate.length == 0) {
				errors = errors + "项目名称不能为空!\n";
				$("input[name='name']").focus();
			}
			
			//如果项目类型是【增量交付项目】,那么【增量负责人不能为空】
			var zlfzr02 = $("#charger02").val();
			var zlfzr03 = $("#charger03").val();
			if(typeCode == "02"){
				if (zlfzr02 == null || zlfzr02.length == 0) {
					errors = errors + "增量负责人不能为空!\n";
					$("#charger02").focus();
				}
			}
			
			if(typeCode == "01"){
				var performanceone=$('input:radio[class="performanceone"]:checked').val();
				var planStart = $("#01planStart").val();
				var planPublish = $("#01planPublish").val();
				if(planStart.length == 0 ){
					errors = errors + "计划开始时间不能为空!\n";
				}
				
				if(planPublish.length == 0 ){
					errors = errors + "计划结束时间不能为空!\n";
				}

				if(parent_id == ""){
					var d1 = new Date(planStart.replace(/-/g, "/"));
				    var d2 = new Date(planPublish.replace(/-/g, "/"));
				    var time = d2.getTime() - d1.getTime();
				    var da = parseInt(time / (1000 * 60 * 60 * 24));
				    
					if(da < 14){
						errors = errors + "传统项目周期不低于2周,2周以下的项目建议建立日常发布!\n";
					} 
				}
				
				if(performanceone == 'Y'){
					var performanceNameone = $("#performanceNameone").val();
					if(performanceNameone.length == 0 || performanceNameone == null){
						errors = errors + "性能测试的模块名称不能为空!\n";
						$("#performanceNameone").focus();
					}
				}
			}
			
			if(typeCode == "03"){
				if (zlfzr03 == null || zlfzr03.length == 0) {
					errors = errors + "日常发布负责人不能为空!\n";
					$("#charger03").focus();
				}
			}
			
//			if (zlfzr == null || zlfzr.length == 0) {
	//			if(typeCode == "02"){
	//				errors = errors + "增量负责人不能为空!\n";
	//			}else if (typeCode=="03"){
	//		        errors = errors + "日常发布负责人不能为空!\n";
	//			}
	//			$("#charger").focus();
	//		}
			
			if(projectTypeId02 != "02"){
				$("input.projectScope,textarea.projectScope").not(':disabled').each(function(i,projectSc){
					var projectScVal = $(projectSc).val();
					if(projectScVal && projectScVal != ""){
						projectScValNull = false;
					}
				});
				if(projectScValNull){
					errors = errors + "项目范围不能为空!\n";
					$("input[name='requirement']").focus();
				}
			}
			if(projectTypeId02 == "02" && parent_id != ""){
				var planStartChild = $("#planStart02").val();
				var planPublishChild = $("#planPublish02").val();
				var performancetwo=$('input:radio[class="performancetwo"]:checked').val();
				
				$("input.projectScope,textarea.projectScope").not(':disabled').each(function(i,projectSc){
					var projectScVal = $(projectSc).val();
					if(projectScVal && projectScVal != ""){
						projectScValNull = false;
					}
				});
				if(projectScValNull){
					errors = errors + "项目范围不能为空!\n";
					$("input[name='requirement']").focus();
				}
				
				if(planStartChild.length == 0 ){
					errors = errors + "计划开始时间不能为空!\n";
				}
				
				if(planPublishChild.length == 0 ){
					errors = errors + "计划结束时间不能为空!\n";
				}
				
				if(performancetwo == 'Y'){
					var performanceNametwo = $("#performanceNametwo").val();
					if(performanceNametwo.length == 0 || performanceNametwo == null){
						errors = errors + "性能测试的模块名称不能为空!\n";
						$("#performanceNametwo").focus();
					}
				}
			}
			
			//对于类型【不是】【紧急发布】的项目的校验
			if(typeCode!="04"){
				var kfInput = $("#开发人员").find("input");
				if(kfInput.length == 0 ){
					errors = errors + "开发人员不能为空!\n";
					$("#开发人员").focus();
				}
				
				var qaInput = $("#QA").find("input");
				if(qaInput.length == 0 ){
					errors = errors + "QA人员不能为空!\n";
					$("#QA").focus();
				}
				
				var dbaInput = $("#DBA").find("input");
				if(dbaInput.length == 0 ){
					errors = errors + "DBA人员不能为空!\n";
					$("#DBA").focus();
				}
			}
			//对于类型是【紧急发布】的项目的校验
			if(typeCode=="04"){
			    /*
				var expectedTime = $("#expectedTime").val().trim();
				if(expectedTime.length == 0 ){
					errors = errors + "预计上线时间不能为空!\n";
					$("#expectedTime").focus();
				}
				var onlineReason = $("#onlineReason").val().trim();
				if(onlineReason.length == 0 ){
					errors = errors + "上线原因不能为空!\n";
					$("#onlineReason").focus();
				}
				
				var system = $("#system").val();
				if(system == "" || system == null){
					errors = errors + "系统不能为空!\n";
					$("#system").focus();
				}
			    var component = $("#component").val();
				if(component == "" || component == null){
					errors = errors + "应用不能为空!\n";
					$("#component").focus();
				}
				
				var componentUser = $("#componentUser").val().trim();
				if(componentUser.length == 0 ){
					errors = errors + "应用负责人不能为空!\n";
					$("#componentUser").focus();
				} 
				 */
				var qaInput = $("#QA").find("input");
				if(qaInput.length == 0 ){
					errors = errors + "QA人员不能为空!\n";
					$("#QA").focus();
				}
			}
			
			if (errors.length > 0) {
				alert(errors);
				return false;
			}
			flag = false;
		});
	});

 

相关标签: 页面校验