<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" th:href="@{/images/logo.jpg}"/>
    <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/js/layui/css/admin.css}">
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>

    <style>
        .layui-form-label {
            width: 150px;
        }
    </style>

</head>
<body>

<div class="layui-form" style="padding: 20px 0 0 0;">
    <form id="formId" onsubmit="return false;">
        <input type="hidden" name="userId" th:value="${obj.userId}">
        <div class="layui-form-item">
            <label class="layui-form-label">用户姓名</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.userName}" name="userName">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">用户电话</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" th:value="${obj.userPhone}" name="userPhone">
            </div>
        </div>
        <button class="layui-btn" style="display: none;" id="saveBtn" onclick="save()">保存</button>
    </form>
</div>

<script>

    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });

    function save() {
        var formdata = $("#formId").serialize()
        $.ajax({
            url: "updateUser",
            data: formdata,
            type: "POST",
            dataType: "json",
            success: function (result) {
                if (result.code == 100) {
                    layer.msg(result.msg, {icon: 6, time: 1000}, function () {
                        closeLayer();
                        parent.layui.table.reload('tableId');
                    });
                } else {
                    layer.msg(result.msg, {icon: 5});
                }
            }
        });
    }

    function closeLayer() {
        var index = parent.layer.getFrameIndex(window.name);
        //关闭当前frame
        parent.layer.close(index);
    }

</script>


</body>
</html>