{{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="{{ data.Username }}" 
                            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="{{ data.Nickname }}" 
                            class="form-control" 
                            id="nicknameInput" 
                            aria-describedby="nicknameHelp">
                        <div id="nicknameHelp" class="form-text">
                            账号的昵称
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="passwordInput" class="form-label">账号密码</label>
                        <input type="password" 
                            name="password" 
                            value="" 
                            class="form-control" 
                            id="passwordInput" 
                            autocomplete="false"
                            aria-describedby="passwordHelp">
                        <div id="passwordHelp" class="form-text">
                            更改账号的密码，为空不修改密码
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="signTextarea" class="form-label">账号签名</label>
                        <textarea class="form-control" 
                            name="sign"
                            placeholder="账号签名" 
                            id="signTextarea" 
                            style="height: 150px;"
                            aria-describedby="signHelp">{{ data.Sign }}</textarea>
                        <div id="signHelp" class="form-text">
                            账号的个人签名
                        </div>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">
                            账号状态
                            <span class="text-danger">*</span>
                        </label>
                        <div class="form-control">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" 
                                    type="radio" 
                                    name="status" 
                                    {{if data.Status == 1 }}
                                    checked=""
                                    {{end}}
                                    id="inlineRadioStatus1" 
                                    value="y">
                                <label class="form-check-label" 
                                    for="inlineRadioStatus1">启用</label>
                            </div>
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" 
                                    type="radio" 
                                    name="status" 
                                    {{if data.Status == 0 }}
                                    checked=""
                                    {{end}}
                                    id="inlineRadioStatus2" 
                                    value="n">
                                <label class="form-check-label" 
                                    for="inlineRadioStatus2">禁用</label>
                            </div>
                        </div>
                        <div 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 password = $("[name=password]").val();
        var sign = $("[name=sign]").val();
        var status = $("[name=status]:checked").val();

        var url = '{{ adminUrl("user/"+id+"/edit") }}';
        $.post(url, {
            username: username,
            nickname: nickname,
            password: password,
            sign: sign,
            status: status,
        }, 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}}