<form class="layui-form admin-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" value="<?= $query['username'] ?>" name="username" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="password" lay-verify="required" autocomplete="off" lay-affix="clear" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item text-right">
        <button type="submit"
                class="layui-btn"
                lay-submit
                lay-filter="save">
            提交
        </button>
    </div>
</form>


<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form;
        var layer = layui.layer;
        console.log('form init ok');

        form.on('submit(save)', function (data) {
            var loadIndex = layer.load();

            // console.log(data.field);
            $.ajax({
                url: '/api/user/create',
                method: 'POST',
                data: data.field,
                success: function (res) {
                    console.log(res)
                    if (res.code != 0) {
                        layer.msg(res.msg);
                        return;
                    }
                    // ✅ 刷新父页面表格
                    parent.layui.table.reload('clueTable');

                    // ✅ 关闭当前弹窗
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                },
                complete: function () {
                    layer.close(loadIndex)
                }
            })

            return false;
        });
    });
</script>
