<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>成绩复核</title>
    <meta name="decorator" content="default"/>
    <%@include file="/WEB-INF/views/include/head.jsp" %>
    <style type="text/css">.sort {
        color: #0663A2;
        cursor: pointer;
    }</style>
</head>
<body>
<div id="importBox" class="hide">
    <form id="importForm" action="${ctx}/admin/exam/inspected/import" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input id="uploadFile" name="file" type="file" style="width:330px"/><br/><br/>　　
        <input id="btnImportSubmit" class="btn btn-primary" type="submit" value="   导    入   "/>
        <a href="${ctx}/admin/exam/inspected/import/template">下载模板</a>
    </form>
</div>
<ul class="nav nav-tabs">
<c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_inspected_info-info')}">
        <li><a href="${ctx}/admin/exam/inspected/info">成绩复核进度</a></li>
        </c:if>
        <li class="active"><a href="##">全卷复核</a></li>
        <c:if test="${examFinish && fnx:hasPrivilegeCode(role_privilege_codes, 'exam_inspected_info-score_verify')}">
        <li><a href="${ctx}/admin/exam/score/verify/init">成绩校验</a></li>
        </c:if>
</ul>
<form id="searchForm" action="${ctx}/admin/exam/inspected/list" method="post" class="breadcrumb form-search" >
    <input type="hidden" id="pageNumber" name="pageNumber" value="${query.pageNumber }"/>
    <input type="hidden" id="pageSize" name="pageSize" value="${query.pageSize }"/>
    <div>
        <label>科目</label>
        <select class="input-large" name="subjectCode" id="subject-select">
            <option value="">请选择</option>
            <c:forEach items="${subjectList}" var="subject">
                <option value="${subject.code}" <c:if test="${subject.code==query.subjectCode}">selected</c:if>>${subject.code}-${subject.name}</option>
            </c:forEach>
        </select>
         &nbsp;
        <label>选做科目</label>
			<select class="input-small" name="selective">
				<option value="" <c:if test="${null==query.selective}">selected</c:if>>不限</option>
				<option value="1" <c:if test="${query.selective!=null &&query.selective}">selected</c:if>>是</option>
				<option value="0" <c:if test="${query.selective!=null &&!query.selective}">selected</c:if>>否</option>
			</select>
        &nbsp;
        <%-- <label>状态</label>
        <select class="input-small" name="inspected">
				<option value="" <c:if test="${null==query.inspected}">selected</c:if>>请选择</option>
				<option value="1" <c:if test="${query.inspected!=null &&query.inspected}">selected</c:if>>已复核</option>
				<option value="0" <c:if test="${query.inspected!=null &&!query.inspected}">selected</c:if>>未复核</option>
			</select>
         &nbsp; --%>
        <label>试卷总分：从</label>
        <input type="text" number="true" id="startScore" name="startScore" value="${query.startScore}" class="input-mini"/>
        <label> 到&nbsp;&nbsp;&nbsp;</label>
        <input type="text" number="true" id="endScore" name="endScore" value="${query.endScore}" class="input-mini"/>
        &nbsp;
        <label>选做题</label>
            <select class="input-small"  name="selectiveStatus" id="selectiveStatus">
	            <option value="">请选择</option>
	            <c:forEach items="${selectiveStatusList}" var="result">
                <option value="${result.value}" <c:if test="${result==selectiveStatus}">selected</c:if>>${result.name}</option>
            	</c:forEach>
            </select>
        <label>打回卷</label>
        <select class="input-small" name="rejected">
				<option value="" <c:if test="${null==query.rejected}">selected</c:if>>请选择</option>
				<option value="1" <c:if test="${query.rejected!=null &&query.rejected}">selected</c:if>>是</option>
				<option value="0" <c:if test="${query.rejected!=null &&!query.rejected}">selected</c:if>>否</option>
			</select>
        <br/><br/>
		<label>大题</label>
        <select class="input-medium" id="question-select" name="mainNumber">
            <option value="">请选择</option>
            <c:forEach items="${questionList}" var="result">
                <option value="${result.mainNumber}" <c:if test="${result.mainNumber==mainNumber}">selected</c:if>>${result.mainNumber}-${result.mainTitle}</option>
            </c:forEach>
        </select>

        <label>大题得分：从</label>
        <input type="text" number="true" name="mainStartScore" id="mainStartScore" value="${mainStartScore }" class="input-mini"/>
        <label> 到&nbsp;&nbsp;&nbsp;</label>
        <input type="text" number="true" id="mainEndScore" name="mainEndScore" value="${mainEndScore }" class="input-mini"/>
        
        <label>小题得分</label>
        <input type="text" number="true" name="questionScore" id="questionScore" value="${query.questionScore }" class="input-mini"/>
		<span id="questionScoreEmptySpan" hidden="true">
			<select class="input-small" id="questionScoreEmpty" name="questionScoreEmpty">
				<option value="" <c:if test="${null==query.questionScoreEmpty}">selected</c:if>>请选择</option>
				<option value="1" <c:if test="${query.questionScoreEmpty!=null &&query.questionScoreEmpty}">selected</c:if>>空</option>
				<option value="0" <c:if test="${query.questionScoreEmpty!=null &&!query.questionScoreEmpty}">selected</c:if>>0</option>
			</select>
		</span>	
        <label>密号</label>
        <input type="text" name="secretNumber" id="secretNumber" value="${query.secretNumber}" class="input-medium"/>
        &nbsp;
         <label>确认人</label>
        <input type="text" name="inspectorName" id="inspectorName" value="${query.inspectorName}" class="input-medium"/>
        
         &nbsp; 
        <br/><br/>
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
        <c:if test="${inspectCount>0}">
        &nbsp;
        <input id="btnStart" class="btn" type="button" value="批量确认:${inspectCount }" onclick="goStart()"/>
        </c:if>
        &nbsp;
        <%-- <c:if test="${!empty showNextInspect &&fnx:hasPrivilegeCode(role_privilege_codes, 'exam_inspected_info-next_round')}">
        <input id="btnNextRound" class="btn" type="button" value="再次复核" onclick="nextRound()"/>
        &nbsp;
        </c:if>
         <input id="btnCancel" class="btn" type="button" value="取消复核" onclick="goCancel()"/>
          &nbsp; --%>
        <c:if test="${exam.status=='FINISH' && web_user.schoolAdmin==true}">
       	<input id="btnImport" class="btn" type="button" value="导入"/>
       	&nbsp;
       	</c:if>
       	<div class="btn-group">
                <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                    导出<span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="##" id="listBtnExport">确认列表</a></li>
                    <li><a href="##" id="workBtnExport">工作量</a></li>
                </ul>
                </div>
    </div>
