// 修改
function updateBadCreditDetail(bizNo,occurDate){
	sendlistpage = $('#badCreditDetailList').getGridParam('page');
	$.get('/orgbaseInfo/badCreditAsset/update?&bizNo='+bizNo+'&occurDate='+occurDate+'&custId='+enterPriseBusinessQuery.enterPriseDomesticCompanyId,function(data){
		$(".enterpriseDialog").html(data);
		$('#myModal-updateBadCredit').modal('show')
	});
};

// 查看
function viewBadCreditDetail(bizNo,occurDate){
	$.get('/orgbaseInfo/badCreditAsset/view?bizNo='+bizNo+'&occurDate='+occurDate+'&custId='+enterPriseBusinessQuery.enterPriseDomesticCompanyId,function(data){
		$(".enterpriseDialog").html(data);
		$('#myModal-viewBadCredit').modal('show')
	})
};

//删除按钮
function deleteBadCreditDetail(bizNo,occurDate){
	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 = $('#badCreditDetailList').getGridParam('page');
				$.ajax({
					url:'/orgbaseInfo/badCreditAsset/doDelete',
					type:'post',
					data:{
						'bizNo':bizNo,
						'occurDate':occurDate,
						'custId':enterPriseBusinessQuery.enterPriseDomesticCompanyId
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								//刷新表格
								$('#badCreditDetailList').setGridParam({
									mtype:'GET',
									url : '/orgbaseInfo/badCreditAsset/doList',
									datatype : 'json',
									postData: {
										'fastSearch':enterPriseBusinessQuery.enterPriseDomesticCompanyId
									},
									page: sendlistpage
								});
								$('#badCreditDetailList').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(){
	function loadSendData(){
		sendlistpage = 1;
		$('#badCreditDetailList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/badCreditAsset/doList',
			datatype : 'json',
			postData: {
				'fastSearch':enterPriseBusinessQuery.enterPriseDomesticCompanyId
			},
			page : 1
		});
		$('#badCreditDetailList').trigger('reloadGrid');
	};
	
	function operateBadCredit(cellValue,options,rowObject){
		var btnstr = '';
		btnstr += '<p><span>查看</span><i class="operateIconfont operateIcon-chakan" onclick="viewBadCreditDetail(\''+rowObject.bizNo+'\',\''+rowObject.occurDate+'\')"></i></p>';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示
			if( $('#updateBadCreditAsset').length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateBadCreditDetail(\''+rowObject.bizNo+'\',\''+rowObject.occurDate+'\')"></i></p>';
			};
			if( $('#deleteBadCreditAsset').length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteBadCreditDetail(\''+rowObject.bizNo+'\',\''+rowObject.occurDate+'\')"></i></p>';
			}
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>';
	};
	
	function showBalance(cellValue,options,rowObject){
		return '<span class="tableRowMultipleSpan" style="text-align:right;">'+handleListAmountFn(rowObject.balanceStr,(rowObject.currency?rowObject.currency.code:''))+'</span>'
	};
	
	function showRecycledAmount(cellValue,options,rowObject){
		return '<span class="tableRowMultipleSpan" style="text-align:right;">'+handleListAmountFn(rowObject.recycledAmountStr,(rowObject.currency?rowObject.currency.code:''))+'</span>'
	}
	
	sxUtil.jqGrid('#badCreditDetailList',{
		colNames:['ID','序号','处置编号','事件发生日期','<p style="margin-bottom:0;text-align:right;">余额</p>','处置日期','<p style="margin-bottom:0;line-height:normal;">主要资产<br>处置方式</p>','<p style="margin-bottom:0;text-align:right;">已回收金额</p>','操作'],
		colModel:[
			{name: 'id', label: 'ID', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: '序号',sortable:false,width:50,align:'center',title:false},
			{name: 'bizNo', label: '处置编号',sortable:false,width:100,align:'center',title:false},
            {name: 'occurDate', label: '事件发生日期',sortable:false,align:'left',width:100,title:false},
            {name: 'balance', label: '余额',sortable:false,align:'center',width:120,title:false,classes:'rightTitle',formatter:showBalance},
            {name: 'disposeDate', label: '处置日期',sortable:false,align:'center',width:100,title:false},
            {name: 'disposeType', label: '主要资产处置方式',sortable:false,align:'center',width:70,title:false},
            {name: 'recycledAmount', label: '已回收金额',sortable:false,align:'center',width:120,title:false,classes:'rightTitle',formatter:showRecycledAmount},
            {name: 'operate', label: '操作',sortable:false,align:'left',width:150,title:false,formatter:operateBadCredit}
		], 
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/badCreditAsset/doList',
		pager : "#badCreditDetailListPage",
		multiselect: false,
		rownumbers:false,
		postData : {
			'fastSearch':enterPriseBusinessQuery.enterPriseDomesticCompanyId
		},
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('列表加载失败', {
			    type: 'warning'
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(function(){
		loadSendData()
	});
	
	// 进入新客户营销(新增)页面
	$("#addBadCreditDetail").click(function(){
		sendlistpage = $('#badCreditDetailList').getGridParam('page');
		$.get('/orgbaseInfo/badCreditAsset/add?custId='+enterPriseBusinessQuery.enterPriseDomesticCompanyId,function(data){
			$(".enterpriseDialog").html(data);
			$('#myModal-addBadCredit').modal('show');
		});
	});
	
})