<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加角色</title>
<%@include file="/views/common.jsp"%>
<link rel="stylesheet" href="${path}/static/css/formSelects-v4.css">
<style>
.layui-input,.layui-input-inline{
	width:350px
}
</style>
</head>
<body>
	<div class="layui-input-block layui-form" lay-filter="addRole"
		style="margin-top: 30px">
		<form class="layui-form " action="">
			<div class="layui-form-item">
				<label class="layui-form-label">角色名称</label>
				<div class="layui-input-inline">
					<input type="text" name="roleName" lay-verify="roleName"
						placeholder="请输入角色名称" class="layui-input" autocomplete="off">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">角色说明</label>
				<div class="layui-input-inline">
					<textarea rows="5" cols="47" name="remark" id="remark" placeholder="请输入角色说明"></textarea>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">是否可注册</label>
				<div class="layui-input-block" id="idSuper">
					<input type="radio" name="isRegist" value="1" title="是" checked="">
					<input type="radio" name="isRegist" value="0" title="否">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="enadd">确认添加</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
	<script>
		layui.use([ 'form', 'layer' ],function() {
			var $ = layui.$,
			 form = layui.form, 
			layer = layui.layer;

			//自定义验证规则
			form.verify({
				roleName : function(value, item) { //value：表单的值、item：表单的DOM对象
					if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
						return '角色名称不能有特殊字符';
					}
				}
			});
			
			//监听提交
			form.on('submit(enadd)', function(data) {
				$.ajax({
					url : '${path}/addRole',
					dataType : 'json',
					data : $(data.form).serialize(),
					type : 'post',
					success : function(data) {
						if (data.code == 200) {
							layer.msg('录入成功！', {
								icon : 6,
								offset : "auto",
								time : 2000
							});//提示框
							setTimeout(function(){
								var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
								parent.layer.close(index);//关闭弹出层
								parent.layui.table.reload("roleTableAll"); //重新加载页面表格
							}, 2100);
						} else {
							layer.msg('录入失败！', {
								icon : 5,
								offset : "auto",
								time : 2000
							});//提示框
						}
					}
				})
				return false;
			});
		})
	</script>
</body>
</html>