<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="./layui/css/layui.css" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" href="./style/myself.css" th:href="@{/style/myself.css}" media="all">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="./js/html5.min.js" th:src="@{/js/html5.min.js}"></script>
    <script src="./js/respond.min.js" th:src="@{/js/respond.min.js}"></script>
    <![endif]-->
    <script type="text/javascript" charset="utf-8" th:inline="javascript">
        var ctxPath = /*[[@{/}]]*/'';
    </script>
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin"
     style="padding: 20px 20px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">账号</label>
        <div class="layui-input-inline">
            <input type="text" name="account" lay-verify="account" placeholder="请输入账号" autocomplete="off"
                   class="layui-input" lay-verType="tips">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" lay-verify="username" placeholder="请输入用户名" autocomplete="off"
                   class="layui-input" lay-verType="tips">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" lay-verify="password" placeholder="请输入密码" autocomplete="off"
                   class="layui-input" lay-verType="tips">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择角色</label>
        <div class="layui-input-block">
            <input type="radio" name="roleId" th:each="role,roleStat:${roles}" th:value="${role.id}"
                   th:title="${role.roleName}" th:checked="${role.id==1}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" lay-verify="email" placeholder="请输入邮箱" autocomplete="off"
                   class="layui-input" lay-verType="tips">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="remarks" class="layui-textarea" placeholder="请输入备注" autocomplete="off"></textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
    </div>
</div>
<script src="./layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script>
    layui.config({
        base: ctxPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function () {
        var form = layui.form;
        //自定义验证规则
        form.verify({
            account: function (value) {
                if (value.length === 0) {
                    return '账号不能为空';
                }
            },
            username: function (value) {
                if (value.length === 0) {
                    return '用户名不能为空';
                }
                return new RegExp("^[a-zA-Z0-9_一-龥\\s·]+$").test(value)
                    ? /(^\_)|(\__)|(\_+$)/.test(value)
                        ? "用户名首尾不能出现下划线'_'" : /^\d+$/.test(value)
                            ? "用户名不能全为数字" : void 0 : "用户名不能有特殊字符";
            },
            password: function (value) {
                if (!(/^[\S]{6,30}$/.test(value))) {
                    return '密码必须6到30位，且不能出现空格'
                }
            },
            email: function (value) {
                if (value.length !== 0) {
                    if (!(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value))) {
                        return '邮箱格式不正确';
                    }
                }
            }
        });
    });
</script>
</body>
</html>