//修改借款人大事
function updateEnterPriseEmployee(custId,eventNo){
	sendlistpage = $('#borrowerEventList').getGridParam('page');
	$(".enterpriseDialog").load('/orgbaseInfo/custevent/update?custId='+custId+'&eventNo='+eventNo,function(){
		$("#myModal-updateBorrowerEventInfor").modal("show");
	})
};
//查看借款人大事
function viewEnterPriseEmployee(custId,eventNo){
	$(".enterpriseDialog").load('/orgbaseInfo/custevent/view?custId='+custId+'&eventNo='+eventNo,function(){
		$("#myModal-viewBorrowerEventInfor").modal("show");
	})
}

//删除借款人大事
function deleteEnterPriseEmployee(custId,eventNo){
	bootbox.confirm({
		title : '删除借款人大事',
		message : '<div style="text-align:left;font-size:0.12rem">确认删除该借款人大事吗？</div>',
		size : 'small',
		buttons : {
			cancel : {
				label : '取消',
				className:'btn-white btn-info'
			},
			confirm : {
				label : '确定',
				className:'btn-white btn-info colorbtn'
			}
		},
		callback:function(result){
			if (result) {
				sendlistpage = $('#borrowerEventList').getGridParam('page');
				$.ajax({
					url:'/orgbaseInfo/custevent/doDelete',
					type:'get',
					data:{
						'custId':custId,
						'eventNo':eventNo
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除借款人大事成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								 $('#borrowerEventList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/orgbaseInfo/custevent/doList',
						            postData: {
						            	'fastSearch':custId
									},
						            page:sendlistpage 
						        }).trigger('reloadGrid');
							}else{
								new $.zui.Messager('删除借款人大事失败', {
								    type: 'danger'
								}).show();
							}
						}else{
							new $.zui.Messager('删除借款人大事请求失败:'+data.msg, {
							    type: 'danger'
							}).show();
						}
					},
					error:function(status){
						new $.zui.Messager('删除借款人大事时发生错误:'+status, {
						    type: 'danger'
						}).show();
					}
				})
			}
		}
	})
};

$(function(){
	var custId='';
	if( $("#companySocialCreditCode").val()=='' ){
		custId=enterPriseBusinessQuery.enterPriseDomesticCompanyId;
	}else{
		custId=$("#companySocialCreditCode").val()
	};
	function loadSendData(data){
		sendlistpage = 1;
		var postdata = {};
		if( data.data == null ){
			postdata = {'fastSearch':custId};
		}else{
			postdata = data.data;
		};
		$('#borrowerEventList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/custevent/doList',
			datatype : 'json',
			postData: postdata,
			page : 1
		}).trigger('reloadGrid');
	};
	
	function operateBusinessUser(cellValue,options,rowObject){
		var btnstr = '';
		btnstr += '<p><span>查看</span><i class="operateIconfont operateIcon-chakan" onclick="viewEnterPriseEmployee('+custId+',\''+rowObject.eventNo+'\')"></i></p>';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示
			if( $("#updateCustEvent").length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateEnterPriseEmployee('+custId+',\''+rowObject.eventNo+'\')"></i></p>';
			}
			if( $("#deleteCustEvent").length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+custId+',\''+rowObject.eventNo+'\')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	
	var tablepostdata = {'fastSearch':custId};
	
	sxUtil.jqGrid('#borrowerEventList',{
		colNames:['借款人大事ID','序号','大事记录流水号','大事记录日期','借款人名称','操作'],
		colModel:[
			{name: 'id', label: '借款人大事ID', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: ' 序号', sortable:false,title:false,width:50},
			{name: 'eventNo', label: '大事记录流水号',sortable:false,width:110,align:'left',title:false},
            {name: 'occurDate', label: '大事记录日期',sortable:false,width:100,align:'left',title:false},
            {name: 'borrowerName', label: '借款人名称',sortable:false,align:'left',width:170,title:false},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:120,title:false,formatter:operateBusinessUser}
		], 
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/custevent/doList',
		pager : "#borrowerEventListPage",
		multiselect: false,
		rownumbers:false,
		postData : tablepostdata,
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('借款人大事列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(loadSendData);
	//新增
	$("#addBorrowerEvent").click(function(){
		sendlistpage = $('#borrowerEventList').getGridParam('page');
		$('.enterpriseDialog').load('/orgbaseInfo/custevent/add?custId='+custId,function(){
			$("#myModal-addBorrowerEventInfor").modal("show");
		})
	})
})