<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='print' />

<%@ include file="../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/swfupload/DBFhandlers.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.mask.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/papers/batchPaper.js"></script>

<%@ include file="../common/validation.jsp"%>
<title>批次管理</title>
<style >
	#skelTbl td{border:solid windowtext 1pt;padding:1px;}
	#skelTbl {border-collapse:collapse;border:none;}
	.tongjiTab td{border:1px solid #999999;}
</style>
<script language="javascript">
	$(function(){
		 $('#revocationBtnW3').on('click',function(){
			 $.messager.confirm("操作提示", "确定撤销最近一次入库操作吗?", function (data) {
				 if (data) {
					 var lastVal=$("#lastW3").val();
			    		if(lastVal==""){
			    			$.messager.alert('提示','没有最近一次入库记录!');
			    		}else{
			    			var obj={
			    				"code" : lastVal,
			    				"batchId" : ${paperBatch.id}
			    			}
			    			var PaperParams = JSON.stringify(obj);
			    			$.ajax({
			    				type : "POST",
			    				url : "${ctx}/examPaper/revocationInStorage",
			    				data : PaperParams,
			    				contentType : "application/json; charset=utf-8",
			    				dataType : "json",
			    				success : function(callback) {
			    					callback=eval(callback);
			    					if(callback.type=="success"){
			    						$.messager.alert('提示','撤销入库成功','info');
			    						$("#lastW3").val("");
			    						$('#dg').datagrid('reload');
			    					}else{
			    						$.messager.alert('提示','撤销入库失败','error');
			    						$('#dg').datagrid('reload');
			    					}
			    	    		}
			    			});
			    		}
				 }
			 });
		    });
		 
		 $('#revocationBtnW4').on('click',function(){
			 
			 $.messager.confirm("操作提示", "确定撤销最近一次出库操作吗?", function (data) {
				 if (data) {
					 var lastVal=$("#lastW4").val();
			    		if(lastVal==""){
			    			$.messager.alert('提示','没有最近一次入库记录!');
			    		}else{
			    			var obj={
				    				"code" : lastVal,
				    				"batchId" : ${paperBatch.id}
				    			}
				    		var PaperParams = JSON.stringify(obj);
			    			$.ajax({
			    				type : "POST",
			    				url : "${ctx}/examPaper/revocationOutBound",
			    				data : PaperParams,
			    				contentType : "application/json; charset=utf-8",
			    				dataType : "json",
			    				success : function(callback) {
			    					callback=eval(callback);
			    					if(callback.type=="success"){
			    						$.messager.alert('提示','撤销出库成功','info');
			    						$('#usedPapersDG').datagrid('reload');
			    					}else{
			    						$.messager.alert('操作提示','撤销出库失败','error');
			    						$('#usedPapersDG').datagrid('reload');
			    					}
			    					
			    	    		}
			    			});
			    		} 
				 }
			 });
		    });
		
		var swfuDBF;
		var swfuPaper;
		var swfuFormal;
		
		swfuDBF = new SWFUpload({
			 upload_url :"${ctx}/examPaper/DBFUpload/${paperBatch.id}",
			 use_query_string : false,
			 
			// File Upload Settings
			file_size_limit : "10 MB",	// 1000MB
			file_types : "*.DBF",
			file_types_description : "所有文件",
			file_upload_limit : "0",

			file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			upload_progress_handler : uploadProgress,
			upload_error_handler : dbfUploadError,
			upload_success_handler : uploadDBFSuccess,
			
			// Button Settings
			button_image_url : '${ctx}/resources/images/SmallSpyGlassWithTransperancy_17x18.png',
			button_placeholder_id : "spanButtonPlaceholder",
			button_width: 180,
			button_height: 18,
			button_text : '<span class="button">导入dbf（文件大小限制10M）<span class="buttonSmall"></span></span>',
			button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12px; } .buttonSmall { font-size: 10px; color: #ff0000;}',
			button_text_top_padding: 0,
			button_text_left_padding: 18,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			
			// Flash Settings
			flash_url : '${ctx}/resources/js/swfupload/swfupload.swf',

			custom_settings : {
				upload_target : "divFileProgressContainer"
			},
			// Debug Settings
			debug: false  //是否显示调试窗口
		});
		
		
		/**
		 * 当文件选择对话框关闭消失时，如果选择的文件成功加入上传队列，
		 * 那么针对每个成功加入的文件都会触发一次该事件（N个文件成功加入队列，就触发N次此事件）。
		 * @param {} file
		 * id : string,			    // SWFUpload控制的文件的id,通过指定该id可启动此文件的上传、退出上传等
		 * index : number,			// 文件在选定文件队列（包括出错、退出、排队的文件）中的索引，getFile可使用此索引
		 * name : string,			// 文件名，不包括文件的路径。
		 * size : number,			// 文件字节数
		 * type : string,			// 客户端操作系统设置的文件类型
		 * creationdate : Date,		// 文件的创建时间
		 * modificationdate : Date,	// 文件的最后修改时间
		 * filestatus : number		// 文件的当前状态，对应的状态代码可查看SWFUpload.FILE_STATUS }
		 */
		function fileQueued(file){
			if(file.type==".DBF"||file.type=="dbf"){
				swfuDBF.startUpload();
			}
			
//			$("#divFileProgress").show();
		}
		 
		 function dbfUploadError(file){
			 alert("文件大小： " + file.size);
		 }
		 
		 function uploadDBFSuccess(file, serverData){
			 serverData=eval('(' + serverData + ')');
			 if(serverData.type=="success"){
				 $.messager.alert('提示','导入成功!');
				 $(document).unmask();
				 $('#w').window('close');
				 $('#dg').datagrid('reload');
			 }else if(serverData.type=="fail"){
				 $.messager.alert('提示',"导入失败!" + serverData.message);
				 $(document).unmask();
				 $('#dg').datagrid('reload');
			 }else if(serverData.type=="contains"){
				 $.messager.alert('提示',serverData.message);
				 $(document).unmask();
				 $('#dg').datagrid('reload');
				 //var jsonData=eval(serverData.data);
				 /**var arr=jsonData.rows;
				 for(var i=0;i<5;i++){
					 
				 }*/
				 //$("#errorDg").datagrid({
					 //data:jsonData
				 //});   
				 
				 //$("#errorDiv").show();
			 }
		 }
	});
	
	function removePaperFromPapersDG(datagridId, batchId){
	    var selectedRows = $('#' + datagridId).datagrid('getSelections');
	    if(selectedRows.length < 1){
	        $.messager.alert('提示','请选中一行或多行记录！');
	    }else{
	    	var status;
	    	var flag=true;
	    	if(datagridId=='dg1'){
	    		status='FORMAL';
	    	}else if(datagridId=='usedPapersDG'){
	    		status='USED';
	    	}
	        var relatedPaperIds = [];
	        for(var i = 0; i < selectedRows.length; i++){
	            if(selectedRows[i].status==status){
	            	flag=false;
	            }
	            relatedPaperIds.push(selectedRows[i].id);
	        }
	        if(flag){
	        	  $.ajax({
		            type : "POST",
		            url : "${ctx}/examPaper/removePapersFromBatch",
		            data : {paperBatchId: batchId, relatedPaperIds : relatedPaperIds},
		            dataType : "json",
		            success: function(){
		                $(document).unmask();
		                $.messager.alert('提示','操作成功！','info');
		                $('#' + datagridId).datagrid('reload');
		                $('#' + datagridId).datagrid('clearChecked');
		            }
		        });
	        }else{
	        	if(status=='FORMAL'){
	        		$.messager.alert('提示','无法移出清样试卷！','error');
	        	}else if(status=='USED'){
	        		$.messager.alert('提示','无法移出已启用的试卷！请先撤销启用后再进行移出操作!','error');
	        	}
	        }
	    }
	}
	
	function onDbfUploadWindowClose(){
		$('#dbfFileUploadList .tableData').remove();
	}
</script>

</head>
<body>
<div class="container-fluid">
    <%@ include file="../common/header.jsp"%>
    <BGSOUND id="sound" balance="0" src="" loop="1"></BGSOUND>
    
    <div class="row-fluid">
        <%@ include file="../common/sub_menu.jsp"%>
        
        <div class="span10">
	        <ul class="breadcrumb">
		        <li class="active">批次管理 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        		批次代码：<i style="color:#bf290b;">${paperBatch.code}</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        		批次类型：<i style="color:#bf290b;">${paperBatch.type}</i></li>
	        </ul>

        	<div class="page-body">
			
	       		<div class="right" style="min-height:300px;position: relative;">
		             <div id="list-wrap posts" class="listview">
		                 <c:choose>
		                   <c:when test="${paperBatch.type == batchType_ruku }">
		                       <%@ include file="./batchPaperList/rukuPapers.jsp"%>
		                   </c:when>
		                   <c:when test="${paperBatch.type==batchType_qingyang}">
		                       <%@ include file="./batchPaperList/formalPapers.jsp"%>
		                   </c:when>
		                   <c:when test="${paperBatch.type==batchType_qiyong}">
		                       <%@ include file="./batchPaperList/usedPapers.jsp"%>
		                   </c:when>
		                   <c:when test="${paperBatch.type==batchType_gongjuan}">
		                       <%@ include file="./batchPaperList/gongjuanPapers.jsp"%>
		                   </c:when>
		                 </c:choose>
		              </div>
	            </div>
	        </div>
        </div>
    </div>
</div>
<%@ include file="../common/footer.jsp"%>
 
    <div id="w" class="easyui-window" title="导入dbf" data-options="modal:true,closed:true,iconCls:'icon-import',onClose:onDbfUploadWindowClose" style="width:750px;height:300px;padding:10px;">
        <div id="do_import_button">
        	<span id="spanButtonPlaceholder"></span>
        	
        	<div id="divFileProgressContainer" style="margin-top:10px;">
        		<table style="border-collapse: collapse;" class="tongjiTab" id="dbfFileUploadList">
        			<tr><td>文件名</td><td>上传结果</td></tr>
        		</table>
        	</div>
        </div>
        <br />
        <div>
        	提示:<br />
        		&nbsp;&nbsp;&nbsp;&nbsp;导入的DBF文件需要有:
        		<div align="center" style="color: red">
        			<table style="border-collapse: collapse;" class="tongjiTab">
        				<tr>
        					<td>字段名称</td>
        					<td>SJBH</td>
        					<td>QY</td>
        					<td>KCDM</td>
        					<td>KCMC</td>
        					<td>JC</td>
        					<td>BZ</td>
        					<td>CBS</td>
        					<td>BC</td>
        					<td>XXMC</td>
        					<td>ZK</td>
        				</tr>
        				<tr>
        					<td>字段含义</td>
        					<td>试卷编号</td>
        					<td>清样</td>
        					<td>课程代码</td>
        					<td>课程名称</td>
        					<td>教材</td>
        					<td>编者</td>
        					<td>出版社</td>
        					<td>版次</td>
        					<td>学校名称</td>
        					<td>专卡</td>
        				</tr>
        				<tr>
        					<td>数据类型</td>
        					<td>字符串</td>
        					<td>整型</td>
        					<td>字符串</td>
        					<td>字符串</td>
        					<td>字符串</td>
        					<td>字符串</td>
        					<td>字符串</td>
        					<td>字符串</td>
        					<td>字符串</td>
        					<td>整型</td>
        				</tr>
        				<tr>
        					<td>备注</td>
        					<td>-</td>
        					<td>1是清样、其他是毛坯</td>
        					<td>-</td>
        					<td>-</td>
        					<td>-</td>
        					<td>-</td>
        					<td>-</td>
        					<td>-</td>
        					<td>-</td>
        					<td><p>1是专卡、其他是非专卡、</p>没有这个字段都视为非专卡</td>
        				</tr>
        			</table>
        		 	
        		 </div> 
        </div>
        <div id="errorDiv" style="display: none">
        	<table id="errorDg" class="easyui-datagrid" data-options="fitColumns:true,singleSelect:false,striped:true,pagination:true,pageNumber:1,pageSize:10" >
				<thead>
					<tr class="title">
						<th rowspan="2" data-options="field:'courseCode',width:50,editor:{type:'validatebox',options:{required:true}}">课程代码</th>
						<th rowspan="2" data-options="field:'courseName',width:110,editor:{type:'validatebox',options:{required:true}}">课程名称</th>
						<th rowspan="2" data-options="field:'bookName',width:150,editor:{type:'validatebox',options:{required:true}}">教材名称</th>
						<th rowspan="2" data-options="field:'bookAuthor',width:50,editor:{type:'validatebox',options:{required:true}}">作者</th>
						<th rowspan="2" data-options="field:'school',width:60,editor:{type:'validatebox',options:{required:true}}">学校</th>
						<th rowspan="2" data-options="field:'bookPress',width:80,editor:{type:'validatebox',options:{required:true}}">出版社</th>
						<th rowspan="2" data-options="field:'bookPressYear',width:50,editor:{type:'validatebox',options:{required:true}}">版次</th>
						<th rowspan="2" data-options="field:'code',width:50,editor:{type:'validatebox',options:{required:true}}">版次</th>
				</thead>
			</table>
        </div>
    </div>
    
    <div id="w3" class="easyui-window" title="" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:700px;height:400px;padding:10px;">
        <div id="barcode-scan" style="text-align: center; font-weight: bold; font-size: 14px;">
            <span id="barcode-scan-result"  >等待扫描结果...</span><br />
            <form action="#" method="post" onsubmit="return checkCode('${ctx}','入库','codeW3','${paperBatch.id}')" id="scanForm">
            	<input type="text" id="codeW3"/>
            	<input type="button" value="撤销入库" id="revocationBtnW3" style="margin:5px;"/><input type="button" value="重新打印" id="repeatPrintBtn" />
            </form>
            <label id="promptW3" style="display: none"></label>
        </div>
        <input type="hidden" value="" id="lastW3"/>
         <dir id="infoW3" style="display: none"></dir>
    </div>
    
    <div id="w4" class="easyui-window" title="出库扫描" data-options="modal:true,closed:true,iconCls:'icon-import'" style="width:700px;height:400px;padding:10px;">
        <div id="barcode-scanW4" style="text-align: center; font-weight: bold; font-size: 14px;">
            <span id="barcode-scan-resultW4"  >等待扫描结果...</span><br />
            <form action="#" method="post" onsubmit="return checkCode('${ctx}','出库','codeW4','${paperBatch.id}')" id="scanFormW4">
            	<input type="text" id="codeW4"/>
            	<input type="button" value="撤销出库" id="revocationBtnW4" style="margin:5px;"/><input type="button" value="重新打印" id="repeatPrintBtnW4" />
            </form>
            <label id="promptW4" style="display: none"></label>
        </div>
        <input type="hidden" value="" id="lastW4"/>
        <dir id="infoW4" style="display: none"></dir>
    </div>
    
    <script type="text/javascript">
        var editIndex = undefined;
        function endEditing(){
            if (editIndex == undefined){return true;}
            if ($('#dg').datagrid('validateRow', editIndex)){
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        
        function onDblClickRow(index){
            if (editIndex != index){
                if (endEditing()){
                    $('#dg').datagrid('selectRow', index)
                            .datagrid('beginEdit', index);
                    editIndex = index;
                } else {
                    $('#dg').datagrid('selectRow', editIndex);
                }
            }
        }
        
        function append(){
            if (endEditing()){
                $('#dg').datagrid('appendRow',{status:''});
                editIndex = $('#dg').datagrid('getRows').length-1;
                $('#dg').datagrid('selectRow', editIndex)
                        .datagrid('beginEdit', editIndex);
                
            }
        }
        function removeit(){
        	var row = $('#dg').datagrid('getSelected');
        	var flag=true;
        	if (row){
        		var arr = new Array();
        		var arrCode=new Array();
        		var rows = $('#dg').datagrid("getSelections");
        		for(var i =0;i<rows.length;i++){
        			var index = $('#dg').datagrid('getRowIndex',rows[i]);
        			var rr=$('#dg').datagrid('getSelected',rows[i]);
        			if(rr.paperPath!=null||rr.standardAnswerPath!=null||rr.answerSheetPat!=null){
        				flag=false;
        				break;
        			}
        		}
  				
        		if(flag){
        			$.messager.confirm("操作提示", "确定要删除选中的试卷吗?", function (data) {
        	            if (data) {
        	            	for(var i =0;i<rows.length;i++){
                    			var index = $('#dg').datagrid('getRowIndex',rows[i]);
                    			var rr=$('#dg').datagrid('getSelected',rows[i]);
                    			$('#dg').datagrid('deleteRow',index);
                    			arr.push(rr.id);
                    			arrCode.push(rr.code);
                    		}
            				
            				var obj={
            						"arrCode" : arrCode,
            	            		"batchId" : ${paperBatch.id},
            	            		"array" : arr
            	            	};
            	           	var PaperParams=JSON.stringify(obj);
            	           	$.ajax({
                    			type : "POST",
                    			url : "${ctx}/examPaper/deletePaper",
                    			data :  PaperParams ,
                    			contentType : "application/json; charset=utf-8",
                    			dataType : "json",
                    			success : function(callback) {
                    				callback=eval(callback);
                    				if(callback.type=="success"){
                    					$.messager.alert('提示','删除成功');
                    					$('#dg').datagrid('reload');
                    					$('#dg').datagrid('clearChecked');
                    				}
                    			}
                    		});
        	            }
        			});
        			
        		}else{
        			$.messager.confirm("操作提示", "选中的数据中存在已导入的电子试卷或题卡,确定删除吗?", function (data) {
        	            if (data) {
        	            	for(var i =0;i<rows.length;i++){
                    			var index = $('#dg').datagrid('getRowIndex',rows[i]);
                    			var rr=$('#dg').datagrid('getSelected',rows[i]);
                    			$('#dg').datagrid('deleteRow',index);
                    			arr.push(rr.id);
                    			arrCode.push(rr.code);
                    		}
            				
            				var obj={
            						"arrCode" : arrCode,
            	            		"batchId" : ${paperBatch.id},
            	            		"array" : arr
            	            	};
            	           	var PaperParams=JSON.stringify(obj);
            	           	$.ajax({
                    			type : "POST",
                    			url : "${ctx}/examPaper/deletePaper",
                    			data :  PaperParams ,
                    			contentType : "application/json; charset=utf-8",
                    			dataType : "json",
                    			success : function(callback) {
                    				callback=eval(callback);
                    				if(callback.type=="success"){
                    					$.messager.alert('提示','删除成功');
                    					$('#dg').datagrid('reload');
                    					$('#dg').datagrid('clearChecked');
                    				}
                    			}
                    		});
        	            }
        			});
        		}
            }
            else{
            	$.messager.alert('提示','请选择要删除的行');
            }
        }
        function accept(){
            if (endEditing()){
                $('#dg').datagrid('acceptChanges');
                var inserted = $('#dg').datagrid('getSelected');
                if(inserted!=null){
                	$.ajax({
            			type : "POST",
            			url : "${ctx}/examPaper/addPaper",
            			data :  JSON.stringify(inserted) ,
            			contentType : "application/json; charset=utf-8",
            			dataType : "json",
            			success : function(callback) {
            				callback=eval(callback);
            				if(callback.type=="success"){
            					$.messager.alert('提示','保存成功');
            				}
            			}
            		});	
                }
            }
        }
        function reject(){
            $('#dg').datagrid('rejectChanges');
            editIndex = undefined;
        }
        
        function barcodeScanStart(scanWinfow,title){
        	if(scanWinfow=="W3"){
        		$('#w3').window({"title":title});
        		$('#w3').window('open');
            	$("#codeW3").focus();
        	}else if(scanWinfow=="W4"){
        		$('#w4').window({"title":title});
        		$('#w4').window('open');
            	$("#codeW4").focus();
        	}
        	
        }
        
        function checkOver(){
        	$.messager.confirm("操作提示", "是否确定结束检查?结束检查后将会删除不符合条件的试卷信息!", function (data) {
        		if (data) {
        			$(document).mask('正在结束检查，请稍等...');
        			var obj={
                    		"batchId" : ${paperBatch.id}
                    	};
                    	var PaperParams=JSON.stringify(obj);
                    	
                    	$.ajax({
                			type : "POST",
                			url : "${ctx}/examPaper/checkOver",
                			data :  PaperParams ,
                			contentType : "application/json; charset=utf-8",
                			dataType : "json",
                			success : function(callback) {
                				 $(document).unmask();
                				callback=eval(callback);
                				if(callback.type=="success"){
                					$.messager.alert('提示','结束检查完成');
                					$('#dg').datagrid('reload');
                				}else{
                					$.messager.alert('提示','结束检查失败');
                					$('#dg').datagrid('reload');
                				}
                			}
                		});
        		}
        	});
        }
        
        function confirmImportFormalPapers(){
        	var rows=$("#dg").datagrid("getRows");
        	for(var i=0;i<rows.length;i++){
        		$('#dg').datagrid('updateRow',{
        		    index: i,
        		    row: {
        		        status: '清样回库'
        		    }
        		});
            }
        	$('#w4').window('close');
        }
        function sendAjax(arr){
        	var obj={
            		"batchId" : ${paperBatch.id},
            		"array" : arr
            	};
            	var PaperParams=JSON.stringify(obj);
            	
            	$.ajax({
        			type : "POST",
        			url : "${ctx}/examPaper/formal",
        			data :  PaperParams ,
        			contentType : "application/json; charset=utf-8",
        			dataType : "json",
        			success : function(callback) {
        				callback=eval(callback);
        				if(callback.type=="success"){
        					$.messager.alert('提示','确认清样完成');
        					$('#dg').datagrid('reload');
        					$('#dg').datagrid('clearChecked');
        				}
        			}
        		});
        }
        function confirmFormal(){
        	var row = $('#dg').datagrid('getSelected');
        	var flag=0;
            if (row){
            	var arr = new Array();
        		var rows = $('#dg').datagrid("getSelections");
        		for(var i =0;i<rows.length;i++){
        			var rr=rows[i];
        			if(rr.status=="FORMAL"||rr.status=="USED"){
        				$.messager.alert('提示','选中的试卷中包含非毛坯的试卷!');
        				flag=6;
    					break;
        			}
        			if(rr.isSeparatePaperReturn != 1){
        				flag=999;
        				$.messager.alert("操作提示", "所选项中含网评卷未回库！","error");
        				break;
        			}
        			//是专卡
        			if(rr.isSpecialAnswerSheet==1){  //因为入库扫描涉及到试卷回库、所以这里不用判断试卷是否回库
        				if(rr.isAnswerSheetReturn==0){//专卡都没回库
        					flag=1;
        					break;
        				}else if(rr.isStorageScanned==0){//入库扫描没实现
        					flag=2;
        					break;
        				}else if(rr.isStandadAnswerReturn==0){//专卡的表达没回库
        					flag=3;
        					break;
        				}else{
        					arr.push(rr.id);
        				}
        			}else{
        				if(rr.isStorageScanned==0){//入库扫描没实现
        					flag=4;
        					break;
        				}else if(rr.isStandadAnswerReturn==0){//专卡的表达没回库
        					flag=5;
        					break;
        				}else{
        					arr.push(rr.id);
        				}
        			}
        		}
        		if(flag=="1"){
        			
        		}else if(flag=="2"||flag=="4"){
        			$.messager.alert("操作提示", "所选项中包含没有入库扫描试卷！","error");
        		}else if(flag=="3"||flag=="5"){
        			$.messager.confirm("操作提示", "所选项的有标答没回库,确定要做确认清样吗?", function (data) {
			            if (data) {
			            	var arr1 = new Array();
			            	for(var i =0;i<rows.length;i++){
			            		arr1.push(rows[i].id);
			            	}
			            	alert("确认清样： " + arr1);
			            	sendAjax(arr1);
			            }
			        });
        		}else if(flag=="0"){//所有均满足
        			sendAjax(arr);
        		}
        	}else{
        		$.messager.confirm("操作提示", "是否进行全部清样操作?", function (data) {
        			if (data) {
        				$(document).mask('正在处理该批次下所有确认清样，请稍等...');
        				var obj={
        	            		"batchId" : ${paperBatch.id},
        	            	};
        	            	var PaperParams=JSON.stringify(obj);
        	            	
        	            	$.ajax({
        	        			type : "POST",
        	        			url : "${ctx}/examPaper/formalAll",
        	        			data :  PaperParams ,
        	        			contentType : "application/json; charset=utf-8",
        	        			dataType : "json",
        	        			success : function(callback) {
        	        				$(document).unmask();
        	        				callback=eval(callback);
        	        				if(callback.type=="success"){
        	        					$.messager.alert("操作提示", "该批次下所有试卷确认清样完成！","info");
        	        					$('#dg').datagrid('reload');
        	        				}else{
        	        					$.messager.alert("操作提示", "确认清样失败！该批次下存在未入库扫描的试卷!","error");
        	        				}
        	        			}
        	        		});
        			}
        		});
        	}
        }
        
        function rejectFormal(){
        	var row = $('#dg').datagrid('getSelected');
        	var flag=true;
            if (row){
            	var arr = new Array();
        		var rows = $('#dg').datagrid("getSelections");
        		for(var i =0;i<rows.length;i++){
        			var rr=rows[i];
        			if(rr.status!="FORMAL"){
        				$.messager.alert('提示','选中的试卷中必须都为清样试卷才可以进行撤销清样操作!');
    					flag=false;
    					break;
        			}
        			        			
        			//是专卡
        			if(rr.isSpecialAnswerSheet==1){
        				if(rr.isStorageScanned!=0&&rr.isPaperReturn!=0&&rr.isAnswerSheetReturn!=0){
        					arr.push(rr.id);
        				}else{
        					$.messager.alert('提示','撤销清样的条件不满足');
        					flag=false;
        					break;
        				}
        			}else{
						if(rr.isStorageScanned!=0&&rr.isPaperReturn!=0){
							arr.push(rr.id);
        				}else{
        					$.messager.alert('提示','撤销清样的条件不满足');
        					flag=false;
        					break;
        				}
        			}
        		}
        		
        		
        		if(flag){
            		var obj={
                    		"batchId" : ${paperBatch.id},
                    		"array" : arr
                    	};
                    	var PaperParams=JSON.stringify(obj);
                    	
                    	$.ajax({
                			type : "POST",
                			url : "${ctx}/examPaper/rejectFormal",
                			data :  PaperParams ,
                			contentType : "application/json; charset=utf-8",
                			dataType : "json",
                			success : function(callback) {
                				callback=eval(callback);
                				if(callback.type=="success"){
                					$.messager.alert('提示','撤销清样完成');
                					$('#dg').datagrid('reload');
                					$('#dg').datagrid('clearChecked');
                				}
                			}
                		});
            	}
            }else{
        		$.messager.alert('提示','请选择一行进行撤销清样操作');
        	}
        }
        
        function removeFromBatch(){
        	var row = $('#dg1').datagrid('getSelected');
        	if (row){
        		var arr = new Array();
        		var rows = $('#dg1').datagrid("getSelections");
        		for(var i =0;i<rows.length;i++){
        			var index = $('#dg1').datagrid('getRowIndex',rows[i]);
        			var rr=$('#dg1').datagrid('getSelected',rows[i]);
        			$('#dg1').datagrid('deleteRow',index);
        			arr.push(rr.id);
        		}
  
            	var obj={
            		"batchId" : ${paperBatch.id},
            		"array" : arr
            	};
            	var PaperParams=JSON.stringify(obj);
            	
            	$.ajax({
        			type : "POST",
        			url : "${ctx}/examPaper/removeFromBatch",
        			data :  PaperParams ,
        			contentType : "application/json; charset=utf-8",
        			dataType : "json",
        			success : function(callback) {
        				callback=eval(callback);
        				if(callback.type=="success"){
        					$.messager.alert('提示','移出成功');
        					$('#dg1').datagrid('clearChecked');
        				}
        			}
        		});
            }
            else{
            	$.messager.alert('提示','请选择需要移出该批次的试卷');
            }
        }
        
        function addFormalPapers(){
        	window.location.href = "${ctx}/examPaper/batchPapers/addFormalPapers/3";
        }
        
        function confirmUsed(){
            var rows=$("#dg").datagrid("getSelections");
            for(var i=0;i<rows.length;i++){
                var rowIndex = $('#dg').datagrid('getRowIndex',rows[i]);
                $('#dg').datagrid('updateRow',{
                    index: rowIndex,
                    row: {status: '启用'}
                });
            }
        }
        function rejectUsed(){
            var rows=$("#dg").datagrid("getSelections");
            for(var i=0;i<rows.length;i++){
                var rowIndex = $('#dg').datagrid('getRowIndex',rows[i]);
                $('#dg').datagrid('updateRow',{
                    index: rowIndex,
                    row: {status: '清样库建设'}
                });
            }
        }
        
    </script>
</body>
</html>