<!DOCTYPE html>
<html>
<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, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" id="form_view_id">
</div>
</div>
    <script id="form_tpl_id" type="text/html">
        <input type="hidden" name="id" value="{{d.id}}" />

    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input type="text" name="username" disabled="" readonly="true" lay-reqtext="账号不能为空" placeholder="账号" value="{{=d.username}}" class="layui-input">
		<tip>账号不能修改</tip>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" placeholder="请输入密码，不提供不修改" class="layui-input">
		<tip>修改密码，不提供不修改</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">昵称</label>
        <div class="layui-input-block">
            <input type="text" name="nickname" placeholder="" value="{{=d.nickname}}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" name="mobile"  placeholder="手机号" value="{{=d.mobile}}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" placeholder="邮箱" value="{{=d.email}}" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="1" title="男" {{# if (d.state == 1) }} checked="" {{# }}>
            <input type="radio" name="sex" value="2" title="女" {{# if (d.state == 2) }} checked="" {{# }}>
            <input type="radio" name="sex" value="0" title="未知" {{# if (d.state == 0) }} checked="" {{# }}>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
    </script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['laytpl', 'form'], function () {
        var form = layui.form,
            layer = layui.layer,
            router = layui.router(),
            laytpl = layui.laytpl,
            $ = layui.$;

        var id = sessionStorage.getItem('edit_id'); // router.search.id
        $.getJSON('/?s=Portal.User_User.GetData&id=' + id, function (data) {
            if (data.ret != 200 || !data.data.data) {
                layer.msg(data.msg || '用户不存在或已经删除');
            }

            var getTpl = form_tpl_id.innerHTML,
                view = document.getElementById('form_view_id');

            laytpl(getTpl).render(data.data.data, function(html){
                view.innerHTML = html;
              	form.render('radio');
            });
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: '/?s=Portal.User_User.UpdateData',
                type:'post',
                data: {data: JSON.stringify(data.field), id: data.field.id},
                success:function(data){
                    if (data.ret != 200) {
                        layer.msg(data.msg);
                        return;
                    }

                    var index = layer.alert('更新成功，请刷新', function () {
                        // 关闭弹出层
                        layer.close(index);

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);

                        //window.location.reload();
                    });
                },
                complete: function () {
                }
            });

            return false;
        });

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