12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import {
- buyVip,
- buyNum,
- } from '~/api/user'
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- },
- /**
- * 组件的初始数据
- */
- data: {
- state: false
- },
- /**
- * 组件的方法列表
- */
- methods: {
- open() {
- this.setData({
- state: true
- })
- },
- close() {
- this.setData({
- state: false
- })
- },
- //购买vip和购买次数不是一个接口 type 1001是vip,1010是次数
- async toBuy({
- currentTarget
- }) {
- let productId = currentTarget.dataset.type
- wx.showLoading({
- title: '提交中',
- mask: true
- })
- let res = ''
- if (productId == '1001') {
- res = await buyVip({
- productId
- }).finally(() => {
- wx.hideLoading()
- })
- } else if (productId == '1010') {
- res = await buyNum({
- productId
- }).finally(() => {
- wx.hideLoading()
- })
- } else {
- wx.hideLoading()
- wx.showToast({
- title: "支付失败,请重试",
- icon: "none"
- })
- }
- let {
- timeStamp,
- nonceStr,
- signType,
- paySign
- } = res
- // package保留字
- wx.requestPayment({
- timeStamp,
- nonceStr,
- package: res.package,
- signType,
- paySign,
- success(res) {
- wx.showToast({
- title: "支付成功",
- duration: 2500
- })
- },
- fail(res) {
- wx.showToast({
- title: "支付失败",
- icon: "none"
- })
- }
- })
- },
- }
- })
|