const $ = global; new $.Page({ data: { amount: 1, unitPrice: 599 }, minusAmount() { if (this.data.amount > 1) { this.setData({ amount: this.data.amount - 1 }); } }, addAmount() { this.setData({ amount: this.data.amount + 1 }); }, toPay() { const { name, phone, address, amount } = this.data; if (!name || !phone || !address || !amount) { return $.wx.showToast({ title: '请把信息填写完整' }); } if (!this._isPhone(phone)) { return $.wx.showToast({ title: '请输入正确的手机号码' }); } $.wx.showToast({ title: '购买中' }, 'loading'); $.request('product_order/store', 'POST', { amount, address, contact: name, phone, product_id: 1 }).then((res) => { if (res.data) { this.callWXPay(res.data.id, res.data.order_type || 'product_order'); } }); }, callWXPay(order_id, order_type) { $.request('payments/pay', 'POST', { order_id, order_type }).then((res) => { $.wx.hideToast('loading'); }); } });