<%@ 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/main.css" type="text/css" />
<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/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/papers/batchPaper.js"></script>

<%@ include file="../common/validation.jsp"%>
<title>批次管理</title>

<script language="javascript">
    $(function(){
         $('#revocationBtnW3').on('click',function(){
                if(confirm("确定撤销最近一次入库操作吗?")){
                    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('提示','撤销入库成功');
                                }else{
                                    $.messager.alert('提示','撤销入库失败');
                                }
                                
                            }
                        });
                    }
                }
            });
         
         $('#revocationBtnW4').on('click',function(){
                if(confirm("确定撤销最近一次出库操作吗?")){
                    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('提示','撤销出库成功');
                                }else{
                                    $.messager.alert('提示','撤销出库失败');
                                }
                                
                            }
                        });
                    }
                }
            });
        
        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,
            upload_progress_handler : uploadProgress,
            upload_error_handler : uploadError,
            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<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 uploadDBFSuccess(file, serverData){
             if(serverData!="success"){
                 $.messager.alert('提示',serverData);
                 $(document).unmask();
             }else{
                 $.messager.alert('提示','导入成功!');
                 $(document).unmask();
                 $('#w').window('close');
                    $('#dg').datagrid('reload');
             }
         }
    });
    
    function removePaperFromPapersDG(datagridId, batchId){
        var selectedRows = $('#' + datagridId).datagrid('getSelections');
        if(selectedRows.length < 1){
            $.messager.alert('提示','请选中一行或多行记录！');
        }else{
            var relatedPaperIds = [];
            for(var i = 0; i < selectedRows.length; i++){
                relatedPaperIds.push(selectedRows[i].id);
            }
            
            $.ajax({
                type : "POST",
                url : "${ctx}/examPaper/removePapersFromBatch",
                data : {paperBatchId: batchId, relatedPaperIds : relatedPaperIds},
                dataType : "json",
                success: function(){
                    $(document).unmask();
                    $.messager.alert('提示','操作成功！');
                    $('#' + datagridId).datagrid('reload');
                    $('#' + datagridId).datagrid('clearChecked');
                }
            });
        }
    }
</script>

</head>
<body>
    <%@ include file="../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../common/sub_menu.jsp"%>
        <div class="page" id="page" >
	        <div class="page-header" >批次管理</div>
	        <div class="page-body">
	
	            <table class="searchTable">
	               <tr>
	                   <th>批次代码：</th>
	                   <td>${paperBatch.code}</td>
	                   <th>批次类型：</th>
	                   <td>${paperBatch.type}</td>
	                   <th>开始日期：</th>
	                   <td><fmt:formatDate value="${paperBatch.startDate}" pattern="yyyy-MM-dd" /></td>
	                   <th>结束日期：</th>
	                   <td><fmt:formatDate value="${paperBatch.endDate}" pattern="yyyy-MM-dd" /></td>
	               </tr>
	               <tr>
	                   <th>负责人：</th>
	                   <td>${paperBatch.admin}</td>
	                   <th>备注：</th>
	                   <td colspan="5">${paperBatch.remark}</td>
	               </tr>
	           </table>
	           
	        </div>
        </div>
     </div>
</body>
</html>