|
@@ -1,10 +1,12 @@
|
|
|
import {
|
|
|
androidbuyVip,
|
|
|
+ aliPay,
|
|
|
buyVip,
|
|
|
} from '~/api/user'
|
|
|
import {
|
|
|
userEvent
|
|
|
} from '~/api/global'
|
|
|
+let app = getApp()
|
|
|
Component({
|
|
|
/**
|
|
|
* 组件的属性列表
|
|
@@ -15,6 +17,7 @@ Component({
|
|
|
data: {
|
|
|
state: false,
|
|
|
product: {},
|
|
|
+ type: "wxpay",
|
|
|
items: [{
|
|
|
value: 'wxpay',
|
|
|
name: '微信',
|
|
@@ -52,7 +55,8 @@ Component({
|
|
|
items[i].checked = items[i].value === e.detail.value
|
|
|
}
|
|
|
this.setData({
|
|
|
- items
|
|
|
+ items,
|
|
|
+ type: e.detail.value
|
|
|
})
|
|
|
},
|
|
|
closeTranscript() {
|
|
@@ -64,11 +68,11 @@ Component({
|
|
|
})
|
|
|
},
|
|
|
async toBuy() {
|
|
|
+ // #if MP
|
|
|
wx.showLoading({
|
|
|
title: '提交中',
|
|
|
mask: true
|
|
|
})
|
|
|
- // #if MP
|
|
|
let res = await buyVip({
|
|
|
productId: this.data.product.id
|
|
|
}).finally(() => {
|
|
@@ -108,40 +112,57 @@ Component({
|
|
|
}
|
|
|
})
|
|
|
// #elif ANDROID
|
|
|
- let res = await androidbuyVip({
|
|
|
- productId: this.data.product.id
|
|
|
- }).finally(() => {
|
|
|
- wx.hideLoading()
|
|
|
- })
|
|
|
- wx.miniapp.requestPayment({
|
|
|
- timeStamp: res.timestamp,
|
|
|
- mchId: res.partnerid,
|
|
|
- prepayId: res.prepayid,
|
|
|
- package: res.package,
|
|
|
- nonceStr: res.noncestr,
|
|
|
- sign: res.sign,
|
|
|
- success: async (res) => {
|
|
|
- /* setTimeout(() => {
|
|
|
- this.setUserInfo()
|
|
|
- this.setData({
|
|
|
- mask: true
|
|
|
- })
|
|
|
- }, 1500)
|
|
|
- userEvent({
|
|
|
- action: 'ANDROID_PAY_SUCCESS',
|
|
|
- }) */
|
|
|
- },
|
|
|
- fail(res) {
|
|
|
- wx.showToast({
|
|
|
- title: "支付失败",
|
|
|
- icon: "none",
|
|
|
- duration: 3000
|
|
|
+ if (this.data.type == 'wxPay') {
|
|
|
+ let res = await androidbuyVip({
|
|
|
+ productId: this.data.product.id
|
|
|
+ }).finally(() => {
|
|
|
+ wx.hideLoading()
|
|
|
+ })
|
|
|
+ wx.miniapp.requestPayment({
|
|
|
+ timeStamp: res.timestamp,
|
|
|
+ mchId: res.partnerid,
|
|
|
+ prepayId: res.prepayid,
|
|
|
+ package: res.package,
|
|
|
+ nonceStr: res.noncestr,
|
|
|
+ sign: res.sign,
|
|
|
+ success: async (res) => {
|
|
|
+ userEvent({
|
|
|
+ action: 'ANDROID_PAY_SUCCESS',
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ this.triggerEvent('reload')
|
|
|
+ this.closeTranscript()
|
|
|
+ }, 1500)
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "支付失败",
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ },
|
|
|
+ complete: (res) => {
|
|
|
+ console.error('wx.miniapp.requestPayment complete:', res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ let res = await aliPay({
|
|
|
+ productId: this.data.product.id
|
|
|
+ }).finally(() => {
|
|
|
+ wx.hideLoading()
|
|
|
+ })
|
|
|
+ app.globalData.plugin.aliPay({
|
|
|
+ orderInfo: res
|
|
|
+ }, (res) => {
|
|
|
+ userEvent({
|
|
|
+ action: 'ANDROID_PAY_SUCCESS',
|
|
|
})
|
|
|
- },
|
|
|
- complete: (res) => {
|
|
|
- console.error('wx.miniapp.requestPayment complete:', res)
|
|
|
- }
|
|
|
- })
|
|
|
+ setTimeout(() => {
|
|
|
+ this.triggerEvent('reload')
|
|
|
+ this.closeTranscript()
|
|
|
+ }, 1500)
|
|
|
+ })
|
|
|
+ }
|
|
|
// #endif
|
|
|
},
|
|
|
}
|