$(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();
			}
		})
	}
	
	$("#familyMemberForm .updateDate").datetimepicker({
	    language:  "zh-CN",
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    format: "yyyymmdd"
	});
	
	//填值---开始
	if( JSON.stringify(familyData[operationRowNum]) != "{}" ){//判断是否保存过值
		$("#familyMemberForm .managerName").val(familyData[operationRowNum].managerName);//主要关系人姓名
		$("#familyMemberForm .certType").attr("value",familyData[operationRowNum].certType);//主要关系人证件类型
		$("#familyMemberForm .certNo").val(familyData[operationRowNum].certNo);//登记注册号码
		$("#familyMemberForm .memberType").attr("value",familyData[operationRowNum].memberType);//家族关系
		$("#familyMemberForm .memberName").val(familyData[operationRowNum].memberName);//家族成员姓名
		$("#familyMemberForm .memberCertType").attr("value",familyData[operationRowNum].memberCertType);//家族成员证件类型
		$("#familyMemberForm .memberCertNo").val(familyData[operationRowNum].memberCertNo);//家族成员证件号码
		$("#familyMemberForm .updateDate").val(familyData[operationRowNum].updateDate);//更新日期
	}
	
	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");
			$(".familyMemberDialog").modal("hide");
			$(".familyMemberDialog").on('hidden.zui.modal', function(){
				familyData[operationRowNum].managerName=$("#familyMemberForm .managerName").val();//主要关系人姓名
				if( $("#familyMemberForm .certType").val()!='' ){
					familyData[operationRowNum].certType=$("#familyMemberForm .certType").val();//主要关系人证件类型id
					familyData[operationRowNum].certTypeCN=$("#familyMemberForm .certType").find("option:selected").text();//主要关系人证件类型name
				}else {
					familyData[operationRowNum].certType='';
					familyData[operationRowNum].certTypeCN='';
				}
				familyData[operationRowNum].certNo=$("#familyMemberForm .certNo").val();//登记注册号码
				if( $("#familyMemberForm .memberType").val()!='' ){
					familyData[operationRowNum].memberType=$("#familyMemberForm .memberType").val();//家族关系
					familyData[operationRowNum].memberTypeCN=$("#familyMemberForm .memberType").find("option:selected").text();//家族关系name
				}else {
					familyData[operationRowNum].memberType='';
					familyData[operationRowNum].memberTypeCN='';
				}
				familyData[operationRowNum].memberName=$("#familyMemberForm .memberName").val();//家族成员证件类型
				if( $("#familyMemberForm .memberCertType").val()!='' ){
					familyData[operationRowNum].memberCertType=$("#familyMemberForm .memberCertType").val();//家族关系
					familyData[operationRowNum].memberCertTypeCN=$("#familyMemberForm .memberCertType").find("option:selected").text();//家族关系name
				}else {
					familyData[operationRowNum].memberCertType='';
					familyData[operationRowNum].memberCertTypeCN='';
				}
				familyData[operationRowNum].memberCertNo=$("#familyMemberForm .memberCertNo").val();//家族成员证件号码
				familyData[operationRowNum].updateDate=$("#familyMemberForm .updateDate").val();//更新日期
				//console.log(familyData);
				updateListData('orgFamilyList',familyData[operationRowNum],operationRowNum);
			});
		},
		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个字符'
			}
		}
	})
})