<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/fns.tld" prefix="fns" %>
<div class="modal-header bg-1f96ef">
	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	<h4 class="modal-title">新增账号</h4>
</div>
<div  class="tab-content">
<form id="aeResellerForm" class="tab-pane fade active in">
	<div class="modal-body">
 	<p class="">
 		<label>登录名:</label>
		<input type="hidden" class="form-control" name="type"  value="1"  >

		<input type="text" class="form-control" name="userName" id="userName" onblur="checkLoginName()"  >
 	</p>
 	<p>
 		<label>姓名:</label>
		<input type="text" name="realName"  class="form-control">
 	</p>
 	<p>
 		<label>电子邮箱</label>
		<input type="text" name="email" class="form-control" id="email"  onblur="checkEmailName()" >
 	</p>

	<p>
		<label>手机号码</label>
		<input type="text" name="telephone" class="form-control" id="telephone"  >
	</p>

	<p>
		<label>密码</label>
		<input type="password" name="password"  value="" class="form-control">
	</p>
	<p>
		<label>角色</label>
		<select  name="roleName" class="form-control">
			<option value="COMMON-ONE-YUNYING" <c:if test="${user.roleName eq 'COMMON-ONE-YUNYING'}">checked="checked"</c:if>>运营</option>

		</select>
	</p>
		<br>
		<br>
	<p>
		<label>状态:</label>
		<select class="form-control" name="status">
			<option value="1" <c:if test="${user.status eq '1'}">selected="selected"</c:if>>正常</option>
			<option value="0" <c:if test="${user.status eq '0'}">selected="selected"</c:if>>失效</option>
		</select>
	</p>
		<br>
		<br>
		<br>
		<div class="modal-footer">
			<div class="bo-conten">
			<button type="button" class="btn pull-left cancel-btn" data-dismiss="modal">取消</button>
			<button type="button" class="btn notarize-btn pull-right" onclick="tijiao()">保存</button>
		</div>
	</div>
	</div>
</form>
</div>
<script>
	 function  checkLoginName(){
		 var flag=false;
		 var index = layer.load(0, {shade: [0.3,'#808080']});
		 var  userName  =$("#userName").val();
		 if(userName!=null&&userName!=""){
			 $.ajax({
				 type : 'POST',
				 url : baseUrl + "/sysuser/getUserForRegister",
				 data : {loginName:userName},
				 dataType : "json",
				 async: false,
				 success : function(data) {
					 layer.close(index);
					 if(data.status == '1'){
						 layer.msg("存在此用户请重新填写。")
					 }else{
						 flag=true;
					 }
				 },
				 error: function(){
					 layer.close(index);
				 }
			 });
		 }else{
			 layer.close(index);
		 }
		 return  flag;
	 }

	 function  checkEmailName(){
		 var flag=false;
		 var index = layer.load(0, {shade: [0.3,'#808080']});
		 var  email  =$("#email").val();
		 if(email!=null&&email!=""){
			 $.ajax({
				 type : 'POST',
				 url : baseUrl + "/sysuser/getEmailForRegister",
				 data : {email:email},
				 dataType : "json",
				 async: false,
				 success : function(data) {
					 layer.close(index);
					 if(data.status == '1'){
						 layer.msg("该邮箱已经被注册了，请重新填写。")
					 }else{
						 flag=true;
					 }
				 },
				 error: function(){
					 layer.close(index);
				 }
			 });
		 }else{
			 layer.close(index);
		 }
		 return  flag;
	 }

	 function tijiao(){

		 if(checkLoginName()){
			 if(checkEmailName()){
				 saveUserModel('aeResellerForm');
			 }

		 }
	 }
</script>