<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>
    	.clearfix:after {
			visibility: hidden;
			display: block;
			font-size: 0;
			content: " ";
			clear: both;
			height: 0;
		}
		.clearfix { display: inline-table; }
		* html .clearfix { height: 1%; }
		.clearfix { display: block; }
		.fl{display:inline;float:left}
		clearfix >control-label-error{display:inline;float:left;marign-left:10px}
		 label.control-label-error {
  				color: Red;
             }
    </style>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    	<li><a href="#">系统管理</a></li>
    	<li><a href="#">管理员管理</a></li>
    </ul>
</div>
<div class="formbody">
	<div class="formtitle"><span>管理员信息</span></div>
	<form id="userFrom"   method="post" class="form-horizontal form-validate">
		<input  type="hidden" id="id" th:if="${admin.id}" th:value="${admin.id}" name="id">
		<input  type="hidden"  th:value="${admin.operId}" name="operId">
		<ul class="forminfo">
			<li class="clearfix">
				<label class="fl">登录名<b>*</b></label>
				  <input  type="text"  id="loginName" th:value="${admin.loginName}"   class="dfinput fl"  name="loginName">
			</li>
			<li class="clearfix">
				<label class="fl">昵称<b>*</b></label>
				<input  type="text"   class="dfinput fl"  th:value="${admin.nickName}"  name="nickName">
			</li>
			<li class="clearfix">
				<label class="fl">密码<b>*</b></label>
				<input type="password"    class="dfinput fl" th:value="${admin.password}"  name="password">
			</li>
			<li>
				<label>&nbsp;</label>
				<button type="submit" class="btn">保存</button>
				<button type="button" class="btn" onclick="window.history.go(-1);">取消</button>
			</li>
		</ul>
	</form>
</div>
</body>
<script type="text/javascript">


$(function(){
	$("#userFrom").validate({
		rules : {
			loginName : {
				required : true,
				maxlength:20,
				minlength:2,
				remote:{
		               type:"POST",
		               url:'[[${sysUrl}]]/sys/role/validateLoginName',       
		               data:{
		            	   loginName:function(){return $("#loginName").val();},
		            	   id:function(){return $("#id").val();}
		               } 
		              } 
			},
			nickName:{required: true},
			password : {
				minlength: 8,
				required : true
			}
		},
		messages: {
			loginName : {
				required : "请输入用户名",
				maxlength:"用户名最多20个字符",
				minlength:"用户名最少2个字符",
				remote:"登录名已存在!"
			},
			password: {
			    required: "请输入密码",
			    minlength: "密码最少8个字符"
			   },
			nickName :"请输入昵称"
		},
		errorPlacement : function(error, element) {
				error.appendTo(element.parent()); 
		},
		submitHandler : function(form) {
			userFrom();
		}
	});
	
});
function userFrom(){
	var url="[[${sysUrl}]]/sys/role/saveAdmin";
	var params = $("#userFrom").serialize();
	$.post(url,params,function(data){
		if(data != null){
				if(data.meta.success){
					layer.msg("操作成功!",{icon:1});
			    	setTimeout(function(){
			    		window.location.href ='[[${sysUrl}]]/sys/role/adminlist.html';
					},1000);
				}else{
					layer.msg(data.meta.message,{icon:11});
				}
		}
		
	});
}


</script>
</html>