12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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
- })
- },
- closeModal() {
- this.setData({
- activationModal: false
- })
- },
- 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) => {
- this.setData({
- activationModal: true
- })
- setTimeout(() => {
- this.setUserInfo()
- }, 1500)
- },
- fail(res) {
- wx.showToast({
- title: "支付失败",
- icon: "none",
- duration: 3000
- })
- }
- })
- },
- })
|