$(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('stakeHolderType','关系人类型',$("#seniorExecutiveInforForm .relationalHumanType"));
	getDictionaryItem('certType','证件类型',$("#seniorExecutiveInforForm .certificateType"));
	
	$(".seniorExecutiveInforDialog .addSure").removeClass("loadingCircle");
	
	$(".seniorExecutiveInforDialog .addSure").click(function(){
		$("#seniorExecutiveInforForm").submit();
	})
	$("#seniorExecutiveInforForm").validate({
		promptPosition : "bottomLeft",
		submitHandler : function(form) {
			$(".seniorExecutiveInforDialog .addSure").addClass("loadingCircle");
			
			$(form).ajaxSubmit({
				success : function(e) {
					if (e && e.success == true) {
						new $.zui.Messager('保存成功', {
							type : 'success',
							time : 1500
						}).show();
						$(".seniorExecutiveInforDialog .addSure").removeClass("loadingCircle");
						$(".seniorExecutiveInforDialog").modal("hide");
						$(".seniorExecutiveInforDialog").on('hidden.zui.modal', function(){
							//刷新表格
							$('#enterpriseSeniorExecutiveList').trigger('reloadGrid');
						});
					}else {
						new $.zui.Messager('保存失败:'+e.msg, {
							type : 'danger',
							time : 1500
						}).show();
						$(".seniorExecutiveInforDialog .addSure").removeClass("loadingCircle");
					}
				}
			})
		},
		rules : {
			'stakeHolderType':{
				required:true
			},
			'name':{
				required:true,
				minlength:2,
				maxlength:120
			},
			'certType':{
				required:true
			},
			'certNo':{
				required:true,
				maxlength:20
			}
		},
		messages : {
			'mailData' : {
				required : "请选择关系人类型"
			},
			'name':{
				required:'请填写姓名',
				minlength:$.validator.format("最少需输入{0}个字符"),
				maxlength:$.validator.format("最多只能输入{0}个字符")
			},
			'certType':{
				required:'请选择证件类型'
			},
			'certNo':{
				required:'请填写证件号码',
				maxlength:$.validator.format("最多只能输入{0}个字符")
			}
		}
	})
})