{{extends "/admin/common/base_content"}}

{{block title()}}添加账号 - Doak CMS{{end}}

{{block body()}}

<style>
.form-text {
    color: #b7bbbf;
}
</style>

<div class="container-fluid pt-4 px-4">
    <div class="row g-4">
        <div class="col-sm-12 col-xl-12">
            <div class="bg-light rounded h-100 p-4">
                <h6 class="mb-4">
                    添加账号
                    
                    <a href='{{ adminUrl("user") }}' class="ms-1" title="返回列表">
                        <i class="fa fa-arrow-circle-left"></i>
                    </a>
                </h6>
                
                <form class="profile-form">
                    <div class="mb-3">
                        <label for="usernameInput" class="form-label">
                            账号名称
                            <span class="text-danger">*</span>
                        </label>
                        <input type="text" 
                            name="username" 
                            value="" 
                            class="form-control" 
                            id="usernameInput" 
                            aria-describedby="usernameHelp">
                        <div id="usernameHelp" class="form-text">
                            账号的名称，包括大小写字母、数字、下划线及其组合
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="nicknameInput" class="form-label">
                            账号昵称
                            <span class="text-danger">*</span>
                        </label>
                        <input type="text" 
                            name="nickname" 
                            value="" 
                            class="form-control" 
                            id="nicknameInput" 
                            aria-describedby="nicknameHelp">
                        <div id="nicknameHelp" class="form-text">
                            账号的昵称
                        </div>
                    </div>
                    
                    <button type="button" 
                        class="btn btn-primary js-save-button">确认添加</button>
                </form>
            </div>

        </div>
    </div>
</div>

{{end}}

{{block script_after()}}
<script type="3029259e35d7bc1c98cd40a8-text/javascript">
(function($) {
    "use strict";
    
    $(".sidebar-user-index").addClass("active");
    
    // 保存
    $(".js-save-button").click(function(e) {
        e.stopPropagation;
        e.preventDefault;

        var username = $("[name=username]").val();
        var nickname = $("[name=nickname]").val();

        var url = '{{ adminUrl("user/add") }}';
        $.post(url, {
            username: username,
            nickname: nickname,
        }, function(data) {
            if (data.code == 0) {
                layer.msg("添加成功");
                
                setTimeout(function() {
                    window.location.reload();
                }, 1500);
            } else {
                layer.msg(data.message);
            }
        }).fail(function (xhr, status, info) {
            layer.msg("请求失败");
        });
    });

})(jQuery);
</script>
{{end}}