<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</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, maximum-scale=1">
    <link rel="stylesheet" href="{{domain}}/resource/admin/mini/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="{{domain}}/resource/admin/mini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    {{# udata}}
    <div class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名称</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" lay-reqtext="用户名称不能为空" placeholder="用户名称用于登录账户"
                    value="{{username}}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">用户昵称</label>
            <div class="layui-input-block">
                <input type="text" name="nickname" lay-verify="required" lay-reqtext="用户昵称不能为空" placeholder="用户昵称用于对外展示"
                    value="{{nickname}}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">状态</label>
            <div class="layui-input-block">
                {{# isok}}
                <input type="radio" name="usable" value="1" title="正常" checked="">
                <input type="radio" name="usable" value="2" title="封禁">
                {{/ isok}}
                {{^ isok}}
                <input type="radio" name="usable" value="1" title="正常">
                <input type="radio" name="usable" value="2" title="封禁" checked="">
                {{/ isok}}
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" lay-verify="email" lay-reqtext="邮箱不能为空" placeholder="请输入邮箱号"
                    value="{{email}}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">图像验证码</label>
            <div class="layui-input-inline">
                <img src="{{domain}}/admin/api/acode?from={{acfrom}}" id="acode" onclick="recode();" alt="验证码加载错误">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveBtn">更新数据</button>
            </div>
        </div>
    </div>
    {{/ udata}}
    </div>
    <script src="{{domain}}/resource/admin/mini/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>

    <script src="http://cdn.bootcss.com/ace/1.2.4/ace.js"></script>
    <script src="http://cdn.bootcss.com/ace/1.2.4/ext-language_tools.js"></script>
    <script src="http://cdn.bootcss.com/ace/1.2.4/ext-old_ie.js"></script>
    <script src="http://cdn.bootcss.com/ace/1.2.4/theme-monokai.js"></script>

    <script>
        function recode() {
            document.getElementById('acode').src = '{{domain}}/admin/api/acode?from={{acfrom}}';
        }

        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

            //监听提交
            form.on('submit(saveBtn)', function (data) {


                layer.prompt({
                    title: '请输入图形验证码:'
                }, function (val, index) {

                    $.post('{{domain}}/admin/api/user/upduser?from=edit.html', {
                        userid: '{{userid}}',
                        username: data.field.username,
                        nickname: data.field.nickname,
                        usable: data.field.usable,
                        email: data.field.email,
                        acode: val
                    }, function (res) {
                        if(res.data == 'OK'){
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            parent.window.location.reload();
                        }else{
                            layer.msg(res.msg + '...');
                        }
                    }).error(function(res){
                        layer.msg('操作异常：' + res.responseJSON.msg + '！');
                    });
                });

                return false;
            });

        });
    </script>
</body>

</html>