<%@ 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;
    }</style>
    <style type="text/css">
        .sort {
            color: #0663A2;
            cursor: pointer;
        }
        
        .addWindow, .editWindow ,.scorePolicyWindow{
            width: 400px;
            min-height: 200px;
            background: #fff;
            font-family: "微软雅黑", Fixedsys;
            border: #5d6d7d solid 1px;
            position: absolute;
            left: 50%;
            top: 50%;
            margin: -150px 0 0 -200px;
            text-align: center;
            z-index: 9999;
        }
        
        .task-header, .password-header {
            width: 100%;
            height: 46px;
            background: #5d6d7d;
            color: #fff;
        }
        
        .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>
	<%-- <%@include file="/WEB-INF/views/include/examInfoNavTabs.jsp" %> --%>
	<form id="inputForm" action="${ctx}/admin/exam/selectiveGroup/add" method="post" class="breadcrumb form-search">
		<input name="subjectCode" value="${subject.code}" type="hidden"/>
		<div>
			<label>科目：${subject.code}-${subject.name}</label>
			<label>客观总分：<fmt:formatNumber pattern="###.###" value="${subject.objectiveScore}"/></label>
			<label>主观总分：<fmt:formatNumber pattern="###.###" value="${subject.subjectiveScore}"/></label>
			<label>试卷总分：<fmt:formatNumber pattern="###.###" value="${subject.totalScore}"/></label>
			&nbsp;		
			<input id="btnAdd" class="btn" type="button" value="新增" onclick="goAdd()"/>
			&nbsp;		
			<input class="btn" type="button" value="编辑" onclick="goEdit()"/>
		</div>
		<br/>
	<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>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${questions}" var="question">
			<tr>
				<td>${question.mainTitle}</td>
				<td>${question.mainNumber}</td>
				<td>${question.subNumber}</td>
				<td><fmt:formatNumber pattern="###.###" value="${question.totalScore}"/></td>
				<td><fmt:formatNumber pattern="###.###" value="${question.intervalScore}"/></td>
				<td>${question.selectiveIndex}-
					<c:if test="${question.scorePolicy==1}">平均分</c:if>
					<c:if test="${question.scorePolicy==2}">取高分</c:if>
					<c:if test="${question.scorePolicy==3}">取低分</c:if>
				</td>
				<td>${question.selectiveIndex}-${question.selectivePart}</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="addWindow" 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>
	    <div class="task-content">选做题规则：<input type="number" id="selectivePart" name="selectivePart" class="task-count" oninput="if(value<0)value=0"/>选<input type="number" id="selectiveCount" name="selectiveCount" class="task-count" oninput="if(value<0)value=0"/><br/><br/>
	    <div style="z-index:99999">
	    取分规则：<select name="scorePolicy" style="z-index:99999;">
	    			 <c:forEach items="${scorePolicyList}" var="item">
                        <option value="${item.value }">${item.name }</option>
                     </c:forEach>
	    		</select><br/><br/>
	    </div>
	    *如选做为5选3，则系统会校验后续选做题总量为5，合分数量为3。
	    <i class="wrong"> </i>
	    </div>
	    <a href="#" class="btn btn-small btn-info task-btn">下一步</a>
	</div>
	<div class="editWindow" 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>
	    <div class="task-content">
	    	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>选做题组</th>
				<th>规则</th>
				<th>大题名称</th>
				<th>分值</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${list}" var="group">
			<tr>
				<td>${group.selectiveIndex}</td>
				<td>${group.selectivePart}选${group.selectiveCount}
					<br/>	${group.scorePolicy.name}
				</td>
				<td>${group.title}</td>
				<td><fmt:formatNumber pattern="###.###" value="${group.partScore*group.selectiveCount}"/></td>
				<td>
					<a href="${ctx}/admin/exam/selectiveGroup/delete?subjectCode=${subject.code}&selectiveIndex=${group.selectiveIndex}">删除</a>
					<a href="#" onclick="goScorePolicy(${group.selectiveIndex},${group.selectivePart},${group.selectiveCount},${group.scorePolicy.value})" >编辑</a>	
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	    </div>
	</div>
	<div class="scorePolicyWindow" style="display:none">
	<input name="selectiveIndex"  type="hidden" id="selectiveIndex"/>
	    <div class="task-header">
	        <p class="title">设置选做题规则</p>
	        <p class="image-close"><img src="${ctxStatic}/mark-new/images/images-close.png"/></p></div>
	    <div class="task-content">选做题规则：<span id ="scorePolicySpan"></span> <br/><br/>
	    <div style="z-index:99999">
	    取分规则：<select name="policy" style="z-index:99999;" id="scorePolicySelect">
	    			 <c:forEach items="${scorePolicyList}" var="item">
                        <option value="${item.value }">${item.name }</option>
                     </c:forEach>
	    		</select><br/><br/>
	    </div>
	    *如选做为5选3，则系统会校验后续选做题总量为5，合分数量为3。
	    <i class="wrong"> </i>
	    </div>
	    <a href="#" class="btn btn-small btn-info btn-score-policy">完成</a>
    </div>

	</form>
