//修改利润表
function updateEnterPriseEmployee(custId,reportYear,reportType,reportSubType,originalReportTime){
	sendlistpage = $('#finpsList').getGridParam('page');
	$(".enterpriseDialog").load('/orgbaseInfo/finps/update?custId='+custId+'&reportYear='+reportYear+'&reportType='+reportType+'&reportSubType='+reportSubType+'&originalReportTime='+originalReportTime,function(){
		$("#baseInfo_finpsDialog").modal("show");
	})
};
//查看利润表
function viewEnterPriseEmployee(custId,reportYear,reportType,reportSubType,originalReportTime){
	$(".enterpriseDialog").load('/orgbaseInfo/finps/view?custId='+custId+'&reportYear='+reportYear+'&reportType='+reportType+'&reportSubType='+reportSubType+'&originalReportTime='+originalReportTime,function(){
		$("#baseInfo_finpsDialog").modal("show");
	})
}

//删除利润表
function deleteEnterPriseEmployee(custId,reportYear,reportType,reportSubType,originalReportTime){
	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 = $('#finpsList').getGridParam('page');
				$.ajax({
					url:'/orgbaseInfo/finps/doDelete',
					type:'post',
					data:{
						'custId':custId,
						'reportYear':reportYear,
						'reportType':reportType,
						'reportSubType':reportSubType,
						'originalReportTime':originalReportTime
					},
					success:function(data){
						if( data.success ){
							if( data.data ){
								new $.zui.Messager('删除利润表成功', {
								    type: 'success'
								}).show();
								//刷新表格(当前页)
								 $('#finpsList').jqGrid('setGridParam',{ 
						            mtype:'GET',
						            url : '/orgbaseInfo/finps/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;
		};
		$('#finpsList').setGridParam({
			mtype:'GET',
			url : '/orgbaseInfo/finps/doList',
			datatype : 'json',
			postData: postdata,
			page : 1
		}).trigger('reloadGrid');
	};
	
	function operateBusinessUser(cellValue,options,rowObject){
		var reportYear=(rowObject.reportYear)?rowObject.reportYear:'';
		var reportType=(rowObject.reportType)?rowObject.reportType:'';
		var reportSubType=(rowObject.reportSubType)?rowObject.reportSubType:'';
		var originalReportTime=(rowObject.originalReportTime)?rowObject.originalReportTime:'';
		var btnstr = '';
		btnstr += '<p><span>查看</span><i class="operateIconfont operateIcon-chakan" onclick="viewEnterPriseEmployee('+rowObject.custId+',\''+reportYear+'\',\''+reportType+'\',\''+reportSubType+'\',\''+originalReportTime+'\')"></i></p>';
		
		if( $('#companySocialCreditCode').val()=='' ){// 查看进入时不显示   custId,reportYear,reportType,reportSubType,originalReportTime
			if( $("#updateFinps").length>0 ){
				btnstr += '<p><span>修改</span><i class="operateIconfont operateIcon-bianji" onclick="updateEnterPriseEmployee('+rowObject.custId+',\''+reportYear+'\',\''+reportType+'\',\''+reportSubType+'\',\''+originalReportTime+'\')"></i></p>';
			}
			if( $("#deleteFinps").length>0 ){
				btnstr += '<p><span>删除</span><i class="operateIconfont operateIcon-shanchu" onclick="deleteEnterPriseEmployee('+rowObject.custId+',\''+reportYear+'\',\''+reportType+'\',\''+reportSubType+'\',\''+originalReportTime+'\')"></i></p>';
			};
		};
		
		return '<div class="operateIcon noHover">'+btnstr+'</div>'
	};
	
	var tablepostdata = {'fastSearch':custId};
	
	sxUtil.jqGrid('#finpsList',{
		colNames:['利润表ID','序号','本系统报表年月','上报报表年份','报表类型','报表类型细分','业务发生日期','操作'],
		colModel:[
			{name: 'id', label: '利润表ID', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: ' 序号', sortable:false,title:false,width:50},
			{name: 'originalReportTime', label: '本系统报表年月',sortable:false,width:120,align:'left',title:false},
            {name: 'reportYear', label: '上报报表年份',sortable:false,width:150,align:'left',title:false},
            {name: 'reportTypeCN', label: '报表类型',sortable:false,align:'left',width:110,title:false},
            {name: 'reportSubTypeCN', label: '报表类型细分',sortable:false,align:'left',width:110,title:false},
            {name: 'occurDate', label: '业务发生日期',sortable:false,align:'left',width:110,title:false},
            {name: 'operate', label: '操作',sortable:false,align:'center',width:150,title:false,formatter:operateBusinessUser}
		], 
		height:'auto',
		mtype:'GET',
		url : '/orgbaseInfo/finps/doList',
		pager : "#finpsListPage",
		multiselect: false,
		rownumbers:false,
		postData : tablepostdata,
		page:sendlistpage,
		loadError:function(){
			new $.zui.Messager('利润表列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		}
	},true);
	
	//刷新
	$('#refresh').click(loadSendData);
})