<%@ 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>
    <style type="text/css">.sort {
        color: #0663A2;
        cursor: pointer;
    }

    .rejectWindow {
        width: 500px;
        min-height: 200px;
        background: #fff;

        padding-bottom: 30px;
        font-family: "微软雅黑", Fixedsys;
        border: #5d6d7d solid 1px;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -150px 0 0 -200px;
        text-align: center;
        z-index: 9999;
    }

    .rejectWindow .form-horizontal .control-label {
        width: 100px;
    }

    .rejectWindow .form-horizontal .controls {
        margin-left: 120px;
    }

    .task-header, .password-header {
        width: 100%;
        height: 46px;
        background: #5d6d7d;
        color: #fff;
        margin-bottom: 30px;
    }

    .task-content, .password-content {
        font-size: 18px;
        color: #005277;
        text-align: left;
        padding: 15px;
        line-height: 30px;
        word-wrap: break-word;
    }

    .image-close {
        margin-top: 15px;
        margin-right: 15px;
        cursor: pointer;
        float: right;
    }

    .title {
        font-size: 22px;
        font-weight: bold;
        color: #fff;
        margin: 0px;
        padding: 13px 0 0 13px;
        float: left;
    }

    .task-count, .password-value {
        width: 50px;
    }

    .btn-info {
        height: 25px;
        margin-left: 320px;
        margin-bottom: 20px;
    }

    .wrong, .passwordWrong {
        font-size: 12px;
        color: #f00;
        line-height: 30px;
        padding-left: 20px;
    }
    </style>
</head>
<body>
<ul class="nav nav-tabs">
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-mark')}">
        <li><a href="${ctx}/admin/exam/mark?subjectCode=${query.subjectCode}">评卷进度</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-group')}">
        <li><a href="${ctx}/admin/exam/group?subjectCode=${query.subjectCode}">分组管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-marker')}">
        <li><a href="${ctx}/admin/exam/marker?subjectCode=${query.subjectCode}">评卷员管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-trial')}">
        <li><a href="${ctx}/admin/exam/trial?subjectCode=${query.subjectCode}">试评管理</a></li>
    </c:if>
    <li class="active"><a href="##">任务管理</a></li>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-arbitrate')}">
        <li><a href="${ctx}/admin/exam/arbitrate?subjectCode=${query.subjectCode}">仲裁管理</a></li>
    </c:if>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-quality')}">
        <li><a href="${ctx}/admin/exam/quality?subjectCode=${query.subjectCode}">质量监控</a></li>
    </c:if>
</ul>
<form id="searchForm" action="${ctx}/admin/exam/library" 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" id="subject-select" name="subjectCode">
            <c:forEach items="${subjectList}" var="item">
                <option value="${item.code}"
                        <c:if test="${item.code==query.subjectCode}">selected</c:if>>${item.code}-${item.name}</option>
            </c:forEach>
        </select>
        <label>分组</label>
        <select class="input-medium" id="group-select" name="groupNumber">
            <option value="" <c:if test="${query.groupNumber==null}">selected</c:if>>不限</option>
            <c:forEach items="${groupList}" var="item">
                <option value="${item.number}"
                        <c:if test="${item.number==query.groupNumber}">selected</c:if>>${item.number}-${item.title}</option>
            </c:forEach>
        </select>
        <label>状态</label>
        <select class="input-small" id="status-select" name="status">
            <option value="">不限</option>
            <c:forEach items="${statusList}" var="item">
                <option value="${item.value}"
                        <c:if test="${item.value==status.value}">selected</c:if>>${item.name}</option>
            </c:forEach>
        </select>
        <span id="reasonSpan" <c:if test="${status.value!=2}">class="hide"</c:if>>
        <label>打回原因</label>
        <select class="input-small" id="reason-select" name="rejectReason">
            <option value="">不限</option>
            <option value="给分较高" <c:if test="${query.rejectReason=='给分较高'}">selected</c:if>>给分较高</option>
            <option value="给分较低" <c:if test="${query.rejectReason=='给分较低'}">selected</c:if>>给分较低</option>
            <option value="判分错误" <c:if test="${query.rejectReason=='判分错误'}">selected</c:if>>判分错误</option>
            <option value="其它" <c:if test="${query.rejectReason=='其它'}">selected</c:if>>其它</option>
        </select>
        </span>
        <label>评卷员</label>
        <select class="input-medium" id="marker-select" name="markerId">
            <option value="0">不限</option>
            <c:forEach items="${markerList}" var="item">
                <option value="${item.id}"
                        <c:if test="${item.id==query.markerId}">selected</c:if>>${item.loginName}</option>
            </c:forEach>
        </select>
        <br/><br/>
        <label>选做题</label>
        <select class="input-small" name="unselective">
            <option value="false" <c:if test="${!query.unselective}">selected</c:if>>不限</option>
            <option value="true" <c:if test="${query.unselective}">selected</c:if>>未选做</option>
        </select>

        <c:if test="${web_user.schoolAdmin==true || forbiddenScore==false}">
            <label>准考证号</label>
            <input type="text" name="examNumber" value="${query.examNumber}" maxlength="20" class="input-medium"
                    <c:if test="${(web_user.subjectHeader==true||web_user.schoolViewer==true) && forbiddenInfo==true}"> disabled="disabled"</c:if>/>
            &nbsp;
        </c:if>
        <label>密号</label>
        <input type="text" name="secretNumber" id="secretNumber" value="${query.secretNumber}" class="input-medium"/>
        &nbsp;
        <label>总分：从</label>
        <input type="number" id="startScore" name="startScore" value="${query.startScore}" class="input-mini"/>
        <label> 到&nbsp;&nbsp;&nbsp;</label>
        <input type="number" id="endScore" name="endScore" value="${query.endScore}" class="input-mini"/>
        <br/><br/>
        <label>小题得分</label>
        <input type="text" number="true" name="questionScore" id="questionScore" value="${query.questionScore }"
               class="input-mini"/>
        &nbsp;
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
        &nbsp;
        <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-library-inspect') && examType!='MULTI_MEDIA' && inspectedCount!=null && inspectedCount>0}">
            <a id="btnInspected" target="_blank"
               href="${ctx}/web/admin/exam/library/inspected/start?subjectCode=${query.subjectCode}&groupNumber=${query.groupNumber}&markerId=${query.markerId}&examNumber=${query.examNumber}&secretNumber=${query.secretNumber}&startScore=${query.startScore}&endScore=${query.endScore}&questionScore=${query.questionScore}&unselective=${query.unselective}"
               class="btn">待复核：${inspectedCount }</a>
        </c:if>
    </div>
