import { buyVip, } from '~/api/user' import { getProducts } from '~/api/global' Page({ data: { products: [], selected: {}, activationModal: false, }, onLoad(options) { this.getProducts() }, async getProducts() { let products = await getProducts() console.log(products); this.setData({ products, selected: products[0] }) }, checked({ currentTarget }) { this.setData({ selected: currentTarget.dataset.product }) }, closeModal() { this.setData({ activationModal: false }) wx.navigateBack() }, async toBuy() { wx.showLoading({ title: '提交中', mask: true }) let res = await buyVip({ productId: this.data.selected.id }).finally(() => { wx.hideLoading() }) let { timeStamp, nonceStr, signType, paySign } = res // package保留字 wx.requestPayment({ timeStamp, nonceStr, package: res.package, signType, paySign, success: (res) => { console.log(res); this.setData({ activationModal: true }) /* setTimeout(() => { this.setUserInfo() }, 1500) */ }, fail(res) { wx.showToast({ title: "支付失败", icon: "none", duration: 3000 }) } }) }, /* // 设置用户信息及vip状态 async setUserInfo() { let userInfo = await getMyInfo() let vipTime = await getVipInfo() this.setUser(userInfo.user) this.setData({ userInfo, vipTime, }) }, */ })