$(function(){
	// 只有卖方基本信息, 卖方为授信主体
	if( creditReportQuery.source == 'sell' ){
		$('.buyerBasicLi,.businessBasicBuyerLi').remove();
	};
	// 只有买方基本信息, 买方为交易对手
	if( creditReportQuery.source == 'buy' ){
		$('.sellerBasicLi,.businessBasicSellerLi').remove();
	};
	// 买方基本信息和卖方基本信息都有, 买方为授信主体，卖方为交易对手
	if( creditReportQuery.source == 'all' ){
		
	};
	
	// 切换导航
	$('.projectListTab li.sellerBasicLi').click(function(){// 卖方基本信息
		if( !$(this).hasClass('active') ){
			$(".yk_rightcontent").load("/creditReportingBasicInfo/sellerView");
		};
	});
	$('.projectListTab li.buyerBasicLi').click(function(){// 买方基本信息
		if( !$(this).hasClass('active') ){
			$(".yk_rightcontent").load("/creditReportingBasicInfo/buyerView");
		};
	});
	$('.projectListTab li.businessBasicBuyerLi').click(function(){// 买方业务信息
		if( !$(this).hasClass('active') ){
			$(".yk_rightcontent").load("/creditreporting/businessInfo/buyerView?creditReportingId="+creditReportQuery.creditReportingId+'&custId='+creditReportQuery.counterpartyId);
		};
	});
	$('.projectListTab li.businessBasicSellerLi').click(function(){// 卖方业务信息
		if( !$(this).hasClass('active') ){
			$(".yk_rightcontent").load("/creditreporting/businessInfo/sellerView?creditReportingId="+creditReportQuery.creditReportingId+'&custId='+creditReportQuery.creditSubjectId);
		};
	});
	
	if( $('.form-horizontal .newTabAddUpdateBox div.row').length <= 0 ){
		$('.form-horizontal .newTabAddUpdateBox').append('<p>无相关信息</p>');
	};
	
	// 卖方-修改按钮
	$('.updateNewsBtnSell').click(function(){
		$(".yk_rightcontent").load("/creditreporting/businessInfo/sellerEdit?creditReportingId="+creditReportQuery.creditReportingId+'&custId='+creditReportQuery.creditSubjectId);
		return false;
	});
	
	// 买方-修改按钮
	$('.updateNewsBtnBuy').click(function(){
		$(".yk_rightcontent").load("/creditreporting/businessInfo/buyerEdit?creditReportingId="+creditReportQuery.creditReportingId+'&custId='+creditReportQuery.counterpartyId);
		return false;
	});
	
	// 返回上级列表
	$(".newBackBtn").click(function(){
		$(".yk_rightcontent").load("/creditreporting/list");
		return false;
	});
	
	// 金额显示
	$('.moneyAmount').each(function(i,ele){
		if( $(ele).text()!='' ){
			$(ele).text(handleListAmountFn($(ele).text(),$(ele).attr('curr')))
		};
	})
	
	// 金额显示
	$('.moneyAmount-notList').each(function(i,ele){
		if( $(ele).text()!='' ){
			if( $(ele).attr('curr') ){
				$(ele).text(commaDelimiter($(ele).text())+' '+$(ele).attr('curr'))
			}else{
				$(ele).text(commaDelimiter($(ele).text()))
			}
		};
	});
	
	// 查看保证合同消息
	$('.viewGuaranty').click(function(){
		$('#myModal-viewGuarantyContractDialog').find('input').val('');
		$.ajax({
			url:'/creditreporting/businessInfo/doViewGuarantyContract',
			type:'get',
			data:{
				'creditReportingId':creditReportQuery.creditReportingId,
				'guarantyNo':$(this).attr('guarantyNo'),
				'loanNo':$(this).attr('loanNo'),
				'isNaturalPerson':$(this).attr('isNaturalPerson'),
				'certNo':$(this).attr('certNo')
			},
			success:function(data){
				if( data.success ){
					$('#myModal-viewGuarantyContractDialog').modal('show');
					$('.guarantyContractDialog-guarantyNo').val(data.data.guarantyNo);
					$('.guarantyContractDialog-creditLineType').val(data.data.creditLineTypeCN);
					$('.guarantyContractDialog-occurDate').val(data.data.occurDate);
					$('.guarantyContractDialog-guarantorName').val(data.data.guarantorName);
					$('.guarantyContractDialog-guarantyLoanCardNo').val(data.data.guarantyLoanCardNo);
					$('.guarantyContractDialog-isNaturalPerson').val(data.data.isNaturalPersonCN);
					$('.guarantyContractDialog-certType').val(data.data.certTypeCN);
					$('.guarantyContractDialog-certNo').val(data.data.certNo);
					$('.guarantyContractDialog-currency').val(data.data.currency);
					$('.guarantyContractDialog-guarantorAmount').val(data.data.guarantorAmount!=undefined?commaDelimiter(data.data.guarantorAmount.toString()):'');
					$('.guarantyContractDialog-createDate').val(data.data.createDate);
					$('.guarantyContractDialog-guaranteeForm').val(data.data.guaranteeFormCN);
					$('.guarantyContractDialog-status').val(data.data.statusCN);
				}else{
					 new $.zui.Messager('查询信息失败:'+data.msg, {
					    type: 'danger'
					 }).show();	
				}
			},
			error:function(status){
				 new $.zui.Messager('查询信息时出错:'+status, {
				    type: 'danger'
				 }).show();	
			}
		})
	});
	
	// 查看抵押合同信息
	$('.viewMortgage').click(function(){
		$('#myModal-viewMortgageContractDialog').find('input').val('');
		$.ajax({
			url:'/creditreporting/businessInfo/doViewMortgageContract',
			type:'get',
			data:{
				'creditReportingId':creditReportQuery.creditReportingId,
				'guarantyNo':$(this).attr('guarantyNo'),
				'loanNo':$(this).attr('loanNo'),
				'mortgageSeqNo':$(this).attr('mortgageSeqNo'),
				'isNaturalPerson':$(this).attr('isNaturalPerson')
			},
			success:function(data){
				if( data.success ){
					$('#myModal-viewMortgageContractDialog').modal('show');
					$('.mortgageContractDialog-guarantyNo').val(data.data.guarantyNo);
					$('.mortgageContractDialog-creditLineType').val(data.data.creditLineTypeCN);
					$('.mortgageContractDialog-occurDate').val(data.data.occurDate);
					$('.mortgageContractDialog-mortgageSeqNo').val(data.data.mortgageSeqNo);
					$('.mortgageContractDialog-mortgageName').val(data.data.mortgageName);
					$('.mortgageContractDialog-isNaturalPerson').val(data.data.isNaturalPersonCN);
					$('.mortgageContractDialog-guaranteeLoanCardNo').val(data.data.guaranteeLoanCardNo);
					$('.mortgageContractDialog-certType').val(data.data.certTypeCN);
					$('.mortgageContractDialog-certNo').val(data.data.certNo);
					$('.mortgageContractDialog-evaluationCurrency').val(data.data.evaluationCurrency);
					$('.mortgageContractDialog-evaluationValue').val(data.data.evaluationValue);
					$('.mortgageContractDialog-evaluationDate').val(data.data.evaluationDate);
					$('.mortgageContractDialog-orgName').val(data.data.orgName);
					$('.mortgageContractDialog-orgCode').val(data.data.orgCode);
					$('.mortgageContractDialog-assignDate').val(data.data.assignDate);
					$('.mortgageContractDialog-mortgageType').val(data.data.mortgageTypeCN);
					$('.mortgageContractDialog-mortgageAmount').val(data.data.mortgageAmount);
					$('.mortgageContractDialog-mortgageCurrency').val(data.data.mortgageCurrency);
					$('.mortgageContractDialog-regOrg').val(data.data.regOrg);
					$('.mortgageContractDialog-regDate').val(data.data.regDate);
					$('.mortgageContractDialog-status').val(data.data.statusCN);
					$('.mortgageContractDialog-mortgageDesc').val(data.data.mortgageDesc);
					$('.mortgageContractDialog-collateralName').val(data.data.collateralName);
					
				}else{
					 new $.zui.Messager('查询信息失败:'+data.msg, {
					    type: 'danger'
					 }).show();	
				}
			},
			error:function(status){
				 new $.zui.Messager('查询信息时出错:'+status, {
				    type: 'danger'
				 }).show();	
			}
		})
	});
	
	// 查看质押合同信息
	$('.viewPledge').click(function(){
		$('#myModal-viewPledgeContractDialog').find('input').val('');
		$.ajax({
			url:'/creditreporting/businessInfo/doViewPledgeContract',
			type:'get',
			data:{
				'creditReportingId':creditReportQuery.creditReportingId,
				'pledgeNo':$(this).attr('pledgeNo'),
				'loanNo':$(this).attr('loanNo'),
				'pledgeSeqNo':$(this).attr('pledgeSeqNo'),
				'isNaturalPerson':$(this).attr('isNaturalPerson')
			},
			success:function(data){
				if( data.success ){
					$('#myModal-viewPledgeContractDialog').modal('show');
					$('.pledgeContractDialog-pledgeNo').val(data.data.pledgeNo);
					$('.pledgeContractDialog-creditLineType').val(data.data.creditLineTypeCN);
					$('.pledgeContractDialog-occurDate').val(data.data.occurDate);
					$('.pledgeContractDialog-pledgeSeqNo').val(data.data.pledgeSeqNo);
					$('.pledgeContractDialog-pledgeName').val(data.data.pledgeName);
					$('.pledgeContractDialog-isNaturalPerson').val(data.data.isNaturalPersonCN);
					$('.pledgeContractDialog-pledgeLoanCardNo').val(data.data.pledgeLoanCardNo);
					$('.pledgeContractDialog-certType').val(data.data.certTypeCN);
					$('.pledgeContractDialog-certNo').val(data.data.certNo);
					$('.pledgeContractDialog-pledgeCurrency').val(data.data.pledgeCurrency);
					$('.pledgeContractDialog-pledgeValue').val(data.data.pledgeValue);
					$('.pledgeContractDialog-assignDate').val(data.data.assignDate);
					$('.pledgeContractDialog-pledgeType').val(data.data.pledgeTypeCN);
					$('.pledgeContractDialog-pledgeAmount').val(data.data.pledgeAmount);
					$('.pledgeContractDialog-pledgeCurrency1').val(data.data.pledgeCurrency1);
					$('.pledgeContractDialog-status').val(data.data.statusCN);
					
				}else{
					 new $.zui.Messager('查询信息失败:'+data.msg, {
					    type: 'danger'
					 }).show();	
				}
			},
			error:function(status){
				 new $.zui.Messager('查询信息时出错:'+status, {
				    type: 'danger'
				 }).show();	
			}
		})
	});
	
	// 查看不良信贷信息
	$('.viewBadCredit').click(function(){
		$('#myModal-viewBadCreditDialog').find('input').val('');
		$.ajax({
			url:'/creditreporting/businessInfo/doViewBadCreditAsset',
			type:'get',
			data:{
				'creditReportingId':creditReportQuery.creditReportingId,
				'bizNo':$(this).attr('bizNo'),
				'occurDate':$(this).attr('occurDate')
			},
			success:function(data){
				if( data.success ){
					$('#myModal-viewBadCreditDialog').modal('show');
					$('.badCreditDialog-bizNo').val(data.data.bizNo);
					$('.badCreditDialog-occurDate').val(data.data.occurDate);
					$('.badCreditDialog-borrowerName').val(data.data.borrowerName);
					$('.badCreditDialog-currency').val(data.data.currency.code);
					$('.badCreditDialog-balance').val(data.data.balance);
					$('.badCreditDialog-disposeDate').val(data.data.disposeDate);
					$('.badCreditDialog-disposeTypeCN').val(data.data.disposeTypeCN);
					$('.badCreditDialog-recycledAmount').val(data.data.recycledAmount);
				}else{
					 new $.zui.Messager('查询信息失败:'+data.msg, {
					    type: 'danger'
					 }).show();	
				}
			},
			error:function(status){
				 new $.zui.Messager('查询信息时出错:'+status, {
				    type: 'danger'
				 }).show();	
			}
		})
	});
	
})