</form>
<tags:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th>科目代码</th>
        <th>分组序号</th>
        <th>准考证号</th>
        <th>密号</th>
        <th>状态</th>
        <th>打回原因</th>
        <th>评卷员</th>
        <th>评卷总分</th>
        <th>给分明细</th>
        <th>评卷时间</th>
        <th>复核人</th>
        <th>复核时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${query.result}" var="result">
        <tr>
            <td>${result.subjectCode}</td>
            <td>${result.groupNumber}</td>
            <td>
                <c:if test="${web_user.subjectHeader==true && forbiddenInfo==true}">
                    ***
                </c:if>
                <c:if test="${web_user.schoolAdmin==true || forbiddenInfo==false}">
                    ${result.examNumber}
                </c:if>
            </td>
            <td>${result.secretNumber}</td>
            <td>${result.status.name}</td>
            <td><span title="${result.rejectReason}">
            	<c:if test="${result.rejectReason.length()>10}">${result.rejectReason.substring(0,10) }...</c:if>
            	<c:if test="${result.rejectReason.length()<=10}">${result.rejectReason}</c:if>
            	</span>
            </td>
            <td>${result.markerLoginName}</td>
            <td>
                <c:if test="${result.markerScore!=null}">
                    <c:if test="${result.markerScore==-1}">未选做</c:if>
                    <c:if test="${result.markerScore!=-1}"><fmt:formatNumber pattern="###.###"
                                                                             value="${result.markerScore}"/></c:if>
                </c:if>
                <c:if test="${result.markerScore==null}">
                    &nbsp;
                </c:if>
            </td>
            <td>
                <c:if test="${result.markerScoreList!=null}">
                    ${result.markerScoreList}
                </c:if>
                <c:if test="${result.markerScoreList==null}">
                    &nbsp;
                </c:if>
            </td>
            <td>
                <c:if test="${result.markerTime!=null}">
                    <fmt:formatDate value="${result.markerTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </c:if>
                <c:if test="${result.markerTime==null}">
                    &nbsp;
                </c:if>
            </td>
            <td> ${result.headerLoginName} </td>
            <td>
                <c:if test="${result.headerLoginName!=null && result.headerTime!=null}">
                    <fmt:formatDate value="${result.headerTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </c:if>
            </td>
            <td>
                <c:if test="${result.status.value==1 || result.status.value==3 ||result.status.value==5 ||result.status.value==6}">
                    <%--  <c:if test="${examType=='MULTI_MEDIA'}">
                         <a class="json-link" href="${ctx}/admin/exam/library/getJson?studentId=${result.studentId}&groupNumber=${result.groupNumber}" target="_blank">原图</a>
                     </c:if>
                     <c:if test="${examType!='MULTI_MEDIA'}"> --%>
                    <a href="${ctx}/web/admin/exam/track/library?libraryId=${result.id}&subjectCode=${result.subjectCode}"
                       target="_blank">查看</a>
                    <%--  </c:if> --%>
                </c:if>
                <c:if test="${result.status.value==1 || result.status.value==5 ||result.status.value==6}">
                    &nbsp;
                    <a href="##" data-id="${result.id}" class="back-link">打回</a>
                </c:if>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="rejectWindow" style="display:none">
    <div class="task-header">
        <p class="title">打回</p>
        <p class="image-close"><img src="${ctxStatic}/mark-new/images/images-close.png"/></p></div>
    <input id="rejectId" type="hidden"/>
    <form class="form-horizontal">
        <div class="control-group">
            <label class="control-label"><span
                    style="color:red;font-size:16px;margin-right:3px">*</span>打回原因</label>
            <div class="controls">
                <select id="rejectReasonSelect" name="rejectReasonSelect">
                    <option value='给分较高'>给分较高</option>
                    <option value='给分较低'>给分较低</option>
                    <option value='判分错误'>判分错误</option>
                    <option value='其它'>其它</option>
                </select>
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">详情描述</label>
            <div class="controls">
                <textarea rows="3" id="rejectReasonInput" maxlength="60"></textarea>
            </div>
        </div>
        <div style="text-align:center;">
            <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-library-reject')}">
                <a class="btn btn-primary task-btn">打回</a>
            </c:if>
            &nbsp;
            <a class="btn task-cancel">取消</a>
        </div>
    </form>
