const api = require("../../utils/api"); Page({ data: { numbers: null, weakest: [], oneLine: "", printUrl: "", loading: true, }, onShow() { if (!api.requireChild()) return; this.load(); }, load() { const child = getApp().globalData.child; api .get("/api/report/weekly?child_id=" + child.id) .then((d) => { this.setData({ numbers: d.numbers, weakest: d.weakest || [], oneLine: d.one_line || "", printUrl: getApp().globalData.apiBase + "/api/print/weekly?child_id=" + child.id + "&token=" + encodeURIComponent(api.token()), loading: false, }); }) .catch((e) => { api.toastError(e); this.setData({ loading: false }); }); }, onPrint() { wx.navigateTo({ url: "/pages/print/print?url=" + encodeURIComponent(this.data.printUrl) }); }, });