//修改借款人诉讼
function updateEnterPriseEmployee(custId,lawNo){
	sendlistpage = $('#borrowerLitigationList').getGridParam('page');
	$(".enterpriseDialog").load('/orgbaseInfo/custlawsuit/update?custId='+custId+'&lawNo='+lawNo,function(){
		$("#myModal-updateBorrowerLitigationInfor").modal("show");
	})
};

//查看借款人诉讼
function viewEnterPriseEmployee(custId,lawNo){
	$(".enterpriseDialog").load('/orgbaseInfo/custlawsuit/view?custId='+custId+'&lawNo='+lawNo,function(){
		$("#myModal-viewBorrowerLitigationInfor").modal("show");
	})
}

//删除借款人诉讼
function deleteEnterPriseEmployee(custId,lawNo){
	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 = $('#borrowerLitigationList').getGridParam('page');
				$.ajax({
					url:'/orgbaseInfo/custlawsuit/doDelete',
					type:'get',
					data:{
						'custId':custId,
						'lawNo':lawNo
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除借款人诉讼成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								 $('#borrowerLitigationList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/orgbaseInfo/custlawsuit/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;
		};
		$('#borrowerLitigationList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/custlawsuit/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.lawNo+'\')"></i></p>';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示
			if( $("#updateCustLawsuit").length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateEnterPriseEmployee('+custId+',\''+rowObject.lawNo+'\')"></i></p>';
			}
			if( $("#deleteCustLawsuit").length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+custId+',\''+rowObject.lawNo+'\')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	function operatorAmount(cellValue,options,rowObject){
		return '<span class="tableRowMultipleSpan" style="text-align:right;">'+handleListAmountFn(rowObject.sentenceExecAmount,rowObject.currency)+'</span>'
	}
	
	var tablepostdata = {'fastSearch':custId};
	
	sxUtil.jqGrid('#borrowerLitigationList',{
		colNames:['借款人诉讼ID','序号','诉讼记录流水号','诉讼记录日期','借款人名称','<p style="margin:0;text-align:right;">判决执行金额</p>','判决执行日期','操作'],
		colModel:[
			{name: 'id', label: '家族成员ID', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: ' 序号', sortable:false,title:false,width:70},
			{name: 'lawNo', label: '诉讼记录流水号',sortable:false,width:120,align:'left',title:false},
            {name: 'occurDate', label: '诉讼记录日期',sortable:false,width:100,align:'left',title:false},
            {name: 'borrowerName', label: '借款人名称',sortable:false,align:'left',width:130,title:false},
            {name: 'sentenceExecAmount', label: '判决执行金额',sortable:false,align:'left',width:150,title:false,classes:'rightTitle',formatter:operatorAmount},
            {name: 'sentenceExecDate', label: '判决执行日期',sortable:false,align:'left',width:100,title:false},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:140,title:false,formatter:operateBusinessUser}
		], 
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/custlawsuit/doList',
		pager : "#borrowerLitigationListPage",
		multiselect: false,
		rownumbers:false,
		postData : tablepostdata,
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('借款人诉讼列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(loadSendData);
	//新增
	$("#addBorrowerLitigation").click(function(){
		sendlistpage = $('#borrowerLitigationList').getGridParam('page');
		$('.enterpriseDialog').load('/orgbaseInfo/custlawsuit/add?custId='+custId,function(){
			$("#myModal-addBorrowerLitigationInfor").modal("show");
		})
	})
})