//修改重要股东
function updateEnterPriseEmployee(id,certType,certNo){
	sendlistpage = $('#importantShareHolderList').getGridParam('page');
	var custId='';
	if( $("#companySocialCreditCode").val()=='' ){
		custId=enterPriseBusinessQuery.enterPriseDomesticCompanyId
	}else{
		custId=$("#companySocialCreditCode").val()
	};
	$(".enterpriseDialog").load('/orgbaseInfo/stockholder/update?custId='+custId+'&certType='+certType+'&certNo='+certNo,function(){
		$("#myModal-updateImportantShareHolderInfor").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 = $('#importantShareHolderList').getGridParam('page');
				
				$.ajax({
					url:'/orgbaseInfo/stockholder/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();
								//刷新表格(当前页)
								 $('#importantShareHolderList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/orgbaseInfo/stockholder/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;
		};
		$('#importantShareHolderList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/stockholder/doList',
			datatype : 'json',
			postData: postdata,
			page : 1
		}).trigger('reloadGrid');
	};
	
	function operateBusinessUser(cellValue,options,rowObject){
		var btnstr = '';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示
			if( $('#updateOrgStockholder').length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateEnterPriseEmployee('+rowObject.id+',\''+rowObject.certType+'\',\''+rowObject.certNo+'\')"></i></p>';
			};
			if( $('#deleteOrgStockholder').length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+rowObject.id+',\''+rowObject.certType+'\',\''+rowObject.certNo+'\')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	function operateRatio(cellValue,options,rowObject){
		return rowObject.stockHoldingRatioStr+'%';
	}
	
	var tablepostdata = {'fastSearch':custId};
	
	sxUtil.jqGrid('#importantShareHolderList',{
		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: 'stockHolderType', label: '股东类型',sortable:false,width:90,align:'left',title:false},
            {name: 'stockHolderName', label: '股东名称',sortable:false,width:120,align:'left',title:false},
            {name: 'certTypeCN', label: '证件/登记注册号类型',sortable:false,align:'left',width:120,title:false},
            {name: 'certNo', label: '证件/登记注册号码',sortable:false,align:'left',width:150,title:false},
            {name: 'stockHoldingRatioStr', label: '持股比例',sortable:false,align:'left',width:60,title:false,formatter:operateRatio},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:150,title:false,formatter:operateBusinessUser}
		], 
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/stockholder/doList',
		pager : "#importantShareHolderListPage",
		multiselect: false,
		rownumbers:false,
		postData : tablepostdata,
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('重要股东列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(loadSendData);
	//新增
	$("#addImportantShareHolder").click(function(){
		sendlistpage = $('#importantShareHolderList').getGridParam('page');
		$('.enterpriseDialog').load('/orgbaseInfo/stockholder/add?custId='+custId,function(){
			$("#myModal-addImportantShareHolderInfor").modal("show");
		})
	})
})