$(function(){
	var occurDate=$(".occurHiddenDate").val();
	if(occurDate){
		$(".occurDate").val(occurDate.substring(0,4)+'-'+occurDate.substring(4,6)+'-'+occurDate.substring(6,8));
	}
	$(".occurDate").datetimepicker({
	    language:  "zh-CN",
	    weekStart: 1,
	    todayBtn:  1,
	    autoclose: 1,
	    todayHighlight: 1,
	    startView: 2,
	    minView: 2,
	    forceParse: 0,
	    format: "yyyymmdd"
	});
	$(".occurDate").val(occurDate);
	$(".borrowerEventDialog .addSure").removeClass("loadingCircle");
	
	$(".borrowerEventDialog .addSure").click(function(){
		$("#borrowerEventForm").submit();
	})
	$("#borrowerEventForm").validate({
		promptPosition : "bottomLeft",
		submitHandler : function(form) {
			$(".borrowerEventDialog .addSure").addClass("loadingCircle");
			
			$(form).ajaxSubmit({
				success : function(e) {
					if (e && e.success == true) {
						new $.zui.Messager('保存成功', {
							type : 'success',
							time : 1500
						}).show();
						$(".borrowerEventDialog .addSure").removeClass("loadingCircle");
						$(".borrowerEventDialog").modal("hide");
						$(".borrowerEventDialog").on('hidden.zui.modal', function(){
							//刷新表格
							$('#borrowerEventList').trigger('reloadGrid');
						});
					}else {
						new $.zui.Messager('保存失败:'+e.msg, {
							type : 'danger',
							time : 1500
						}).show();
						$(".borrowerEventDialog .addSure").removeClass("loadingCircle");
					}
				}
			})
		},
		rules : {
			'eventNo':{
				required:true
			},
			'occurDate':{
				required:true
			},
			'borrowerName':{
				required:true
			},
			'eventDesc':{
				required:true
			}
		},
		messages : {
			'eventNo':{
				required:'请填写大事记录流水号'
			},
			'occurDate':{
				required:'请选择大事记录日期'
			},
			'borrowerName':{
				required:'请填写借款人名称'
			},
			'eventDesc':{
				required:'请填写大事描述'
			}
		}
	})
})