<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>编辑用户</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <!-- 引入 dtree 相关资源 -->
    <link rel="stylesheet" href="/js/lay-module/dtree/dtree.css">
    <link rel="stylesheet" href="/js/lay-module/dtree/font/dtreefont.css">
    <!-- 引入 font-aswsome 相关资源 -->
    <link rel="stylesheet" href="/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <input hidden name="id" th:value="${user.id}"/>
            <!-- 【用户名称】和【性别】 -->
            <div class="layui-form-item">
                <!-- 【用户名称】 -->
                <div class="layui-inline">
                    <label class="layui-form-label">用户名称<span style="color:red"> *</span></label>
                    <div class="layui-input-inline" style="width: 200px">
                        <input type="text" th:value="${user.username}" name="username" lay-verify="usernameVerify" placeholder="请输入用户姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <!--【性别】-->
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 70px">性别</label>
                    <div class="layui-input-inline" style="width: 100px">
                        <select name="sex" lay-filter="userSexFilter">
                            <option th:selected="${user.sex}=='0'" value="0" selected="">保密</option>
                            <option th:selected="${user.sex}=='1'" value="1">男</option>
                            <option th:selected="${user.sex}=='2'" value="2">女</option>
                        </select>
                    </div>
                </div>
            </div>
            <!-- 【邮箱账号】 -->
            <div class="layui-form-item">
                <label class="layui-form-label">登陆账号<span style="color:red"> *</span></label>
                <div class="layui-input-inline" style="width: 300px">
                    <input type="text" th:value="${user.loginName}" name="loginName" lay-verify="userEmailVerify" placeholder="请输入登陆账号" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">后台登录账号</div>
            </div>
            <!-- 【手机账号】-->
            <div class="layui-form-item">
                <label class="layui-form-label">手机号码</label>
                <div class="layui-input-inline" style="width: 300px">
                    <input type="text" th:value="${user.phone}" name="phone" lay-verify="userPhoneVerify" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">后台登录账号</div>
            </div>
            <!-- 【备注】 -->
            <div class="layui-form-item">
                <label class="layui-form-label">备　　注</label>
                <div class="layui-input-block">
                    <input type="text" th:value="${user.remark}" name="remark" lay-verify="userRemarkVerify" placeholder="备注信息" autocomplete="off" class="layui-input">
                </div>
            </div>
            <!-- 提交按钮 -->
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="#" lay-filter="form-user-save">立即保存</button>
            </div>
        </form>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['form', 'dtree', 'iconPickerFa'], function () {
        let $ = layui.jquery;
        let form = layui.form,
            layer = layui.layer;
        window.form = layui.form;

        //自定义验证规则
        form.verify({
            // 用户姓名
            usernameVerify: function (value) {
                if (value.length <= 0) {
                    return '请输入角色名称！';
                }
            },
            // 邮箱
            userEmailVerify: function (value) {
                if (value.length <= 0) {
                    return '请输入登录名称！';
                }

                if (value.length>30) {
                    return '登录名过长！';
                }
            },
            // 手机号
            userPhoneVerify: function (value) {
                let pattern = /^(13[0-9]|14[5|7]|15[0-9]|18[0-9]|19[4|5])\d{8}$/g;
                if (value.length > 0 && !pattern.test(value)) {
                    return '手机号码格式错误！';
                }
            }
        });

        //监听提交
        form.on('submit(form-user-save)', function (data) {
            // 加载层
            let index_loading = layer.load(1, {
                shade: [0.2, '#fff'] //0.1透明度的白色背景
            });
            // 提交角色
            $.post("/cloud/account/user/update", data.field, function (data) {
                // 关闭加载层
                layer.close(index_loading)
                // 根据返回状态码输出提示信息，200 表示成功，其他表示失败
                if (data.code === 200) {
                    layer.alert(data.msg, {icon: 1}, function () {
                        // 先得到当前iframe层的索引
                        let index22 = parent.layer.getFrameIndex(window.name);
                        // 关闭当前弹窗
                        parent.layer.close(index22);
                    });
                } else {
                    layer.alert(data.msg, {icon: 2});
                }
            });
            return false;
        });

    });
</script>
</body>
</html>