<script type="text/javascript">
function goAdd() {
	$('.editWindow').hide();
	$('.addWindow').show();
}
function goEdit() {
	 $('.addWindow').hide();
	$('.editWindow').show();
}
function goScorePolicy(selectiveIndex,a,b,c) {
	$('#selectiveIndex').empty();
	$('#selectiveIndex').attr("value",selectiveIndex);
	
	$('#scorePolicySpan').empty();
	$('#scorePolicySpan').append(a+"选"+b);
	
	$('#scorePolicySelect').empty();
	$('#scorePolicySelect').append('<option value="2">最高分</option>');
	$('#scorePolicySelect').append('<option value="3">最低分</option>');
	$('#scorePolicySelect').val(c).trigger('change');;
	
	$('.scorePolicyWindow').show();
	$('.addWindow').hide();
    $('.editWindow').hide();
}

$('.image-close').click(function () {
    $('.addWindow').hide();
    $('.editWindow').hide();
    $('.scorePolicyWindow').hide();
});
$('.task-btn').click(function () {
    var selectivePart = $('#selectivePart').val();
    var selectiveCount = $('#selectiveCount').val();
    var wrongMessage = $('.wrong');
    selectivePart = selectivePart.replace(/(^\s*)|(\s*$)/g, "");
    selectiveCount = selectiveCount.replace(/(^\s*)|(\s*$)/g, "");
    if (selectivePart.length == 0 ||selectiveCount.length==0) {
        wrongMessage.html('规则不能为空！');
        return false;
    } else {
        if (!/^\+?[1-9][0-9]*$/.test(selectivePart) || !/^\+?[1-9][0-9]*$/.test(selectiveCount)) {
            wrongMessage.html('请输入正整数!');
            return false;
        }
        selectivePart = Number(selectivePart);
        selectiveCount = Number(selectiveCount);
        if (selectivePart > 100 ||selectiveCount > 100 ||selectivePart <= 0 ||selectiveCount <= 0) {
            wrongMessage.html('数量不合法!');
            return false;
        }
        if (selectivePart <= selectiveCount || selectiveCount<1) {
            wrongMessage.html('合分数量必须小于选择数量且大于等于1');
            return false;
        }
    }
   $("#inputForm").attr("action", "${ctx}/admin/exam/selectiveGroup/add");
   $('#inputForm').submit();
});
$('.btn-score-policy').click(function () {
	if(confirm('修改取分规则会触发重新算分，算分完成前，不能进行该科目的任何操作！')){
		 $("#inputForm").attr("action", "${ctx}/admin/exam/selectiveGroup/edit");
		   $('#inputForm').submit();
	}
});
</script>	
</body>
</html>