/** * Soul创业派对 - 我的代付 * Tab: 我发起的 / 我帮付的 */ const app = getApp() Page({ data: { statusBarHeight: 44, tab: 'requests', requests: [], payments: [], loading: false }, onLoad() { this.setData({ statusBarHeight: app.globalData.statusBarHeight || 44 }) this.loadData() }, onShow() { if (this.data.requests.length > 0 || this.data.payments.length > 0) { this.loadData() } }, switchTab(e) { const tab = e.currentTarget.dataset.tab || 'requests' this.setData({ tab }) this.loadData() }, async loadData() { const userId = app.globalData.userInfo?.id || '' if (!userId) { wx.showToast({ title: '请先登录', icon: 'none' }) return } this.setData({ loading: true }) try { if (this.data.tab === 'requests') { const res = await app.request(`/api/miniprogram/gift-pay/my-requests?userId=${encodeURIComponent(userId)}`) this.setData({ requests: (res && res.list) || [], loading: false }) } else { const res = await app.request(`/api/miniprogram/gift-pay/my-payments?userId=${encodeURIComponent(userId)}`) this.setData({ payments: (res && res.list) || [], loading: false }) } } catch (e) { this.setData({ loading: false }) } }, async cancelRequest(e) { const requestSn = e.currentTarget.dataset.sn if (!requestSn) return const ok = await new Promise(r => { wx.showModal({ title: '取消代付', content: '确定取消该代付请求?', success: res => r(res.confirm) }) }) if (!ok) return try { const res = await app.request({ url: '/api/miniprogram/gift-pay/cancel', method: 'POST', data: { requestSn, userId: app.globalData.userInfo?.id } }) if (res && res.success) { wx.showToast({ title: '已取消', icon: 'success' }) this.loadData() } else { wx.showToast({ title: res?.error || '取消失败', icon: 'none' }) } } catch (e) { wx.showToast({ title: '取消失败', icon: 'none' }) } }, shareRequest(e) { const requestSn = e.currentTarget.dataset.sn wx.showToast({ title: '请点击右上角「...」分享给好友', icon: 'none', duration: 2500 }) }, goBack() { app.goBackOrToHome() }, onShareAppMessage() { return { title: '我的代付 - Soul创业派对', path: '/pages/gift-pay/list' } } })