
<form class="layui-form admin-form" lay-filter="testForm">
    <?php foreach ($arr as $accountName => $item): ?>
        <h3 class="ws-bold"><?= $accountName ?></h3>
        <div class="layui-form">
            <div class="layui-form-item">
                <?php foreach ($item['items'] as $childItem): ?>
                    <input type="checkbox"
                           name="advertiser_ids[]"
                           value="<?= $childItem['id'] . '|' . $item['id'] ?>"
                           title="<?= $childItem['advertiser_name'] ?>"
                        <?= $childItem['is_active'] == 1 ? 'checked' : '' ?>
                           lay-filter="demo-checkbox-filter">
                <?php endforeach; ?>
            </div>
        </div>
    <?php endforeach; ?>
    <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/oauth-account-local-update',
                method: 'POST',
                data: data.field,
                success: function (res) {
                    if (res.code != 0) {
                        layer.msg(res.message)
                        return
                    }
                    layer.close(loadIndex)
                    // ✅ 刷新父页面表格
                    parent.layui.table.reload('clueTable');

                    // ✅ 关闭当前弹窗
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            })
            layer.closeAll()
            return false;
        });
    });
</script>