const api = require("../../utils/api"); Page({ data: { a: false, b: false, ok: false, loading: false }, onLoad() { if (!api.requireLogin()) return; }, toggle(e) { const key = e.currentTarget.dataset.k; const next = {}; next[key] = !this.data[key]; this.setData(next, () => this.setData({ ok: this.data.a && this.data.b })); }, onOk() { if (!this.data.ok || this.data.loading) return; this.setData({ loading: true }); api .post("/api/consent", { version: "v1" }) .then(() => wx.reLaunch({ url: "/pages/children/children" })) .catch((e) => { api.toastError(e); this.setData({ loading: false }); }); }, });