//修改家庭成员
function updateEnterPriseEmployee(id,certType,certNo,memberCertType,memberCertNo){
	sendlistpage = $('#familyMemberList').getGridParam('page');
	var custId='';
	if( $("#companySocialCreditCode").val()=='' ){
		custId=enterPriseBusinessQuery.enterPriseDomesticCompanyId
	}else{
		custId=$("#companySocialCreditCode").val()
	};
	$(".enterpriseDialog").load('/orgbaseInfo/family/update?custId='+custId+'&certType='+certType+'&certNo='+certNo+'&memberCertType='+memberCertType+'&memberCertNo='+memberCertNo,function(){
		$("#myModal-updateFamilyMemberInfor").modal("show");
	})
};

//删除家庭成员
function deleteEnterPriseEmployee(id,certType,certNo,memberCertType,memberCertNo){
	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 = $('#familyMemberList').getGridParam('page');
				$.ajax({
					url:'/orgbaseInfo/family/doDelete',
					type:'get',
					data:{
						'custId':custId,
						'certType':certType,
						'certNo':certNo,
						'memberCertType':memberCertType,
						'memberCertNo':memberCertNo
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除家庭成员成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								 $('#familyMemberList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/orgbaseInfo/family/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;
		};
		$('#familyMemberList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/family/doList',
			datatype : 'json',
			postData: postdata,
			page : 1
		}).trigger('reloadGrid');
	};
	
	function operateBusinessUser(cellValue,options,rowObject){
		var btnstr = '';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示
			if( $("#updateOrgFamily").length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateEnterPriseEmployee('+rowObject.id+',\''+rowObject.certType+'\',\''+rowObject.certNo+'\',\''+rowObject.memberCertType+'\',\''+rowObject.memberCertNo+'\')"></i></p>';
			};
			if( $("#deleteOrgFamily").length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+rowObject.id+',\''+rowObject.certType+'\',\''+rowObject.certNo+'\',\''+rowObject.memberCertType+'\',\''+rowObject.memberCertNo+'\')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	
	var tablepostdata = {'fastSearch':custId};
	
	sxUtil.jqGrid('#familyMemberList',{
		colNames:['家族成员ID','序号','主要关系人姓名','主要关系人证件类型','证件号码','家族关系','家族成员姓名','家族成员证件类型','证件号码','操作'],
		colModel:[
			{name: 'id', label: '家族成员ID', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: ' 序号', sortable:false,title:false,width:60},
			{name: 'memberName', label: '主要关系人姓名',sortable:false,width:110,align:'left',title:false},
            {name: 'certTypeCN', label: '主要关系人证件类型',sortable:false,width:110,align:'left',title:false},
            {name: 'certNo', label: '证件号码',sortable:false,align:'left',width:140,title:false},
            {name: 'memberType', label: '家族关系',sortable:false,align:'left',width:80,title:false},
            {name: 'memberName', label: '家族成员姓名',sortable:false,align:'left',width:110,title:false},
            {name: 'memberCertTypeCN', label: '家族成员证件类型',sortable:false,align:'left',width:110,title:false},
            {name: 'memberCertNo', label: '证件号码',sortable:false,align:'left',width:140,title:false},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:130,title:false,formatter:operateBusinessUser}
		],
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/family/doList',
		pager : "#familyMemberListPage",
		multiselect: false,
		rownumbers:false,
		postData : tablepostdata,
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('家庭成员列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(loadSendData);
	//新增
	$("#addFamilyMember").click(function(){
		sendlistpage = $('#familyMemberList').getGridParam('page');
		$('.enterpriseDialog').load('/orgbaseInfo/family/add?custId='+custId,function(){
			$("#myModal-addFamilyMemberInfor").modal("show");
		})
	})
})