<%@ 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/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' />
<style>
.boderTbl {border-collapse:collapse;border:none;}
.boderTbl th{text-align:center;vertical-align:middle;border:1pt solid #dddddd;padding:5px;}
.boderTbl td{vertical-align:middle;border:1pt solid #dddddd;padding:5px;}
.myTitleTd{
	font-size: 12px;
	font-weight: normal;
	width: 100px;
	height:25px;
	text-align: right;
}

.myValueTd{
	font-size: 12px;
	font-weight: normal;
	text-align: left;
}

.myValueTd input[type=text]{
	width: 200px;
}

.myValueTd textarea{
	width: 200px;
	height: 50px;
}

.myValueTd select{
	width: 200px;
}

.myValueTd label{
	color: red;
}

.formErrorContent{
	display: none;
}
</style>
<%@ include file="../common/top.jsp"%>
<script type="text/javascript" src="${ctx}/resources/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/validator.js"></script>
<script type="text/javascript" src="${ctx}/resources/js/easyui-lang-zh_CN.js"></script>
<%@ include file="../common/validation.jsp"%>
<title>细目表配置</title>

<script language="javascript">
$(document).ready(function(){
    $('#search-form').submit(function(event){
        event.preventDefault(); 
        var param = $('#search-form').serializeJson();
        param = $.extend(param, {page:1,rows:10});
        $('#dg').datagrid('load',param);
    });

    $("#dg").datagrid({
        onDblClickRow: function (rowIndex, rowData) {
            openBookWin(rowData,"编辑教材信息");
        }
    });
    
    $("#addBtn").click(function(){
    	openBookWin({},"添加教材信息");
    	return false;
    });
    
    $("#cancleEditBtn").click(function(){
    	$('#editBookDiv').window('close');
    	return false;
    });
    
    $("#saveEditBtn").click(function(){
    	saveBookEdit();
    	return false;
    });
    
    $("#formForEdit").validationEngine();
    
    $("#remarkForEdit").keydown(function(){
    	calculate_byte(200,'remarkForEdit','count');
    });
    $("#remarkForEdit").keyup(function(){
    	calculate_byte(200,'remarkForEdit','count');
    });
    $("#remarkForEdit").keypress(function(){
    	calculate_byte(200,'remarkForEdit','count');
    });
    
    $("#searchBtn").on('click',function(){
    	$('#search-form').submit();
    });
});

function saveBookEdit(){
	if($("#formForEdit").validationEngine('validate')){
		$.ajax({
			type : "POST",
			url : "${ctx}/book/save",
			data : $('#formForEdit').serialize(), 
			success : function(callback) {
				if(callback.flag == 'success'){
					$.messager.alert('提示', callback.msg, 'info', function () {
						$('#editBookDiv').window('close');
						$('#dg').datagrid('reload');
                    });
				}else{
					$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
				}
			}
		});
	}
}
</script>
</head>
<body>
    <%@ 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">
        <form action="#" id="cfgForm">
        <input type="hidden" name="id" value="${skelCfg.id}"/>
        <table class="boderTbl">
        	<tr>
        		<th>配置项</th>
        		<th>最小值(%)</th>
        		<th>最大值(%)</th>
        	</tr>
        	<tr>
        		<td>预计难度-易</td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty1RangeMin" name="estimateDifficulty1RangeMin" value="${skelCfg.estimateDifficulty1RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty1RangeMax" name="estimateDifficulty1RangeMax" value="${skelCfg.estimateDifficulty1RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>预计难度-中等偏易</td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty2RangeMin" name="estimateDifficulty2RangeMin" value="${skelCfg.estimateDifficulty2RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty2RangeMax" name="estimateDifficulty2RangeMax" value="${skelCfg.estimateDifficulty2RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>预计难度-中等偏难</td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty3RangeMin" name="estimateDifficulty3RangeMin" value="${skelCfg.estimateDifficulty3RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty3RangeMax" name="estimateDifficulty3RangeMax" value="${skelCfg.estimateDifficulty3RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>预计难度-难</td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty4RangeMin" name="estimateDifficulty4RangeMin" value="${skelCfg.estimateDifficulty4RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="estimateDifficulty4RangeMax" name="estimateDifficulty4RangeMax" value="${skelCfg.estimateDifficulty4RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>认知层次-识记</td>
        		<td><input type="text" textType="number" maxlength="2" id="ability1RangeMin" name="ability1RangeMin" value="${skelCfg.ability1RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="ability1RangeMax" name="ability1RangeMax" value="${skelCfg.ability1RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>认知层次-理解</td>
        		<td><input type="text" textType="number" maxlength="2" id="ability2RangeMin" name="ability2RangeMin" value="${skelCfg.ability2RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="ability2RangeMax" name="ability2RangeMax" value="${skelCfg.ability2RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>认知层次-简单应用</td>
        		<td><input type="text" textType="number" maxlength="2" id="ability3RangeMin" name="ability3RangeMin" value="${skelCfg.ability3RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="ability3RangeMax" name="ability3RangeMax" value="${skelCfg.ability3RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td>认知层次-综合应用</td>
        		<td><input type="text" textType="number" maxlength="2" id="ability4RangeMin" name="ability4RangeMin" value="${skelCfg.ability4RangeMin}"/></td>
        		<td><input type="text" textType="number" maxlength="2" id="ability4RangeMax" name="ability4RangeMax" value="${skelCfg.ability4RangeMax}"/></td>
        	</tr>
        	<tr>
        		<td colspan="3" align="center"><button id="saveBtn">保存</button></td>
        	</tr>
        </table>
        </form>
	    </div>
        </div>
    </div>
</body>
</html>
<script language="javascript">
$(document).ready(function(){
	$("[textType='number']").each(function(){
    	$(this).keyup(function(e){
    		var val = $(this).val() - 0;
    		if(!val || val < 0){
    			val = '';
    		}
    		$(this).val(val);
    	});
	});
	
	$('#saveBtn').click(function(){
		var allRight = true;
		$("[textType='number']").each(function(index,element){
			var curInput = $(this);
    		var val = curInput.val() - 0;
    		if(!val || val < 0){
    			val = '';
    		}
    		console.log(val);
    		curInput.val(val);
    		if(val == ''){
    			$.messager.alert('提示', '请输入数值!', 'error', function () {
    				curInput.focus();
 	        	});
    			allRight = false;
    			return allRight;
    		}
    		if(index % 2 == 1){
    			var preVal = $("[textType='number']").eq(index - 1).val() - 0;
    			if(preVal > val){
    				$.messager.alert('提示', '最大值不能小于最小值，请重新输入!', 'error', function () {
    					curInput.select();
        				curInput.focus();
     	        	});
        			allRight = false;
        			return allRight;
    			}
    		}
		});
		if(!allRight){
			return false;
		}
		var estimateDifficulty1RangeMin = $('#estimateDifficulty1RangeMin').val() - 0;
		var estimateDifficulty1RangeMax = $('#estimateDifficulty1RangeMax').val() - 0;
		var estimateDifficulty2RangeMin = $('#estimateDifficulty2RangeMin').val() - 0;
		var estimateDifficulty2RangeMax = $('#estimateDifficulty2RangeMax').val() - 0;
		var estimateDifficulty3RangeMin = $('#estimateDifficulty3RangeMin').val() - 0;
		var estimateDifficulty3RangeMax = $('#estimateDifficulty3RangeMax').val() - 0;
		var estimateDifficulty4RangeMin = $('#estimateDifficulty4RangeMin').val() - 0;
		var estimateDifficulty4RangeMax = $('#estimateDifficulty4RangeMax').val() - 0;
		var ability1RangeMin = $('#ability1RangeMin').val() - 0;
		var ability1RangeMax = $('#ability1RangeMax').val() - 0;
		var ability2RangeMin = $('#ability2RangeMin').val() - 0;
		var ability2RangeMax = $('#ability2RangeMax').val() - 0;
		var ability3RangeMin = $('#ability3RangeMin').val() - 0;
		var ability3RangeMax = $('#ability3RangeMax').val() - 0;
		var ability4RangeMin = $('#ability4RangeMin').val() - 0;
		var ability4RangeMax = $('#ability4RangeMax').val() - 0;
		if(estimateDifficulty1RangeMin + estimateDifficulty2RangeMin + estimateDifficulty3RangeMin + estimateDifficulty4RangeMin > 100){
			$.messager.alert('提示', '预计难度最小值设置不合理，请重新设置!', 'error', function () {
				//$('#estimateDifficulty1RangeMin').select();
				//$('#estimateDifficulty1RangeMin').focus();
	        });
			return false;
		}if(estimateDifficulty1RangeMax + estimateDifficulty2RangeMax + estimateDifficulty3RangeMax + estimateDifficulty4RangeMax < 100){
			$.messager.alert('提示', '预计难度最大值设置不合理，请重新设置!', 'error', function () {
				//$('#estimateDifficulty1RangeMax').select();
				//$('#estimateDifficulty1RangeMax').focus();
	        });
			return false;
		}
		if(ability1RangeMin + ability2RangeMin + ability3RangeMin + ability4RangeMin > 100){
			$.messager.alert('提示', '认知层次最小值设置不合理，请重新设置!', 'error', function () {
				//$('#ability1RangeMin').select();
				//$('#ability1RangeMin').focus();
	        });
			return false;
		}if(ability1RangeMax + ability2RangeMax + ability3RangeMax + ability4RangeMax < 100){
			$.messager.alert('提示', '认知层次最大值设置不合理，请重新设置!', 'error', function () {
				//$('#ability1RangeMax').select();
				//$('#ability1RangeMax').focus();
	        });
			return false;
		}
		$.ajax({
			type : "POST",
			url : "${ctx}/paperSkeleton/skelCfgSave",
			data : $('#cfgForm').serialize(), 
			success : function(callback) {
				if(callback.flag == 'success'){
					$.messager.alert('提示', callback.msg, 'info', function () {
						reloadWin();
                    });
				}else{
					$.messager.alert('提示', "更新失败，请刷新后操作!", 'error');
				}
			}
		});
    	return false;
    });
});
</script>