<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../common/init.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="${ctx}/resources/css/main.css" type="text/css" />
<link rel='stylesheet' href='${ctx}/resources/css/easyui.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/easyui/icon.css' type='text/css' media='screen' />
<link rel='stylesheet' href='${ctx}/resources/css/user-center-style.css' type='text/css' media='screen' />

<%@ include file="../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<%@ include file="../common/validation.jsp"%>
<title>智能组卷</title>

<script language="javascript">
$(document).ready(function(){
	var myDate = new Date();
	var year = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
	var month = myDate.getMonth() + 1;       //获取当前月份(0-11,0代表1月)
	var headDefault = year + "年" + month + "月湖北省高等教育自学考试";
	$('#head').val(headDefault);
});

function onCourseChange(){
	var courseId = $('#course').combogrid('getValue');
	$('#book').combogrid('clear');
	$('#skeletion').combogrid('clear');
	$('#book').combogrid('grid').datagrid('load', {'courseId':courseId});
}

function onBookChange(){
	var courseId = $('#course').combogrid('getValue');
	var bookId = $('#book').combogrid('getValue');
	$('#skeletion').combogrid('clear');
	$('#skeletion').combogrid('grid').datagrid('load', {'courseId':courseId,'bookId':bookId});
}

function onCourseLoadSuccess(){
	var allCourses = $('#course').combogrid('grid').datagrid('getRows');
	if(allCourses.length == 1){
		$('#course').combogrid('setValue',allCourses[0].id);
	}
}

function onBookLoadSuccess(){
	var allBooks = $('#book').combogrid('grid').datagrid('getRows');
	if(allBooks.length == 1){
		$('#book').combogrid('setValue',allBooks[0].id);
	}
}

function onSkeletonLoadSuccess(){
	var allSkeletions = $('#skeletion').combogrid('grid').datagrid('getRows');
	if(allSkeletions.length == 1){
		$('#skeletion').combogrid('setValue',allSkeletions[0].id);
	}
}

function auto(){
	var lt = $('input[name="skeletion"]').val();
	var head = $('#head').val();
	var sl = $('input[name="zjsl"]').val();
	var sameCount = $('input[name="sameCount"]').val();
	var oldCount = $('input[name="oldCount"]').val();
	if(lt==null||lt==""){
		$.messager.alert('提示','请选择细目表!', 'error',function(){
			$('input[name="skeletion"]').focus();
		});
       return false;
	}
	if(head==null||head==""){
		$.messager.alert('提示','请输入题头!', 'error',function(){
			$('#head').focus();
		});
		return false;
	}
	if(sl==null||sl==""){
		$.messager.alert('提示','请输入组卷的数量!', 'error',function(){
			$('input[name="zjsl"]').focus();
		});
		return false;
	}
	if(sameCount==null||sameCount==""){
		$.messager.alert('提示','请输入同批试卷重复题数限制数量!', 'error',function(){
			$('input[name="sameCount"]').focus();
		});
		return false;
	}
	if(oldCount==null||oldCount==""){
		$.messager.alert('提示','请输入旧题限制数量!', 'error',function(){
			$('input[name="oldCount"]').focus();
		});
		return false;
	}
	//调用组卷校验方法
	$(document).mask('正在组卷中，请稍等...');
	$.post('${ctx}/zujuan/autoGeneratedPapers',$('#autoForm').serialize(),function(res){
		$(document).unmask();
		if(res.flag=='failed'){
			$.messager.alert('提示', res.msg, 'error', function () {
		        	   //do nothing
				});
			return false;
		}else{
			var url = "${ctx}/zujuan/viewPapers?skeletion=" + $('input[name="skeletion"]').val() + "&pcIdArrStr=" + encodeURIComponent(res.pcIdArrStr);
			window.location.href = url;
		}
	});
    return false;
};

</script>
</head>
<body style="overflow: hidden;">
    <%@ include file="../common/header.jsp"%>
    <div id="content" class="content">
        <%@ include file="../common/sub_menu.jsp"%>
        <div class="page" id="page" >
	        <div class="page-header" >智能组卷</div>
	        <div class="page-body">
	            <div id="generateForm" style="float: none;">
	                <form id="autoForm" action="" method="post" >
	                    <table class="searchTable" style="float: none;">
		                   <tr>
		                       <th>课程：</th>
		                       <td style="padding:0px 5px;" width="300px;">
		                          
		                           <input id="course" name="course" class="easyui-combogrid" style="width:300px;" 
	                           data-options="url:'${ctx}/course/queryByCurrentUser',
		                                   method:'get',
		                                   panelHeight:'160',
		                                   idField: 'id',
		                                   textField: 'name',
		                                   columns: [[
						                    {field:'code',title:'code',width:40},
						                    {field:'name',title:'课程名称',width:160}
						                    ]],
						                    fitColumns: true,
						                    editable:false,
	                                        onLoadSuccess: onCourseLoadSuccess,
						                    onChange: onCourseChange                    
		                                    "/>
		                       </td>
	                       </tr>
	                       <tr>
		                       <th>教材：</th>
		                       <td style="padding:0px 5px;">
		                         <input id="book" name="book" class="easyui-combogrid" style="width:300px;" 
                               data-options="url:'${ctx}/book/queryByCourseId',
	                                         method:'get',
	                                         panelHeight:'160',
	                                         idField: 'id',
	                                         textField: 'name',
	                                         columns: [[
	                                         {field:'code',title:'编号',width:40},
	                                         {field:'name',title:'名称',width:160},
	                                         {field:'press',title:'出版社',width:100}
	                                         ]],
	                                         fitColumns: true,
	                                         editable:false,
	                                         onLoadSuccess: onBookLoadSuccess,
	                                         onChange: onBookChange                                       
	                                          "/>
		                       </td>
	                       </tr>
	                       <tr>
		                       <th>细目表：</th>
		                       <td style="padding:0px 5px;">
		                            <input id="skeletion" name="skeletion" class="easyui-combogrid" style="width:300px;" 
                               data-options="url:'${ctx}/paperSkeleton/queryByBookId',
	                                         method:'get',
	                                         panelHeight:'160',
	                                         idField: 'id',
	                                         textField: 'name',
	                                         columns: [[
	                                         {field:'name',title:'名称',width:160}
	                                         ]],
	                                         fitColumns: true,
	                                         editable:false,
	                                         onLoadSuccess: onSkeletonLoadSuccess                                         
	                                          "/>
		                       </td>
		                   </tr>
	                       <tr>
		                       <th>试卷题头：</th>
		                       <td style="padding:0px 5px;"><input id="head" name="head" style="width:300px" maxlength="40" value=""/></td>
		                   </tr>
	                       <tr>
		                       <th>组卷数量：</th>
		                       <td style="padding:0px 5px;"><input id="zjsl" name="zjsl" style="width:300px" maxlength="2" value="1"/></td>
		                   </tr>
		                    <tr>
		                       <th style="width: 180px;">同批试卷重复题数限制：</th>
		                       <td style="padding:0px 5px;"><input id="sameCount" name="sameCount" style="width:300px" maxlength="2" value="0"/></td>
		                   </tr>
		                    <tr>
		                       <th>旧题限制数量：</th>
		                       <td style="padding:0px 5px;"><input id="oldCount" name="oldCount" style="width:300px" maxlength="2" value="40"/></td>
		                   </tr>
		                 </table>
		                 <div>
	                    <button class="btn" id="autoGenerate" onclick="return auto();" style="margin-top:5px;">开始组卷</button>
	                    </div>
	                </form>
	            </div>
	        </div>
        </div>
    </div>
</body>
</html>