<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>私塾家</title>
<script th:include="sys/common/metaCSS" th:remove="tag"></script> 
<script th:include="sys/common/metaJS" th:remove="tag"></script> 
<script src="sys/js/jquery.validate.min.js" th:src="@{/static/sys/js/jquery.validate.min.js}"></script>
<script src="sys/js/jquery-validation/messages_zh.js" th:src="@{/static/sys/js/jquery-validation/messages_zh.js}"></script>
<style type="text/css">
   body{min-width:180px;}
       .select1{
   		    width:100%;
		    height: 32px;
		    line-height: 32px;
		    border-top: solid 1px #a7b5bc;
		    border-left: solid 1px #a7b5bc;
		    border-right: solid 1px #ced9df;
		    border-bottom: solid 1px #ced9df;
		    opacity:1;
	        margin-bottom: 10px;
    	}
    	.btn{
    	  width: 100px;
    	}
     label.control-label-error {color: Red;}	
    </style>
</head>

<body>
<div class="formbody">
	<form id="submitFrom"   method="post" class="form-horizontal form-validate">
		     <input type="hidden" name="libId"  th:value="${libId}"/>
		<ul class="forminfo">
			  <li>
				<label>新增折扣数量:<b>*</b></label>
				<input type="number" id="num" class="dfinput fl" name="num"  value="1"/>
			</li>
			<li>
				<label>输入折扣</label>
				<input type="number" id="discount" class="dfinput fl" name="discount"  value="100"/>
			</li>
				<li>
					<label>&nbsp;</label>
					<button type="submit" class="btn">保存</button>
					<button type="button" class="btn"  onclick="closeWin();">取消</button>
				</li>
		</ul>
	</form>
</div>
</body>
<script type="text/javascript">

$(function(){
	
	
	$("#submitFrom").validate({
		rules : {
			
			num : {
				required : true,
				digits:true
			},
			discount : {
				required : true,
				digits:true,
				min:10,
				max:100
			}
		},
		messages: {
			num : {
				required : "不能为空",
				digits : "只能输入整数"
			},
			discount : {
				required : "不能为空",
				digits : "只能输入整数",
				max:"最大为100",
				min:"最小为10",
			}
			
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			roleFrom();
		}
	});
	
});
function roleFrom(){
	var url="[[${sysUrl}]]/sys/sales/libVipCodeSave";
	var params = $("#submitFrom").serialize();
	$.post(url,params,function(data){
		if(data != null){
				if(data.meta.success){
					parent.layer.msg("新增成功",{icon:1});
					closeWin();
				}else{
					parent.layer.msg(data.meta.message,{icon:11});
					closeWin();
				}
		}
		
	});
}
function closeWin(){
	parent.location.reload();
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}


</script>
</html>