</div>
<div class="pagination">${query}</div>
<%@include file="/WEB-INF/views/include/trackView.jsp" %>
<script type="text/javascript">
    $('#subject-select').change(function () {
        var code = $(this).val();
        $('#group-select').empty();
        if (code == '') {
            $('#group-select').val('').trigger('change');
            return;
        }
        $.post('${ctx}/admin/exam/group/query', {subjectCode: code, status: 'FORMAL'}, function (result) {
            var parent = $('#group-select');
            var first = '';
            $('<option value="">不限</option>').appendTo(parent);
            for (var i = 0; i < result.length; i++) {
                var group = result[i];
                $('<option value="' + group.number + '">' + group.number + '-' + group.title + '</option>').appendTo(parent);
                /* if (i == 0) {
                    first = group.number;
                } */
            }
            parent.val(first).trigger('change');
        });
    });
    $('#group-select').change(function () {
        var subjectCode = $('#subject-select').val();
        var groupNumber = $('#group-select').val();
        $('#marker-select').empty();
        $('#marker-select').append('<option value="0">不限</option>');
        $('#marker-select').val('0').trigger('change');
        if (subjectCode == '') {
            return;
        }
        if (groupNumber == '') {
            return;
        }
        $.post('${ctx}/admin/exam/marker/query', {
            subjectCode: subjectCode,
            groupNumber: groupNumber
        }, function (result) {
            var parent = $('#marker-select');
            var first = '';
            for (var i = 0; i < result.length; i++) {
                var marker = result[i];
                $('<option value="' + marker.id + '">' + marker.loginName + '</option>').appendTo(parent);
                if (i == 0) {
                    first = marker.id;
                }
            }
            //parent.val(first).trigger('change');
        });
    });

    $('#status-select').change(function () {
        var status = $(this).val();
        if (status == 2) {
            $('#reasonSpan').show();
        } else {
            $('#reasonSpan').hide();
        }
    });

    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        var startScore = $("#startScore").val();
        var endScore = $("#endScore").val();
        if (startScore.length > 0) {
            if (endScore.length == 0) {
                alert("请输入结束分数值！");
                return false;
            }
        }
        if (endScore.length > 0) {
            if (startScore.length == 0) {
                alert("请输入开始分数值！");
                return false;
            }
        }
        if (endScore.length > 0 && startScore.length > 0) {
            if (parseInt(startScore) > parseInt(endScore)) {
                alert("开始分值必须小于结束分值");
                return false;
            }
        }
        $("#pageNumber").val(1);
        $("#searchForm").submit();
        return false;
    }

    $('#btnInspected').click(function () {
        var groupNumber = '${query.groupNumber}';
        if (groupNumber == null || groupNumber == '') {
            alert("请选择分组查询后再开始复核");
            return false;
        }
    });
    $('.back-link').click(function () {
        $('#rejectReasonInput').attr("value", "");
        $('#rejectId').attr("value", $(this).attr('data-id'));
        $('.rejectWindow').show();
    });
    $('.image-close').click(function () {
        $('.rejectWindow').hide();
    });
    $('.task-cancel').click(function () {
        $('.rejectWindow').hide();
    });
    $('.task-btn').click(function () {
        var rejectReason = $("#rejectReasonSelect").val();
        var rejectReasonInput = $('#rejectReasonInput').val();
        var rejectId = $("#rejectId").val();
        if (rejectReason == "" || rejectReason == undefined) {
            alert("请选择打回原因");
            return false;
        }
        if (rejectReasonInput != "" && rejectReasonInput != null) {
            rejectReason = rejectReason + ":" + rejectReasonInput;
        }
        $.ajax({
            url: "${ctx}/admin/exam/library/reject",
            data: {id: rejectId, reason: rejectReason},
            traditional: true,
            type: "post",
            success: function (result) {
                if (result.success == true) {
                    alert('打回成功');
                    $("#searchForm").submit();
                } else {
                    alert(result.message);
                }
                $('.rejectWindow').hide();
            }
        });
    });
</script>
</body>
</html>
