<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link
	href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css"
	rel="stylesheet" type="text/css" />
<link
	href="${pageContext.request.contextPath }/common/admin/css/H-ui.login.css"
	rel="stylesheet" type="text/css" />
<link
	href="${pageContext.request.contextPath }/common/admin/css/style.css"
	rel="stylesheet" type="text/css" />
<link
	href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css"
	rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加管理员</title>
</head>
<body>
<div class="pd-20">
	<%-- <form action="${pageContext.request.contextPath }/admin/admin/addUI" method="post" class="form form-horizontal" id="form-admin-add"> --%>
	<form   class="form form-horizontal" id="form-admin-add">	
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>管理员：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="" id="user-name" name="adminLoginName" datatype="*2-16" nullmsg="用户名不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>初始密码：</label>
			<div class="formControls col-5">
				<input id="newpassword1" type="password" placeholder="密码" autocomplete="off" value="" class="input-text" datatype="*6-20" nullmsg="密码不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>确认密码：</label>
			<div class="formControls col-5">
				<input id="newpassword2" type="password" placeholder="确认新密码" autocomplete="off" class="input-text Validform_error" errormsg="您两次输入的新密码不一致！" datatype="*" nullmsg="请再输入一次新密码！" recheck="newpassword" name="adminLoginPwd">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>性别：</label>
			<div class="formControls col-5 skin-minimal">
				<div class="radio-box">
					<input type="radio" id="sex-1" name="adminSex" checked="checked" value="1" datatype="*" nullmsg="请选择性别！">
					<label for="sex-1">男</label>
				</div>
				<div class="radio-box"> 
					<input type="radio" id="sex-2" name="adminSex" value="2">
					<label for="sex-2">女</label>
				</div>
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>手机：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" value="" placeholder="" id="user-tel" name="adminTel"  datatype="m" nullmsg="手机不能为空">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>邮箱：</label>
			<div class="formControls col-5">
				<input type="text" class="input-text" placeholder="@" name="adminEmail" id="email" datatype="e" nullmsg="请输入邮箱！">
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<label class="form-label col-3">简介：</label>
			<div class="formControls col-5">
				<textarea name="adminDesc" cols="" rows="" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p>
			</div>
			<div class="col-4"> </div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-3">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" onclick="admin_add()">
			</div>
		</div>
	</form>
</div>
<script type="text/javascript"
		src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
	<script type="text/javascript"
		src="${pageContext.request.contextPath }/common/admin/js/tips.js"></script>
<script type="text/javascript">
 $(document).ready(function(){
	//管理员账号数据验证
	$('#user-name').blur(function(){
		if(!commonLengthJdg('user-name',6,20,null,true)){
			layer.msg("用户名不能为空长度为6-20位",{icon: 5,time:3000});
			return;
		}
	});
	//密码验证
	$('#newpassword1').blur(function(){
		if(!commonLengthJdg('newpassword1',6,20,null,true)){
			layer.msg("密码不能为空长度为6-20位",{icon: 5,time:3000});
			return;
		}
	});
	//2次密码须保持一致
	$('#newpassword2').blur(function(){
		var passwordObj = $("#newpassword1").val();
		var rePasswordObj = $("#newpassword2").val();
		if(passwordObj != rePasswordObj){
			layer.msg("两次密码输入不一致",{icon: 5,time:3000});
			return;
		}
	});
	//手机验证
	$('#user-tel').blur(function(){
		if(!commonTypeJdg('user-tel','mobile',null,true)){
			layer.msg("手机号不能为空或格式错误",{icon: 5,time:3000});
			return;
		}
	});
	//邮箱验证
	$('#email').blur(function(){
		if(!commonTypeJdg('email','mail',null,true)){
			layer.msg("邮箱不能为空或格式错误",{icon: 5,time:3000});
			return;
		}
    });
    
});

$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-admin-add").Validform({
		tiptype:2,
		callback:function(form){
			form[0].submit();
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});

/*管理员-添加*/
function admin_add(){
			//管理员账号数据验证
			if(!commonLengthJdg('user-name',6,20,null,true)){
				layer.msg("管理员账号长度为6-20位",{icon: 5,time:3000});
				return;
			}
			//密码验证
			if(!commonLengthJdg('newpassword1',6,20,null,true)){
				layer.msg("密码由字母与数字组成且大于6位",{icon: 5,time:3000});
				return;
			}
			//2次密码须保持一致
			var passwordObj = $("#newpassword1").val();
    		var rePasswordObj = $("#newpassword2").val();
			if(passwordObj != rePasswordObj){
				layer.msg("两次密码输入不一致",{icon: 5,time:3000});
				return;
			}
			//手机验证
			if(!commonTypeJdg('user-tel','mobile',null,true)){
				layer.msg("手机号不能为空或格式错误",{icon: 5,time:3000});
				return;
			}
			//邮箱验证
			if(!commonTypeJdg('email','mail',null,true)){
				layer.msg("邮箱不能为空或格式错误",{icon: 5,time:3000});
				return;
			}
			
		  $.ajax({
              url: '${pageContext.request.contextPath }/admin/admin/addUI',
              type: "POST",
              dataType: "json",
              data: $("#form-admin-add").serialize(),
              beforeSubmit: function (data) {
            	  $("#submit").attr("disabled","disabled");
              },
              success:  function(data){
            	  	  layer.msg(data.status,{icon: 1,time:3000},function(){
            		  window.location.href = '${pageContext.request.contextPath }/admin/admin/listUI';
            	  });
            	 
              },
              error:function(data){
            	  layer.msg(data.status,{icon: 5,time:3000});
              }
          });
}
</script>
</body>
</html>