</form>
<tags:message content="${message}"/>
<form id="cancelForm" action="${ctx}/admin/exam/inspected/batchCancel" method="post" class="breadcrumb form-search"  style="overflow-x: auto;">
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th><input type="checkbox" id="ids">科目</th>
        <th>密号</th>
        <th>客观分</th>
        <th>主观分</th>
        <th>试卷总分</th>
        <th>客观明细</th>
        <th>得分明细</th>
        <th>操作</th>
        <c:forEach begin="1" end="${maxInspectRound}" step="1" varStatus="status">
        <th>确认人${status.index}</th>
        <th>确认时间${status.index}</th>
        </c:forEach>
        
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${query.result}" var="result">
        <tr>
            <td><input type="checkbox" class="ids" name="ids" value="${result.id}">${result.subjectCode}-${result.subjectName}</td>
            <td>${result.secretNumber}</td>
            <td>${result.objectiveScoreString}</td>
            <td>${result.subjectiveScoreString}</td>
            <td><fmt:formatNumber pattern="###.###" value="${result.totalScore}"/></td>
            <td>${result.objectiveScoreList}</td>
            <td>${result.subjectiveScoreList}</td>
            <td>
            	 <a href="${ctx}/web/admin/exam/track/student?studentId=${result.id}&subjectCode=${result.subjectCode}" target="_blank">轨迹图</a>
                <%-- <c:if test="${result.subjectiveStatus=='MARKED'&&!result.inspected}"> --%>
	                <a target="_blank" href="${ctx}/web/admin/exam/inspected/start?studentId=${result.id}&subjectCode=${result.subjectCode}">进入确认</a>
                <%-- </c:if> --%>
                <%-- <c:if test="${result.inspected}">
                <a class="cancel-link" href="#" data-id="${result.id}">取消复核</a>
                </c:if> --%>
            </td>
            <c:if test="${!empty result.inspectHistoryMap}">
	            <c:forEach begin="1" end="${maxInspectRound}" step="1" varStatus="status">
	            	<c:set var="inspectHistory" value="${result.inspectHistoryMap.get(fn:trim(status.index))}" />
	            	<c:if test="${!empty inspectHistory}">
	            		<td> ${inspectHistory.inspectorName} </td>
	            		<td>
			            	<c:if test="${inspectHistory.inspectTime!=null}">
			                    <fmt:formatDate value="${inspectHistory.inspectTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
			                </c:if>
			                <c:if test="${inspectHistory.inspectTime==null}">
			                    &nbsp;
			                </c:if>
			            </td>
	            	</c:if>
	            	<c:if test="${empty inspectHistory}">
	            		<td></td>
             			<td></td>
	            	</c:if>
	            </c:forEach>
            </c:if>
            <c:if test="${empty result.inspectHistoryMap}">
	            <c:forEach begin="1" end="${maxInspectRound}" step="1" varStatus="status">
	            	<td></td>
             		<td></td>
	            </c:forEach>
            </c:if>
            
        </tr>
    </c:forEach>
    </tbody>
