<form class="layui-form  admin-form" lay-filter="testForm">
    <input type="hidden" name="clue_id" value="<?= $clueId ?>">
    <?php if (Yii::$app->user->identity->role === 'ADMIN'): ?>
        <div class="layui-form-item">
            <label class="layui-form-label">转化状态</label>
            <div class="layui-input-inline">
                <select name="convert_status" lay-filter="aihao">
                    <option value="1" <?= $covert_status == 1 ? 'selected' : '' ?>>合法转化</option>
                    <option value="2" <?= $covert_status == 2 ? 'selected' : '' ?>>待确认</option>
                    <option value="3" <?= $covert_status == 3 ? 'selected' : '' ?>>营销预览</option>
                    <option value="4" <?= $covert_status == 4 ? 'selected' : '' ?>>其他转化</option>
                </select>
            </div>
        </div>
    <?php endif; ?>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" value="<?= $name ?>" name="name" 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-block">
            <textarea name="note" placeholder="备注" class="layui-textarea" lay-verType="tips"><?= htmlspecialchars($note ?? '', ENT_QUOTES) ?></textarea>
        </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'], function () {
        var form = layui.form;

        console.log('form init ok');

        form.on('submit(save)', function (data) {
            console.log(data)
            $.ajax({
                url: '/api/update-clue',
                method: 'POST',
                data: {
                    clue_id: data.field.clue_id,
                    note: data.field.note,
                    name: data.field.name,
                    <?php if (Yii::$app->user->identity->role === 'ADMIN'): ?>
                        <?= 'convert_status: data.field.convert_status' ?>
                    <?php endif; ?>
                }
            })

            // ✅ 刷新父页面表格
            parent.layui.table.reload('clueTable');

            // ✅ 关闭当前弹窗
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);

            // 修复焦点 & 滚动锁
            parent.document.body.style.overflow = 'auto';
            parent.window.focus();
            return false;
        });
    });
</script>
