<%@ 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>
<ul class="nav nav-tabs">
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-mark')}">
        <li><a href="${ctx}/admin/exam/mark?subjectCode=${subject.code}">评卷进度</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>
    <li class="active"><a href="##">试评管理</a></li>
    <c:if test="${fnx:hasPrivilegeCode(role_privilege_codes, 'exam_mark-library')}">
        <li><a href="${ctx}/admin/exam/library?subjectCode=${query.subjectCode}">任务管理</a></li>
    </c:if>
    <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/trial/marker" 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-medium" id="marker-select" name="id">
            <option value="">不限</option>
            <c:forEach items="${markerList}" var="item">
                <option value="${item.id}"
                        <c:if test="${item.id==query.id}">selected</c:if>>${item.loginName}</option>
            </c:forEach>
        </select>
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>

    </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>
        <c:forEach items="${questionList}" var="question">
        <th>${question.mainNumber}-${question.subNumber}明细</th>
        <th>${question.mainNumber}-${question.subNumber}平均分</th>
        </c:forEach>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${result}" var="marker">
        <tr>
            <td>${marker.loginName}</td>
            <td>${marker.groupNumber}-${marker.groupTitle}</td>
            <td>${marker.trialCount}</td>
            <td>${marker.avgScore}</td>
            <c:forEach items="${marker.questionList}" var="q">
            <td>${q.scoreList}</td>
            <td>${q.avgScore}</td>
            </c:forEach>
        </tr>
    </c:forEach>
    </tbody>
</table>
<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: 'TRIAL'}, function (result) {
            debugger;
            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="">不限</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');
        });
    });

    function goSearch() {
        var subjectCode = $('#subject-select').val();
        var groupNumber = $('#group-select').val();
        if(subjectCode==''||groupNumber=='') {
            alert('请选择对应的科目及分组');
            return false;
        }
        $("#searchForm").submit();
        return false;
    }
</script>
</body>
</html>