$(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();
			}
		})
	}
	
	$("#seniorExecutiveInforForm .updateDate").datetimepicker({
	    language:  "zh-CN",
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    format: "yyyymmdd"
	});
	
	//填值---开始
	if( JSON.stringify(executiveData[operationRowNum]) != "{}" ){//判断是否保存过值
		$("#seniorExecutiveInforForm .relationalHumanType").attr("value",executiveData[operationRowNum].stakeHolderType);//关系人类型的id
		$("#seniorExecutiveInforForm #relationalName").val(executiveData[operationRowNum].name);//姓名
		$("#seniorExecutiveInforForm .certificateType").attr("value",executiveData[operationRowNum].certType);//证件类型id
		$("#seniorExecutiveInforForm #identificationNumber").val(executiveData[operationRowNum].certNo);//证件号码
		$("#seniorExecutiveInforForm .updateDate").val(executiveData[operationRowNum].updateDate);//更新日期
	}
	//填值---结束
	
	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");
			$(".seniorExecutiveInforDialog").modal("hide");
			$(".seniorExecutiveInforDialog").on('hidden.zui.modal', function(){
				if( $("#seniorExecutiveInforForm .relationalHumanType").val()!='' ){
					executiveData[operationRowNum].stakeHolderType=$("#seniorExecutiveInforForm .relationalHumanType").val();//关系人类型id
					executiveData[operationRowNum].stakeHolderTypeCN=$("#seniorExecutiveInforForm .relationalHumanType").find("option:selected").text();//关系人类型name
				}else {
					executiveData[operationRowNum].stakeHolderType='';
					executiveData[operationRowNum].stakeHolderTypeCN='';
				}
				executiveData[operationRowNum].name=$("#seniorExecutiveInforForm #relationalName").val();//姓名
				if( $("#seniorExecutiveInforForm .certificateType").val()!='' ){
					executiveData[operationRowNum].certType=$("#seniorExecutiveInforForm .certificateType").val();//证件类型id
					executiveData[operationRowNum].certTypeCN=$("#seniorExecutiveInforForm .certificateType").find("option:selected").text();//证件类型name
				}else {
					executiveData[operationRowNum].certType='';
					executiveData[operationRowNum].certTypeCN='';
				}
				executiveData[operationRowNum].certNo=$("#seniorExecutiveInforForm #identificationNumber").val();//证件号码
				executiveData[operationRowNum].updateDate=$("#seniorExecutiveInforForm .updateDate").val();//更新日期
				//console.log(executiveData);
				updateListData('orgExecutiveList',executiveData[operationRowNum],operationRowNum);
			});
		},
		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}个字符")
			}
		}
	})
})