$(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();
			}
		})
	}
	
	getDictionaryItem('certType','主要关系人证件类型',$("#familyMemberForm .certType"));
	getDictionaryItem('memberType','家族关系',$("#familyMemberForm .memberType"));
	getDictionaryItem('certType','家族成员证件类型',$("#familyMemberForm .memberCertType"));
	
	$(".familyMemberDialog .addSure").removeClass("loadingCircle");
	
	$(".familyMemberDialog .addSure").click(function(){
		$("#familyMemberForm").submit();
	})
	$("#familyMemberForm").validate({
		promptPosition : "bottomLeft",
		submitHandler : function(form) {
			$(".familyMemberDialog .addSure").addClass("loadingCircle");
			
			$(form).ajaxSubmit({
				success : function(e) {
					if (e && e.success == true) {
						new $.zui.Messager('保存成功', {
							type : 'success',
							time : 1500
						}).show();
						$(".familyMemberDialog .addSure").removeClass("loadingCircle");
						$(".familyMemberDialog").modal("hide");
						$(".familyMemberDialog").on('hidden.zui.modal', function(){
							//刷新表格
							$('#familyMemberList').trigger('reloadGrid');
						});
					}else {
						new $.zui.Messager('保存失败:'+e.msg, {
							type : 'danger',
							time : 1500
						}).show();
						$(".familyMemberDialog .addSure").removeClass("loadingCircle");
					}
				}
			})
		},
		rules : {
			'managerName':{//主要关系人姓名
				required:true,
				minlength:2,
				maxlength:80
			},
			'certType':{
				required:true
			},
			'certNo':{
				required:true,
				maxlength:20
			},
			'memberType':{
				required:true
			},
			'memberName':{
				required:true,
				minlength:2,
				maxlength:80
			},
			'memberCertType':{
				required:true
			},
			'memberCertNo':{
				required:true,
				maxlength:20
			}
		},
		messages : {
			'managerName':{
				required:'请填写主要关系人姓名',
				minlength:'最少填写2个字符',
				maxlength:'最多填写80个字符'
			},
			'certType':{
				required:'请选择主要关系人证件类型'
			},
			'certNo':{
				required:'请填写主要关系人证件号码',
				maxlength:'最多填写20个字符'
			},
			'memberType':{
				required:'请选择家族关系'
			},
			'memberName':{
				required:'请填写家族成员姓名',
				minlength:'最少填写2个字符',
				maxlength:'最多填写80个字符'
			},
			'memberCertType':{
				required:'请选择家族成员证件类型'
			},
			'memberCertNo':{
				required:'请填写家族成员证件号码',
				maxlength:'最多填写20个字符'
			}
		}
	})
})