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

//删除某行高管／关系人
function deleteEnterPriseEmployee(id,certType,certNo){
	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:'/orgbaseInfo/orgexec/doDelete',
					type:'get',
					data:{
						'custId':custId,
						'certType':certType,
						'certNo':certNo
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除高管／关系人成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								 $('#enterpriseSeniorExecutiveList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/orgbaseInfo/orgexec/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;
		};
		$('#enterpriseSeniorExecutiveList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/orgexec/doList',
			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('+custId+',\''+rowObject.certType+'\',\''+rowObject.certNo+'\')"></i></p>';
			};
			if( $("#deleteOrgExecutive").length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+custId+',\''+rowObject.certType+'\',\''+rowObject.certNo+'\')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	
	var tablepostdata = {'fastSearch':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: 'stakeHolderType', label: '关系人类型',sortable:false,width:100,align:'left',title:false},
            {name: 'name', label: '姓名',sortable:false,width:100,align:'left',title:false},
            {name: 'certTypeCN', label: '证件类型',sortable:false,align:'left',width:100,title:false},
            {name: 'certNo', label: '证件号码',sortable:false,align:'left',width:150,title:false},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:150,title:false,formatter:operateBusinessUser}
		], 
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/orgexec/doList',
		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('/orgbaseInfo/orgexec/add?custId='+custId,function(){
			$("#myModal-addSeniorExecutiveInfor").modal("show");
		})
	})
})