$(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);
		};
	});
	
	
	$(".orivalDate").each(function(){
		$(this).datetimepicker({
		    language:  "zh-CN",
		    weekStart: 1,
		    todayBtn:  1,
		    autoclose: 1,
		    todayHighlight: 1,
		    startView: 2,
		    minView: 2,
		    forceParse: 0,
		    format: "yyyymmdd"
		});
	})

	// 获取字典项数据
	function getDictCode(paramName){
		var dictOptionsData = {};
		$.ajax({
			url:'/orgbaseInfo/doFindDictCode',
			type:'get',
			data:{
				'paramName':paramName
			},
			async:false,
			success:function(data){
				dictOptionsData = data;
			},
			error:function(status){
				new $.zui.Messager('获取字典项时出错:'+status, {
				    type: 'danger'
				}).show();
			}
		});
		return dictOptionsData;
	};
	
	//编辑按钮
	$("#creditReportForm").delegate(".editNewsBtn",'click',function(){
		var url='/creditReportingBasicInfo'+$(this).attr("dialogUrl");
		var index=$(this).parents("tr").find('td').eq(0).text()-1;
		operationRowNum=index;
		$("#infoDialog").empty().load(url,function(){
			$("#creditReportingDialog").modal("show");
		})
	})
	
	//上报不上报
	$("#creditReportForm").delegate(".isReportNewsBtn","click",function(){
		var index=$(this).parents("tr").find('td').eq(0).text()-1;
		var report=true;
		if( $(this).text()=="不报" ){//选择的是上报
			report=false;
		}
		var listName=$(this).attr("listName");
		switch(listName){
			case 'orgExecutiveList':
				executiveData[index].isReporting=report;
				break;
			case 'orgStockholderList':
				stockholderData[index].isReporting=report;
				break;
			case 'orgAffiliatedList':
				affiliatedData[index].isReporting=report;
				break;
			case 'orgParentbodyList':
				parentbodyData[index].reporting=report;
				break;
			case 'orgFamilyList':
				familyData[index].reporting=report;
				break;
			case 'finbsList':
				finbsData[index].reporting=report;
				break;
			case 'finpsList':
				finpsData[index].reporting=report;
				break;
			case 'fincfList':
				fincfData[index].reporting=report;
				break;
			case 'custLawsuitList':
				custLawsuitData[index].reporting=report;
				break;
			case 'custEventList':
				custEventData[index].reporting=report;
				break;
		}
		$(this).text($(this).text()=='不报'?'报':'不报');
	})
	//列表中某行删除
	$('#creditReportForm').on('click','.deleteNewsBtn',function(){
		var $that = $(this);
		var index=$(this).parents("tr").find('td').eq(0).text()-1;
		var listName=$(this).attr("listName");var tempObj={};
		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) {
					switch(listName){
					case 'orgExecutiveList':
						tempObj.certType=executiveData[index].historicCertType;
						tempObj.certNo=executiveData[index].historicCertNo;
						deleteOrgExecutiveList.push(tempObj);
						executiveData.splice(index,1);
						break;
					case 'orgStockholderList':
						tempObj.certType=stockholderData[index].historicCertType;
						tempObj.certNo=stockholderData[index].historicCertNo;
						deleteOrgStockholderList.push(tempObj);
						stockholderData.splice(index,1);
						break;
					case 'orgAffiliatedList':
						tempObj.regNoType=affiliatedData[index].historicRegNoType;
						tempObj.regNo=affiliatedData[index].historicRegNo;
						deleteOrgAffiliatedList.push(tempObj);
						affiliatedData.splice(index,1);
						break;
					case 'orgParentbodyList':
						tempObj.regNoType=parentbodyData[index].historicRegNoType;
						tempObj.regNo=parentbodyData[index].historicRegNo;
						deleteOrgParentbodyList.push(tempObj);
						parentbodyData.splice(index,1);
						break;
					case 'orgFamilyList':
						tempObj.certType=familyData[index].historicCertType;
						tempObj.certNo=familyData[index].historicCertNo;
						tempObj.memberCertType=familyData[index].historicMemberCertType;
						tempObj.memberCertNo=familyData[index].historicMemberCertNo;
						deleteOrgFamilyList.push(tempObj);
						familyData.splice(index,1);
						break;
					case 'finbsList':
						tempObj.reportYear=finbsData[index].historicReportYear;
						tempObj.originalReportTime=finbsData[index].originalReportTime;
						deleteFinbsList.push(tempObj);
						finbsData.splice(index,1);
						break;
					case 'finpsList':
						tempObj.reportYear=finpsData[index].historicReportYear;
						tempObj.originalReportTime=finpsData[index].originalReportTime;
						deleteFinpsList.push(tempObj);
						finpsData.splice(index,1);
						break;
					case 'fincfList':
						tempObj.reportYear=fincfData[index].historicReportYear;
						tempObj.originalReportTime=fincfData[index].originalReportTime;
						deleteFincfList.push(tempObj);
						fincfData.splice(index,1);
						break;
					case 'custLawsuitList':
						tempObj.lawNo=custLawsuitData[index].historicLawNo;
						deleteCustLawsuitList.push(tempObj);
						custLawsuitData.splice(index,1);
						break;
					case 'custEventList':
						tempObj.eventNo=custEventData[index].historicEventNo;
						deleteCustEventList.push(tempObj);
						custEventData.splice(index,1);
						break;
					}
					//将列表的序号重新排一下
					var num=$that.parents("tr").find("td").eq(0).text();
					$that.parents("tr").nextAll().each(function(i){
						var ind=num*1+i;
						$(this).find("td").eq(0).text(ind);
					})
					$that.parents("tr").remove();
				}
			}
		})
	})

	// 查询卖方方基本信息
	function getSubjectBasicInfo(custId){
		$.ajax({
			url:'/creditReportingBasicInfo/doGetBasicInfo',
			type:'get',
			data:{
				'creditReportingId':creditReportQuery.creditReportingId,
				'custId':custId
			},
			async:false,
			success:function(data){
				// 通用信息
				$('.orgChnName').val(data.data.orgChnName);//机构中文名称
				$('.orgEngName').val(data.data.orgEngName);//机构英文名称
				$('.custId').val(data.data.custId);//客户号
				$('.loanCardNo').val(data.data.loanCardNo);//中征码
				if( data.data.regNoType!='' ){
					$('.regNoType').attr('orival',data.data.regNoType);//登记注册号类型
				}
				$('.regNo').val(data.data.regNo);//登记注册号
				$('.orgCode').val(data.data.orgCode);//组织机构代码
				$('.orgCreditCode').val(data.data.orgCreditCode);//机构信用代码
				$('.finOrgCode').val(data.data.finOrgCode);//金融机构代码
				$('.bankCode').val(data.data.bankCode);//管理行代码
				// 机构基本信息-基础段数据项
				if( data.data.orgbase ){
					$('.orgbase-custId').val(data.data.orgbase.custId);//客户号
					$('.orgbase-bankCode').val(data.data.orgbase.bankCode);//管理行代码
					$('.orgbase-orgCode').val(data.data.orgbase.orgCode);//组织机构代码
					$('.orgbase-orgCreditCode').val(data.data.orgbase.orgCreditCode);//机构信用代码
					$('.orgbase-regNoType').val(data.data.orgbase.regNoType);//登记注册号类型
					$('.orgbase-regNo').val(data.data.orgbase.regNo);//登记注册号
					$('.orgbase-nationalTaxNo').val(data.data.orgbase.nationalTaxNo);//纳税人识别号(国税)
					$('.orgbase-localTaxNo').val(data.data.orgbase.localTaxNo);//纳税人识别号(地税)
					$('.orgbase-finOrgCode').val(data.data.orgbase.finOrgCode);//金融机构代码
					$('.orgbase-loanCardNo').val(data.data.orgbase.loanCardNo);//中征码
					if( data.data.orgbase.custType!='' ){
						$('.orgbase-custType').attr('orival',data.data.orgbase.custType);//客户类型
					}
					$('.orgbase-accountPermitNo').val(data.data.orgbase.accountPermitNo);//开户许可证核准号
					$('.orgbase-isInstitution').val(data.data.orgbase.isInstitution);//是否事业单位
					$('.orgbase-dataExtraDate').val(data.data.orgbase.dataExtraDate);//更新日期
				};
				// 机构基本信息-基本属性段数据项
				if( data.data.orgAttribute ){
					$('.orgAttribute-custId').val(data.data.orgAttribute.custId);//客户号
					$('.orgAttribute-finOrgCode').val(data.data.orgAttribute.finOrgCode);//金融机构代码
					$('.orgAttribute-orgChnName').val(data.data.orgAttribute.orgChnName);//机构中文名称
					$('.orgAttribute-orgEngName').val(data.data.orgAttribute.orgEngName);//机构英文名称
					$('.orgAttribute-regAddr').val(data.data.orgAttribute.regAddr);//注册(登记)地址
					if( data.data.orgAttribute.countryCode!='' ){
						$('.orgAttribute-countryCode').attr('orival',data.data.orgAttribute.countryCode);//国别
					}
					if( data.data.orgAttribute.regAreaCode!='' ){//注册(登记)地行政区划
						$(".originalVal").parent().attr("originalCode",data.data.orgAttribute.regAreaCode);
						$(".originalVal").text(data.data.orgAttribute.regAreaCodeStr);
					}
					$('.orgAttribute-regDate').val(data.data.orgAttribute.regDate);//成立日期
					$('.orgAttribute-bizScope').val(data.data.orgAttribute.bizScope);//经营业务范围
					if( data.data.orgAttribute.capitalCurrency!='' ){
						$('.orgAttribute-capitalCurrency').attr('orival',data.data.orgAttribute.capitalCurrency);//注册资本(币种)
					}
					$('.orgAttribute-regCapital').val(data.data.orgAttribute.regCapital);//注册资本(万元)
					if( data.data.orgAttribute.orgType!='' ){
						$('.orgAttribute-orgType').attr('orival',data.data.orgAttribute.orgType);//组织机构类别
					}
					if( data.data.orgAttribute.orgSubType!='' ){
						$('.orgAttribute-orgSubType').attr('orival',data.data.orgAttribute.orgSubType);//组织机构类别细分
					}
					if( data.data.orgAttribute.industry!='' ){
						$('#industryId').val( data.data.orgAttribute.industry )
						//$('.orgAttribute-industry').attr('orival',data.data.orgAttribute.industry);//经济行业分类
					}
					if( data.data.orgAttribute.economicType ){
						$('.orgAttribute-economicType').attr('orival',data.data.orgAttribute.economicType);//经济类型
					}
					$('.orgAttribute-regDuee').val(data.data.orgAttribute.regDuee);//证书到期日
					$('.orgAttribute-updateDate').val(data.data.orgAttribute.updateDate);//更新日期
				};
				// 机构基本信息-机构状态段数据项
				if( data.data.orgStatus ){
					$('.orgStatus-custId').val(data.data.orgStatus.custId);//客户号
					$('.orgStatus-finOrgCode').val(data.data.orgStatus.finOrgCode);//金融机构代码
					if( data.data.orgStatus.accountStatus!='' ){
						$('.orgStatus-accountStatus').attr('orival',data.data.orgStatus.accountStatus);//基本户状态
					}
					if( data.data.orgStatus.enterpriseScope!='' ){
						$('.orgStatus-enterpriseScope').attr('orival',data.data.orgStatus.enterpriseScope);//企业规模
					}
					if( data.data.orgStatus.orgStatus!='' ){
						$('.orgStatus-orgStatus').attr('orival',data.data.orgStatus.orgStatus);//机构状态
					}
					$('.orgStatus-updateDate').val(data.data.orgStatus.updateDate);//更新日期
				};
				// 机构基本信息-联络信息段数据项
				if( data.data.orgContact ){
					$('.orgContact-custId').val(data.data.orgContact.custId);//客户号
					$('.orgContact-finOrgCode').val(data.data.orgContact.finOrgCode);//金融机构代码
					$('.orgContact-officeAddr').val(data.data.orgContact.officeAddr);//办公(生产、运营)地址
					$('.orgContact-phoneNo').val(data.data.orgContact.phoneNo);//联系电话
					$('.orgContact-financePhoneNo').val(data.data.orgContact.financePhoneNo);//财务部联系电话
					$('.orgContact-updateDate').val(data.data.orgContact.updateDate);//更新日期
				};
				var i=0;
				// 机构基本信息-高管及主要关系人段数据项
				if( data.data.orgExecutiveList ){
					renderData('orgExecutiveList',data.data.orgExecutiveList);
				}
				//机构基本信息-重要股东段数据项
				if( data.data.orgStockholderList ){
					renderData('orgStockholderList',data.data.orgStockholderList);
				}
				//机构基本信息-主要关联企业段数据项
				if( data.data.orgAffiliatedList ){
					renderData('orgAffiliatedList',data.data.orgAffiliatedList);
				}
				
				//机构基本信息-上级单位(主管单位)
				if( data.data.orgParentbodyList ){
					renderData('orgParentbodyList',data.data.orgParentbodyList);
				}
				//家族成员信息-基础段数据项
				if( data.data.orgFamilyList ){
					renderData('orgFamilyList',data.data.orgFamilyList);
				}
				//借款人财务报表-2007版资产负债表段数据项
				if( data.data.finbsList ){
					renderData('finbsList',data.data.finbsList);
				}
				//借款人财务报表-2007版利润及利润分配表段数据项
				if( data.data.finpsList ){
					renderData('finpsList',data.data.finpsList);
				}
				//借款人财务报表-2007版现金流量表段数据项
				if( data.data.fincfList ){
					renderData('fincfList',data.data.fincfList);
				}
				//借款人关注信息表-诉讼信息段数据项
				if( data.data.custLawsuitList ){
					renderData('custLawsuitList',data.data.custLawsuitList);
				}
				//借款人关注信息表-其他大事信息段数据项
				if( data.data.custEventList ){
					renderData('custEventList',data.data.custEventList);
				}
			},
			error:function(status){
				new $.zui.Messager('查询卖方基本信息时出错', {
				    type: 'danger'
				}).show();
			}
		})
	};
	if( $('.form-horizontal').hasClass('sell') ){
		getSubjectBasicInfo(creditReportQuery.creditSubjectId);
	}else{
		getSubjectBasicInfo(creditReportQuery.counterpartyId);
	};
	
	//经济行业分类--开始
	var industryOptions = getDictCode('industry');
    $('.allIndustry').empty();
    for( var i in industryOptions ){
    		$('.allIndustry').append('<li class="companyli" value="'+i+'">'+industryOptions[i]+'</li>');
    		if( $('#industryId').val() == i ){
    			$('#industry').val(industryOptions[i])
    		}
    };
	withSearchDropDownBox({
		allOptionSelector:'.allIndustry li',//所有的选项的选择器
		triggerSelector:'#industry',//触发选择(显示下拉框)的表单的选择器(存放选择的name)
		resultIdSelector:'#industryId',//表单元素选择器(存放选择的id)
		dropdownSelector:'.industryListBox'//下拉框的选择器
	});
	//经济行业分类--结束
	
	//字典项数据的获取
	$('.disposeType').each(function(i,ele){
		var selectTypeOptions = getDictCode($(ele).attr('selectData'));
		if( selectTypeOptions ){
			$(ele).empty().append('<option value="">请选择</option>')
			for( var i in selectTypeOptions){
				$(ele).append('<option value="'+i+'">'+selectTypeOptions[i]+'</option>')
			}
			if( $(ele).attr("orival") ){
				$(ele).find('option[value='+$(ele).attr("orival")+']').prop('selected',true);
			}
		};
	});
	
	$(".sourceEle").keyup(function(){
		var dataSource=$(this).attr("dataSource");
		$("[dataCopy="+dataSource+"]").val($(this).val());
		if( dataSource=='loanCardNo' ){//中征码改动，需同步修改财务报表的
			var i=0
			for(i=0;i<finbsData.length;i++){//资产负债表
				finbsData[i].loanCardNo=$(this).val();
			}
			for(i=0;i<finpsData.length;i++){//利润及利润分配表
				finpsData[i].loanCardNo=$(this).val();
			}
			for(i=0;i<fincfData.length;i++){//现金流量表
				fincfData[i].loanCardNo=$(this).val();
			}
		}
	})
	
	$(".sourceSelect").change(function(){
		var name=$(this).find("option:selected").text();
		var selectSource=$(this).attr("selectSource");
		$("[selectCopy="+selectSource+"]").val(name);
		$("[selectCopy="+selectSource+"]").attr("dataId",$(this).val())
	})
	$(".sourceSelect").change();
	// 选择行政区划
	$('#regAreaCode').click(function(){
		chooseProvinceEtc({
			triggerId:'#regAreaCode',// 触发选择元素的选择器, 即存放最终选择结果的选择器, 该元素需要至少有相对定位属性
			originalId:'.originalVal'// 原先的纯文字元素的选择器, 选填
		})
	});
	//暂存或保存最后的提交
	function submitFunction(e){
		var postdata = {},tipword = '';
		postdata = {
			'creditReportingId':creditReportQuery.creditReportingId
		};
		if( $('.form-horizontal').hasClass('buy') ){
			postdata['custId'] = creditReportQuery.counterpartyId;
		}else{
			postdata['custId'] = creditReportQuery.creditSubjectId;
		};
		postdata['orgChnName']=$("[name='orgChnName']").val();//机构中文名称
		postdata['orgEngName']=$("[name='orgEngName']").val();//机构英文名称
		postdata['loanCardNo']=$(".loanCardNo").val();//中征码
		postdata['regNoType']=$(".regNoType").val();//登记注册号类型
		postdata['regNo']=$(".regNo").val();//登记注册号
		postdata['orgCode']=$(".orgCode").val();//组织机构代码
		postdata['orgCreditCode']=$(".orgCreditCode").val();//机构信用代码
		postdata['finOrgCode']=$(".finOrgCode").val();//金融机构代码
		postdata['bankCode']=$(".bankCode").val();//管理行代码
		
		//机构基本信息-基础段数据项
		postdata['orgbase.custId']=$(".orgbase-custId").val();//客户号
		postdata['orgbase.bankCode']=$(".orgbase-bankCode").val();//管理行代码
		postdata['orgbase.orgCode']=$(".orgbase-orgCode").val();//组织机构代码
		postdata['orgbase.orgCreditCode']=$(".orgbase-orgCreditCode").val();//机构信用代码
		postdata['orgbase.regNoType']=$(".orgbase-regNoType").attr("dataId");//登记注册号类型
		postdata['orgbase.egNo']=$(".orgbase-regNo").val();//登记注册号
		postdata['orgbase.nationalTaxNo']=$(".orgbase-nationalTaxNo").val();//纳税人识别号(国税)
		postdata['orgbase.localTaxNo']=$(".orgbase-localTaxNo").val();//纳税人识别号(地税)
		postdata['orgbase.finOrgCode']=$(".orgbase-finOrgCode").val();//金融机构代码
		postdata['orgbase.loanCardNo']=$(".orgbase-loanCardNo").val();//中征码
		postdata['orgbase.custType']=$(".orgbase-custType").val();//客户类型
		postdata['orgbase.accountPermitNo']=$(".orgbase-accountPermitNo").val();//开户许可证核准号
		postdata['orgbase.isInstitution']=$(".orgbase-isInstitution").val();//是否事业单位
		postdata['orgbase.dataExtraDate']=$(".orgbase-dataExtraDate").val();//更新日期
		
		//机构基本信息-基本属性段数据项
		postdata['orgAttribute.custId']=$(".orgAttribute-custId").val();//客户号
		postdata['orgAttribute.finOrgCode']=$(".orgAttribute-finOrgCode").val();//金融机构代码
		postdata['orgAttribute.orgChnName']=$(".orgAttribute-orgChnName").val();//机构中文名称
		postdata['orgAttribute.orgEngName']=$(".orgAttribute-orgEngName").val();//机构英文名称
		postdata['orgAttribute.regAddr']=$(".orgAttribute-regAddr").val();//注册(登记)地址
		postdata['orgAttribute.countryCode']=$(".orgAttribute-countryCode").val();//国别
		
		if( $("#regAreaCode").attr("originalcode")!='' ){
			if( $("#regAreaCode").find(".resultcounty").length ){
				postdata['orgAttribute.regAreaCode']=$("#regAreaCode").find(".resultcounty").attr("deptcode");//注册(登记)地行政区划
			}else {
				postdata['orgAttribute.regAreaCode']=$("#regAreaCode").attr("originalcode");
			}
		}
		
		postdata['orgAttribute.regDate']=$(".orgAttribute-regDate").val();//成立日期
		postdata['orgAttribute.bizScope']=$(".orgAttribute-bizScope").val();//经营业务范围
		postdata['orgAttribute.capitalCurrency']=$(".orgAttribute-capitalCurrency").val();//注册资本(币种)
		postdata['orgAttribute.regCapital']=$(".orgAttribute-regCapital").val();//注册资本(万元)
		postdata['orgAttribute.orgType']=$(".orgAttribute-orgType").val();//组织机构类别
		postdata['orgAttribute.orgSubType']=$(".orgAttribute-orgSubType").val();//组织机构类别细分
		postdata['orgAttribute.industry']=$('#industryId').val();//经济行业分类
		postdata['orgAttribute.economicType']=$(".orgAttribute-economicType").val();//经济类型
		postdata['orgAttribute.regDuee']=$(".orgAttribute-regDuee").val();//证书到期日
		postdata['orgAttribute.updateDate']=$(".orgAttribute-updateDate").val();//更新日期
		
		//机构基本信息-机构状态段数据项
		postdata['orgStatus.custId']=$(".orgStatus-custId").val();//客户号
		postdata['orgStatus.finOrgCode']=$(".orgStatus-finOrgCode").val();//金融机构代码
		postdata['orgStatus.accountStatus']=$(".orgStatus-accountStatus").val();//基本户状态
		postdata['orgStatus.enterpriseScope']=$(".orgStatus-enterpriseScope").val();//企业规模
		postdata['orgStatus.orgStatus']=$(".orgStatus-orgStatus").val();//机构状态
		postdata['orgStatus.updateDate']=$(".orgStatus-updateDate").val();//更新日期
		
		//机构基本信息-联络信息段数据项
		postdata['orgContact.custId']=$(".orgContact-custId").val();//客户号
		postdata['orgContact.finOrgCode']=$(".orgContact-finOrgCode").val();//金融机构代码
		postdata['orgContact.officeAddr']=$(".orgContact-officeAddr").val();//办公(生产、运营)地址
		postdata['orgContact.phoneNo']=$(".orgContact-phoneNo").val();//联系电话
		postdata['orgContact.financePhoneNo']=$(".orgContact-financePhoneNo").val();//财务部联系电话
		postdata['orgContact.updateDate']=$(".orgContact-updateDate").val();//更新日期
		
		//机构基本信息-高管及主要关系人段数据项
		//console.log(executiveData);
		var i=0;
		for(i=0;i<executiveData.length;i++){
			for(var j in executiveData[i]){
				postdata['orgExecutiveList['+i+'].'+j+'']=executiveData[i][j];
			}
		};
		for(i=0;i<stockholderData.length;i++){
			for(var j in stockholderData[i]){
				postdata['orgStockholderList['+i+'].'+j+'']=stockholderData[i][j];
			}
		};
		for(i=0;i<affiliatedData.length;i++){
			for(var j in affiliatedData[i]){
				postdata['orgAffiliatedList['+i+'].'+j+'']=affiliatedData[i][j];
			}
		};
		for(i=0;i<parentbodyData.length;i++){
			for(var j in parentbodyData[i]){
				postdata['orgParentbodyList['+i+'].'+j+'']=parentbodyData[i][j];
			}
		};
		for(i=0;i<familyData.length;i++){
			for(var j in familyData[i]){
				postdata['orgFamilyList['+i+'].'+j+'']=familyData[i][j];
			}
		};
		for(i=0;i<finbsData.length;i++){
			for(var j in finbsData[i]){
				postdata['finbsList['+i+'].'+j+'']=finbsData[i][j];
			}
		};
		for(i=0;i<finpsData.length;i++){
			for(var j in finpsData[i]){
				postdata['finpsList['+i+'].'+j+'']=finpsData[i][j];
			}
		};
		for(i=0;i<fincfData.length;i++){
			for(var j in fincfData[i]){
				postdata['fincfList['+i+'].'+j+'']=fincfData[i][j];
			}
		};
		for(i=0;i<custLawsuitData.length;i++){
			for(var j in custLawsuitData[i]){
				postdata['custLawsuitList['+i+'].'+j+'']=custLawsuitData[i][j];
			}
		};
		for(i=0;i<custEventData.length;i++){
			for(var j in custEventData[i]){
				postdata['custEventList['+i+'].'+j+'']=custEventData[i][j];
			}
		}
		if( deleteOrgExecutiveList.length ){
			for(i=0;i<deleteOrgExecutiveList.length;i++){
				for(var j in deleteOrgExecutiveList[i]){
					postdata['deleteOrgExecutiveList['+i+'].'+j+'']=deleteOrgExecutiveList[i][j];
				}
			}
		}
		if( deleteOrgStockholderList.length ){
			for(i=0;i<deleteOrgStockholderList.length;i++){
				for(var j in deleteOrgStockholderList[i]){
					postdata['deleteOrgStockholderList['+i+'].'+j+'']=deleteOrgStockholderList[i][j];
				}
			}
		}
		if( deleteOrgAffiliatedList.length ){
			for(i=0;i<deleteOrgAffiliatedList.length;i++){
				for(var j in deleteOrgAffiliatedList[i]){
					postdata['deleteOrgStockholderList['+i+'].'+j+'']=deleteOrgAffiliatedList[i][j];
				}
			}
		}
		if( deleteOrgParentbodyList.length ){
			for(i=0;i<deleteOrgParentbodyList.length;i++){
				for(var j in deleteOrgParentbodyList[i]){
					postdata['deleteOrgParentbodyList['+i+'].'+j+'']=deleteOrgParentbodyList[i][j];
				}
			}
		}
		if( deleteOrgFamilyList.length ){
			for(i=0;i<deleteOrgFamilyList.length;i++){
				for(var j in deleteOrgFamilyList[i]){
					postdata['deleteOrgFamilyList['+i+'].'+j+'']=deleteOrgFamilyList[i][j];
				}
			}
		}
		if( deleteFinbsList.length ){
			for(i=0;i<deleteFinbsList.length;i++){
				for(var j in deleteFinbsList[i]){
					postdata['deleteFinbsList['+i+'].'+j+'']=deleteFinbsList[i][j];
				}
			}
		}
		if( deleteFinpsList.length ){
			for(i=0;i<deleteFinpsList.length;i++){
				for(var j in deleteFinpsList[i]){
					postdata['deleteFinpsList['+i+'].'+j+'']=deleteFinpsList[i][j];
				}
			}
		}
		if( deleteFincfList.length ){
			for(i=0;i<deleteFincfList.length;i++){
				for(var j in deleteFincfList[i]){
					postdata['deleteFincfList['+i+'].'+j+'']=deleteFincfList[i][j];
				}
			}
		}
		if( deleteCustLawsuitList.length ){
			for(i=0;i<deleteCustLawsuitList.length;i++){
				for(var j in deleteCustLawsuitList[i]){
					postdata['deleteCustLawsuitList['+i+'].'+j+'']=deleteCustLawsuitList[i][j];
				}
			}
		}
		if( deleteCustEventList.length ){
			for(i=0;i<deleteCustEventList.length;i++){
				for(var j in deleteCustEventList[i]){
					postdata['deleteCustEventList['+i+'].'+j+'']=deleteCustEventList[i][j];
				}
			}
		}
		if( $("span.error.shows").length>0 ){
			if( $("span.error.shows:first").parent().prev().find('input').length ){
				$("span.error.shows:first").parent().prev().find('input:first').focus();
			}else {
				$("span.error.shows:first").parent().find('input:first').focus();
			}
			return false;
		};
		$.ajax({
			url:'/creditReportingBasicInfo/doUpdateBasicInfo',
			type:'post',
			data:postdata,
			success:function(data){
				if( data.success ){
					new $.zui.Messager('保存成功', {
					    type: 'success'
					}).show();
					if( $(".yk_addNewMsg .btn-cancel").hasClass('sell') ){
						$(".yk_rightcontent").load("/creditReportingBasicInfo/sellerView");
					}else{
						$(".yk_rightcontent").load("/creditReportingBasicInfo/buyerView");
					};
				}else{
					new $.zui.Messager('保存失败:'+data.msg, {
					    type: 'danger'
					 }).show();	
				}
			},
			error:function(){
				new $.zui.Messager('保存时发生错误:'+status, {
				    type: 'danger'
				 }).show();	
			}
		});
		
		return false;
	} 

	//表单验证
	function addNewCustomer(e){ 
		$("#creditReportForm").validate({
			 promptPosition : "bottomLeft",
			 submitHandler : function(form) {
				 if( $(".orgAttribute-regCapital").val()&&(!$(".orgAttribute-capitalCurrency").val()) ){
					 $(".orgAttribute-capitalCurrency").parent().find("span.error").addClass("shows").show();
				 }
				 if( $("#creditReportForm").find("span.error.shows").length ){
					 return;
				 }
				 submitFunction(e);
			 }, 
			rules : {
				
			},
			messages : {
				
			} 
		}); 
	};
	
	//提交按钮
	$(".yk_addNewMsg .save").click(addNewCustomer);
	
	
	// 返回上级列表
	$(".newBackBtn").click(function(){
		$(".yk_rightcontent").load("/creditreporting/list");
		return false;
	});
	
	// 卖方-返回查看
	$(".yk_addNewMsg .btn-cancel.sell").click(function(){
		$(".yk_rightcontent").load("/creditReportingBasicInfo/sellerView");
		return false;
	});
	
	// 买方-返回查看
	$(".yk_addNewMsg .btn-cancel.buy").click(function(){
		$(".yk_rightcontent").load("/creditReportingBasicInfo/buyerView");
		return false;
	});
	
})
