$(function(){
	function getDictionaryItem(paramName,name,ele){
		$.ajax({
			type:"get",
			url:'/orgbaseInfo/doFindDictCode',
			data:{
				'paramName':paramName
			},
			success:function(data){
//				console.log(data);
				if( data ){
					ele.empty().append('<option value="">请选择</option>');
					for(var i in data){
						ele.append('<option value="'+i+'">'+data[i]+'</option>');
					}
					if( ele.attr("value")!='' ){//有值
						ele.find("option").each(function(){
							if( $(this).val()==ele.attr("value") ){
								$(this).prop("selected",true);
							}
						})
					}
				}
			},
			error:function(status){
				new $.zui.Messager(name+'数据获取失败', {
					type : 'danger',
					time : 1500
				}).show();
			}
		})
	}
	$("#superiorUnitForm .updateDate").datetimepicker({
	    language:  "zh-CN",
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    format: "yyyymmdd"
	});
	//填值---开始
	if( JSON.stringify(parentbodyData[operationRowNum]) != "{}" ){//判断是否保存过值
		$("#superiorUnitForm .parentName").val(parentbodyData[operationRowNum].parentName);//上级机构名称
		$("#superiorUnitForm .regNoType").attr("value",parentbodyData[operationRowNum].regNoType);//登记注册号类型
		$("#superiorUnitForm .regNo").val(parentbodyData[operationRowNum].regNo);//登记注册号码
		$("#superiorUnitForm .updateDate").val(parentbodyData[operationRowNum].updateDate);//更新日期
	}
	getDictionaryItem('regNoType','登记注册号类型',$("#superiorUnitForm .regNoType"));
	
	$(".superiorUnitDialog .addSure").removeClass("loadingCircle");
	
	$(".superiorUnitDialog .addSure").click(function(){
		$("#superiorUnitForm").submit();
	})
	$("#superiorUnitForm").validate({
		promptPosition : "bottomLeft",
		submitHandler : function(form) {
			$(".superiorUnitDialog .addSure").addClass("loadingCircle");
			$(".superiorUnitDialog").modal("hide");
			$(".superiorUnitDialog").on('hidden.zui.modal', function(){
				parentbodyData[operationRowNum].parentName=$("#superiorUnitForm .parentName").val();//上级机构名称
				if( $("#superiorUnitForm .regNoType").val() ){
					parentbodyData[operationRowNum].regNoType=$("#superiorUnitForm .regNoType").val();//登记注册号类型id
					parentbodyData[operationRowNum].regNoTypeCN=$("#superiorUnitForm .regNoType").find("option:selected").text();//登记注册号类型name
				}else {
					parentbodyData[operationRowNum].regNoType='';
					parentbodyData[operationRowNum].regNoTypeCN='';
				}
				parentbodyData[operationRowNum].regNo=$("#superiorUnitForm .regNo").val();//登记注册号码
				parentbodyData[operationRowNum].updateDate=$("#superiorUnitForm .updateDate").val();//更新日期
				//console.log(parentbodyData);
				updateListData('orgParentbodyList',parentbodyData[operationRowNum],operationRowNum);
			});
		},
		rules : {
			'parentName':{
				required:true,
				minlength:2,
				maxlength:120
			},
			'regNoType':{
				required:true
			},
			'regNo':{
				required:true
			}
		},
		messages : {
			'parentName':{
				required:'请填写上级机构名称',
				minlength:'最少填写2个字符',
				maxlength:'最多填写120个字符'
			},
			'regNoType':{
				required:'请选择登记注册号类型'
			},
			'regNo':{
				required:'请填写登记注册号码'
			}
		}
	})
})