1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import {
- buyVip,
- } from '~/api/user'
- import {
- getProducts
- } from '~/api/global'
- Page({
- data: {
- products: [],
- selected: {},
- activationModal: false,
- },
- onLoad(options) {
- this.getProducts()
- },
- onShow() {
- },
- async getProducts() {
- let products = await getProducts()
- console.log(products);
- this.setData({
- products,
- selected: products[0]
- })
- },
- checked({
- currentTarget
- }) {
- this.setData({
- selected: currentTarget.dataset.product
- })
- },
- activation() {
- this.setData({
- activationModal: true
- })
- },
- closeModal() {
- this.setData({
- activationModal: false
- })
- },
- async toBuy() {
- wx.showLoading({
- title: '提交中',
- mask: true
- })
- let res = await buyVip({
- productId: this.data.selected.id
- }).finally(() => {
- wx.hideLoading()
- })
- console.log(res);
- let {
- timeStamp,
- nonceStr,
- signType,
- paySign
- } = res
- // package保留字
- wx.requestPayment({
- timeStamp,
- nonceStr,
- package: res.package,
- signType,
- paySign,
- success(res) {
- wx.showToast({
- title: "支付成功",
- duration: 2500
- })
- setTimeout(() => {
- this.setUserInfo()
- }, 1500)
- },
- fail(res) {
- wx.showToast({
- title: "支付失败",
- icon: "none",
- duration: 3000
- })
- }
- })
- },
- })
|