//修改高管／关系人
function updateEnterPriseEmployee(id,certType,certNo){
	sendlistpage = $('#enterpriseSeniorExecutiveList').getGridParam('page');
	$(".enterpriseDialog").load('/creditEntBusiness/relative/updateCreditEntRelative?id='+id,function(){
		$("#myModal-updateSeniorExecutiveInfor").modal("show");
	})
};

//删除某行高管／关系人
function deleteEnterPriseEmployee(id){
	var custId='';
	if( $("#companySocialCreditCode").val()=='' ){
		custId=enterPriseBusinessQuery.enterPriseDomesticCompanyId
	}else{
		custId=$("#companySocialCreditCode").val()
	};
	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 = $('#enterpriseSeniorExecutiveList').getGridParam('page');
				$.ajax({
					url:'/creditEntBusiness/relative/doDelete?relativeId=' + id,
					type:'get',
					data:{

					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除关联信息成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								 $('#enterpriseSeniorExecutiveList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/creditEntBusiness/relative/doListCreditEntRelative',
						            postData: {'entBusInfoId':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 = {'entBusInfoId':custId};
		}else{
			postdata = data.data;
		};
		$('#enterpriseSeniorExecutiveList').setGridParam({
			mtype:'GET',
			url : '/creditEntBusiness/relative/doListCreditEntRelative',
			datatype : 'json',
			postData: postdata,
			page : 1
		}).trigger('reloadGrid');
	};
	
	function operateBusinessUser(cellValue,options,rowObject){
		var btnstr = '';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示
			if( $('#updateOrgExecutive').length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateEnterPriseEmployee('+rowObject.id+')"></i></p>';
			};
			if( $("#deleteOrgExecutive").length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+rowObject.id+')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	
	var tablepostdata = {'entBusInfoId':custId};
	
	sxUtil.jqGrid('#enterpriseSeniorExecutiveList',{
		colNames:['关联信息ID','序号','主体统一社会信用码','关联关系','身份类型','身份类别','关系人名称','证件类型','证件号','操作'],
		colModel:[
			{name: 'id', label: '关联信息ID', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: ' 序号', sortable:false,title:false,width:70},
			{name: 'subjectSocialCreditCode', label: '主体统一社会信用码',width:220,sortable:false,align:'left',title:false},
            {name: 'entOthType.name', label: '关联关系',sortable:false,align:'left',title:false},
			{name: 'type.name', label: '身份类型',sortable:false,align:'left',title:false},
			{name: 'idType.name', label: '身份类别',sortable:false,align:'left',title:false},
			{name: 'name', label: '关系人名称',sortable:false,align:'left',title:false},
			{name: 'certType.name', label: '证件类型',sortable:false,align:'left',title:false},
			{name: 'certId', label: '证件号',sortable:false,align:'left',title:false},
			// {name: 'flag', label: '出资人出资比例',sortable:false,width:200,align:'left',title:false},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:150,title:false,formatter:operateBusinessUser}
		], 
		height:'auto',
		mtype:'GET',
		url : '/creditEntBusiness/relative/doListCreditEntRelative',
		pager : "#enterpriseSeniorExecutiveListPage",
		multiselect: false,
		rownumbers:false,
		postData : tablepostdata,
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('关联信息列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(loadSendData);
	//新增
	$("#addSeniorExecutive").click(function(){
		sendlistpage = $('#enterpriseSeniorExecutiveList').getGridParam('page');
		$('.enterpriseDialog').load('/creditEntBusiness/relative/addCreditEntRelative?entBusInfoId='+custId,function(){
			$("#myModal-addSeniorExecutiveInfor").modal("show");
		})
	})
})