var http = require('../../utils/request') Page({ data: { plans: [ { plan: 'monthly', price: '¥99', desc: '约3.3元/天' }, { plan: 'yearly', price: '¥899', desc: '省¥289' } ], selected: 'yearly', purchasing: false }, onSelect: function (e) { this.setData({ selected: e.currentTarget.dataset.plan }) }, onPurchase: function () { var self = this if (!self.data.selected) { wx.showToast({ title: '请选择套餐', icon: 'none' }) return } self.setData({ purchasing: true }) http.post('/api/v1/subscription/purchase', { plan: self.data.selected, payment_method: 'wechat' }).then(function (data) { return http.post('/api/v1/subscription/verify', { order_id: data.order_id, plan: self.data.selected }) }).then(function () { self.setData({ purchasing: false }) wx.redirectTo({ url: '/pages/subscribe-success/subscribe-success' }) }).catch(function () { self.setData({ purchasing: false }) wx.showToast({ title: '购买失败', icon: 'none' }) }) } })