<%@ 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>
	<script src="${ctxStatic}/echarts/echarts.min.js" type="text/javascript"></script>
</head>
<body>
<div id="objImportBox" class="hide">
    <form id="objImportForm" action="${ctx}/admin/exam/paper/import" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input name="objective" type="hidden" value="true"/>
        <input name="file" type="file" style="width:330px"/><br/><br/>　　
        <input class="btn btn-primary" type="submit" value="导入" onclick="goObjImport()"/>
        <a href="${ctx}/admin/exam/paper/template?objective=true">下载模板</a>
    </form>
</div>
<div id="subImportBox" class="hide">
    <form id="subImportForm" action="${ctx}/admin/exam/paper/import" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input name="objective" type="hidden" value="false"/>
        <input name="file" type="file" style="width:330px"/><br/><br/>　　
        <input class="btn btn-primary" type="submit" value="导入" onclick="goSubImport()"/>
        <a href="${ctx}/admin/exam/paper/template?objective=false">下载模板</a>
    </form>
</div>
<div id="groupImportBox" class="hide">
    <form id="groupImportForm" action="${ctx}/admin/exam/paper/importGroup" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input name="objective" type="hidden" value="false"/>
        <input name="file" type="file" style="width:330px"/><br/><br/>　　
        <input class="btn btn-primary" type="submit" value="导入" onclick="goGroupImport()"/>
        <a href="${ctx}/admin/exam/paper/template?objective=false">下载模板</a>
    </form>
</div>
<div id="dataImportBox" class="hide">
    <form id="dataImportForm" action="${ctx}/admin/exam/paper/importData" method="post" enctype="multipart/form-data"
          style="padding-left:20px;text-align:center;" class="form-search" onsubmit="loading('正在导入，请稍等...');"><br/>
        <input name="objective" type="hidden" value="false"/>
        <input name="file" type="file" style="width:330px"/><br/><br/>　　
        <input class="btn btn-primary" type="submit" value="导入" onclick="goDataImport()"/>
    </form>
</div>
<%-- <%@include file="/WEB-INF/views/include/examInfoNavTabs.jsp" %> --%>

<div id="main" style="width: 600px;height:300px;"></div>
<form id="searchForm" action="${ctx}/admin/exam/paper" 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="code" id="subject-select">
            <option value="">请选择</option>
            <c:forEach items="${subjectList}" var="subject">
                <option value="${subject.code}" data-level="${subject.level}" <c:if test="${subject.code==query.code}">selected</c:if>>${subject.code}-${subject.name}</option>
            </c:forEach>
        </select>
        <label>层次</label>
        <select class="input-small" name="level" id="level-select">
            <option value="">请选择</option>
            <c:forEach items="${levelList}" var="level">
                <option value="${level}" data-level="${level}" <c:if test="${level==query.level}">selected</c:if>>${level}</option>
            </c:forEach>
        </select>
        <label>选做科目</label>
        <select class="input-small" name="selective" id="selective-select">
            <option value="" <c:if test="${query.selective==null}">selected</c:if>>不限</option>
            <option value="true" <c:if test="${query.selective!=null && query.selective}">selected</c:if>>是</option>
            <option value="false" <c:if test="${query.selective!=null && !query.selective}">selected</c:if>>否</option>
        </select>
        <label>专业类型</label>
        <select class="input-small" name="category" id="category-select">
            <option value="">请选择</option>
            <c:forEach items="${categoryList}" var="category">
                <option value="${category}" <c:if test="${category==query.category}">selected</c:if>>${category}</option>
            </c:forEach>
        </select>
        &nbsp;
        <label>状态</label>
        <select class="input-small" name="upload">
            <option value="">不限</option>
            <option value="1" <c:if test="${upload!=null && upload==true}">selected</c:if>>已扫描</option>
            <option value="0" <c:if test="${upload!=null && upload==false}">selected</c:if>>未扫描</option>
        </select>
        &nbsp;
        <label>总分</label>
        <input type="number" name="totalScore" value="${query.totalScore}" maxlength="10" class="input-mini"/>
        <br/><br/>
        &nbsp;
        <input id="btnSubmit" class="btn btn-primary" type="button" value="查询" onclick="goSearch()"/>
        <c:if test="${web_user.schoolAdmin==true}">
            &nbsp;
            <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="obj-import">客观题</a></li>
                    <li><a href="##" id="sub-import">主观题结构</a></li>
                    <li><a href="##" id="group-import">主观题分组</a></li>
                </ul>
            </div>
        </c:if>
        &nbsp;
        <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="${ctx}/admin/exam/paper/export?objective=true">客观题</a></li>
                <li><a href="${ctx}/admin/exam/paper/export?objective=false">主观题</a></li>
            </ul>
        </div>
        <c:if test="${!examLock}">
            &nbsp;
            <a href="${ctx}/admin/exam/paper/calculate" class="btn">客观题统分</a>
            &nbsp;
            <a href="${ctx}/admin/exam/paper/report" class="btn">分析计算</a>
        </c:if>
        <c:if test="${examLock}">&nbsp;
            <a href="#" class="btn" disabled="disabled">正在计算</a>
        </c:if>
        &nbsp;
        <input id="data-import" class="btn" type="button" value="导入数据包"/>
    </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="subject">
        <tr>
            <td>
                <a href="${ctx}/admin/exam/paper/detail?subjectCode=${subject.code}&pageNumber=${query.pageNumber}&code=${query.code }&category=${ query.category}&level=${query.level }&upload=${ upload}&totalScoreNotEqual=${  query.totalScoreNotEqual}">
                ${subject.code}-${subject.name}&nbsp;${subject.remark}</a>
            </td>
            <td>${subject.level}</td>
            <td>${subject.category}</td>
            <td>
            	<c:if test="${subject.selective}">是</c:if>
            </td>
            <td>
                <c:if test="${subject.paperUrl != null && examType!='MULTI_MEDIA'}">
                    <a href="${fileServer}${subject.paperUrl}" target="_blank">已上传</a>
                </c:if>
            </td>
            <td>
                <c:if test="${subject.answerUrl != null && examType!='MULTI_MEDIA'}">
                    <a href="${fileServer}${subject.answerUrl}" target="_blank">已上传</a>
                </c:if>
            </td>
            <td>
                ${subject.paperType}
            </td>
            <td>
                <c:if test="${subject.cardType == 'JSON'}">电子题卡</c:if>
                <c:if test="${subject.cardType == 'ZIP'}">扫描题卡</c:if>
            </td>
            <td><fmt:formatNumber pattern="###.###" value="${subject.objectiveScore}"/></td>
            <td><fmt:formatNumber pattern="###.###" value="${subject.subjectiveScore}"/></td>
            <td><fmt:formatNumber pattern="###.###" value="${subject.totalScore}"/></td>
            <td>
                <c:if test="${examLock || subject.locked}">正在计算</c:if>
                <c:if test="${!examLock && !subject.locked}">正常</c:if>
            </td>
            <td>
                <c:if test="${!examLock && !subject.locked}">
                    <a href="${ctx}/admin/exam/subject/edit?code=${subject.code}&pageNumber=${query.pageNumber}&queryCode=${query.code }&category=${ query.category}&level=${query.level }&upload=${ upload}&totalScoreNotEqual=${query.totalScoreNotEqual}">编辑</a>
                    <a href="${ctx}/admin/exam/paper/report?subjectCode=${subject.code}">分析计算</a>
                </c:if>
                <a href="${ctx}/admin/exam/selectiveGroup?subjectCode=${subject.code}">设置选做题</a>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div class="pagination">${query}</div>