</table>
</form>
<div class="pagination">${query}</div>
<%@include file="/WEB-INF/views/include/trackView.jsp" %>
<script type="text/javascript">
    $(document).ready(function () {
        /* new jBox('Image', {
            imageFade: 0,
            delayOpen: 0,
            delayClose: 0,
            maxHeight: $(window).height()*0.88
        }); */
    	/* var s=localStorage.getItem("inspectQuery");
    	if(s!="" && s!=null && s!=undefined){
    		var inspectQuery = JSON.parse(s);
    		var pageN =1;
    		var pageS =20;
    		 for (var i = 0; i < inspectQuery.length; i++) {
    			var value = inspectQuery[i].value;
    			if(value!="" && value!=null && value!=undefined){
	    			var name = inspectQuery[i].name;
    				$('[name='+name+']').attr('value',value);
    				if(name=='pageNumber'){
    					pageN = value;
    				}
    				if(name=='pageSize'){
    					pageS = value;
    				}
    			} 
    		};
    		localStorage.setItem("inspectQuery","");
    		page(pageN, pageS);
    	} */
        $("#searchForm").validate();
        $('.cancel-link').click(function () {
            if (!confirm('确定要取消复核吗?')) {
                return;
            }
           // localStorage.setItem("inspectQuery", JSON.stringify($("#searchForm").serializeArray()));
            $.post('${ctx}/admin/exam/inspected/cancel', {studentId: $(this).attr('data-id')}, function (result) {
            	if(typeof result.success === 'undefined'){
            		alert("权限失效，请重新登录！");
                    window.location.href = "/login";
                    return;
            	}
                if (result.success == true) {
                    alert('取消成功');
                    $('[name="subjectCode"]').attr('value',result.subjectCode);
                    $("#searchForm").submit();
                } else {
                    alert(result.message);
                }
            });
        });
        $('.track-link').click(function () {
            initTrackPopover($(this).attr('data-title'), $(this).attr('data-image-url'));
            return false;
        });
        $('#subject-select').change(function () {
            var code = $(this).val();
            $('#question-select').empty();
            if (code == '') {
                $('#question-select').val('').trigger('change');
                return;
            }
            $('#question-select').append('<option value="">不限</option>');
            $.post('${ctx}/admin/exam/paper/question/query', {subjectCode: code, status: 'FORMAL'}, function (result) {
                var parent = $('#question-select');
                var first = '';
                for (var i = 0; i < result.length; i++) {
                    var question = result[i];
                    $('<option value="' + question.mainNumber + '">' + question.mainNumber + '-' + question.mainTitle + '</option>').appendTo(parent);
                    if (i == 0) {
                        first = question.mainNumber;
                    }
                }
                parent.val(first).trigger('change');
            });
        });
        
        $("#btnImport").click(function () {
            $.jBox($("#importBox").html(), {
                title: "导入数据", buttons: {"关闭": true},
                bottomText: "导入文件不能超过1000行，仅允许导入“xls”或“xlsx”格式文件！"
            });
        });
        $("#questionScore").trigger('change');
    });

    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").attr('target', "_self");
        $("#searchForm").attr('action', '${ctx}/admin/exam/inspected/list');
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#pageSize").val('${query.pageSize}');
        $("#searchForm").attr('target', "_self");
        $("#searchForm").attr('action', '${ctx}/admin/exam/inspected/list');
        $("#searchForm").submit();
        return false;
    }
    function goStart() {
    	var url = '${ctx}/web/admin/exam/inspected/start?';
    	var subjectCode =  $("#subject-select").val();
    	if(subjectCode==undefined || subjectCode==""){
    		 alert('请选择科目');
    		 return;
    	}
		url = url+'subjectCode='+subjectCode
    	var startScore =  $("#startScore").val();
    	if(startScore!=undefined && startScore!=""){
    		url = url+'&startScore='+startScore;
    	}
    	var endScore =  $("#endScore").val();
    	if(endScore!=undefined && endScore!=""){
    		url = url+'&endScore='+endScore;
    	}
    	var mainNumber =  $("#question-select").val();
    	if(mainNumber!=undefined && mainNumber!=""){
    		url = url+'&mainNumber='+mainNumber;
    	}
    	var mainStartScore =  $("#mainStartScore").val();
    	if(mainStartScore!=undefined && mainStartScore!=""){
    		url = url+'&mainStartScore='+mainStartScore;
    	}
    	var mainEndScore =  $("#mainEndScore").val();
    	if(mainEndScore!=undefined && mainEndScore!=""){
    		url = url+'&mainEndScore='+mainEndScore;
    	}
    	var questionScore =  $("#questionScore").val();
    	if(questionScore!=undefined && questionScore!=""){
    		url = url+'&questionScore='+questionScore;
    	}
    	var selectiveStatus =  $("#selectiveStatus").val();
    	if(selectiveStatus!=undefined && selectiveStatus!=""){
    		url = url+'&selectiveStatus='+selectiveStatus;
    	}
    	var secretNumber =  $("#secretNumber").val();
    	if(secretNumber!=undefined && secretNumber!=""){
    		url = url+'&secretNumber='+secretNumber;
    	}
    	window.open(url, '_blank');
        return false;
    }
    
    $("#ids").change(function () {
        if ($("#ids").is(':checked')) {
            $(".ids").attr("checked", true);
        } else {
        	$(".ids").attr("checked", false);
        }
    });
    $("#questionScore").change(function () {
    	var scoreStr=$("#questionScore").val();
    	if(!scoreStr){
    		$("#questionScoreEmpty").val('').trigger('change');
    		$("#questionScoreEmptySpan").hide();
    	}else{
    		var scoreNum= parseFloat(scoreStr);
    		if(scoreNum==0){
    			$("#questionScoreEmptySpan").show();
    		}else{
    			$("#questionScoreEmpty").val('').trigger('change');
        		$("#questionScoreEmptySpan").hide();
    		}
    	}
    });
    
    $(".ids").change(function () {
    	var all = true;
    	$("input[name='ids']").each(function(){
    		if(!$(this).is(':checked')){
    			all = false;
    		}
    	})
		 $("#ids").attr("checked", all);
    });
    function goCancel() {
    	var check_list = []
    	$("input[name='ids']:checked").each(function(){
    		check_list.push($(this).val())
    	})
        if(check_list.length==0) {
            alert('请选择');
            return false;
        }
    	//localStorage.setItem("inspectQuery", JSON.stringify($("#searchForm").serializeArray()));
        $("#cancelForm").submit();
        return false;
    }
    function nextRound() {
    	var subjectCode =  $("#subject-select").val();
    	if(subjectCode==undefined || subjectCode==""){
    		 alert('请选择科目');
    		 return;
    	}
    	if (!confirm('系统将生成新的复核任务，是否确认？')) {
            return;
        }
    	
        $("#cancelForm").attr('target', "_self");
        $("#cancelForm").attr('action', '${ctx}/admin/exam/inspected/nextround?subjectCode='+subjectCode);
        $("#cancelForm").submit();
        return false;
    }
    $("#listBtnExport").click(function () {
    	$("#searchForm").attr("action", "${ctx}/admin/exam/inspected/list/export");
        $("#searchForm").submit();
    });
    $("#workBtnExport").click(function () {
    	$("#searchForm").attr("action", "${ctx}/admin/exam/inspected/work/export");
        $("#searchForm").submit();
    });
</script>
</body>
</html>