<script type="text/javascript">
    function page(n, s) {
        $("#pageNumber").val(n);
        $("#pageSize").val(s);
        $("#searchForm").submit();
        return false;
    }

    function goSearch() {
        $("#pageNumber").val(1);
        $("#pageSize").val('${query.pageSize}');
        $("#searchForm").submit();
        return false;
    }

    $("#obj-import").click(function () {
        $.jBox($("#objImportBox").html(), {
            title: "导入客观题", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#sub-import").click(function () {
        $.jBox($("#subImportBox").html(), {
            title: "导入主观题结构", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#group-import").click(function () {
        $.jBox($("#groupImportBox").html(), {
            title: "导入主观题分组", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！"
        });
    });
    $("#data-import").click(function () {
        $.jBox($("#dataImportBox").html(), {
            title: "导入数据包", buttons: {"关闭": true},
            bottomText: "导入文件不能超过5M，仅允许导入“zip”格式文件！"
        });
    });
    function goObjImport() {
        alert("导入后请务必重新统分");
    };

    function goSubImport() {
        alert("导入后请务必重新统分");
    };
    
    var myChart = echarts.init(document.getElementById('main'));
    var subjectString = "${subjectCountList}";
    var subjectData = subjectString.split(","); 
    var scoreString = "${totalScoreList}";
    var scoreData = scoreString.split(",");
    var colorList = ['#4080FF', '#F76560', '#FF9A2E', '#68CEC8', '#23C343', '#EB9562',
                     '#F2CD5F', '#57A9FB', '#8D4EDA', '#FBE842', '#B5E241', '#E13EDB', '#F754A8'];
    myChart.setOption({
    	title: {
            text: '科目总分统计'
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'cross',
              crossStyle: {
                color: '#999',
              },
            },
          },
        color:['#7CB5EC'],
    	  	xAxis: {
    	  		 name: '总分',
    		    type: 'category',
    		    data: scoreData
    		  },
    		  yAxis: {
    			name: '科目数量',
    		    type: 'value',
    		    minInterval:1,
    		  },
    		  series: [
    		    {	
    		      name:'科目数量',
    		      data: subjectData,
    		      type: 'bar',
    		      tooltip: {
    		          valueFormatter: function (value) {
    		            return value +' 个';
    		          }
    		        },
				  label: {
    		            show: true,
    		            position: 'top',
    		          },
    		      itemStyle:{
    		            normal:{
    		              color:function(params){
    		                return colorList[params.dataIndex%colorList.length]
    		              }
    		            }
    		          }
    		    }
    		  ]
    		})
    	
</script>
</body>
</html>