|
@@ -1,3 +1,10 @@
|
|
|
+import {
|
|
|
+ androidbuyVip,
|
|
|
+ buyVip,
|
|
|
+} from '~/api/user'
|
|
|
+import {
|
|
|
+ userEvent
|
|
|
+} from '~/api/global'
|
|
|
Component({
|
|
|
/**
|
|
|
* 组件的属性列表
|
|
@@ -6,33 +13,136 @@ Component({
|
|
|
|
|
|
},
|
|
|
data: {
|
|
|
-
|
|
|
+ state: false,
|
|
|
+ product: {},
|
|
|
+ items: [{
|
|
|
+ value: 'wxpay',
|
|
|
+ name: '微信',
|
|
|
+ checked: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ value: 'alipay',
|
|
|
+ name: '支付宝',
|
|
|
+ checked: false
|
|
|
+ },
|
|
|
+ ]
|
|
|
},
|
|
|
methods: {
|
|
|
- open(
|
|
|
- currentTarget
|
|
|
- ) {
|
|
|
- /* if (currentTarget.dataset.isclick) {
|
|
|
+ open(product) {
|
|
|
+ if (!product) {
|
|
|
return
|
|
|
- } */
|
|
|
- this.getTabBar().setData({
|
|
|
- mask: true
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ product
|
|
|
})
|
|
|
// #if MP
|
|
|
+ this.toBuy()
|
|
|
// #elif ANDROID
|
|
|
- // #endif
|
|
|
- },
|
|
|
- showTranscript() {
|
|
|
this.getTabBar().setData({
|
|
|
mask: true
|
|
|
})
|
|
|
- this.selectComponent("#popUp").showModal()
|
|
|
+ this.setData({
|
|
|
+ state: true,
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+ radioChange(e) {
|
|
|
+ const items = this.data.items
|
|
|
+ for (let i = 0, len = items.length; i < len; ++i) {
|
|
|
+ items[i].checked = items[i].value === e.detail.value
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ items
|
|
|
+ })
|
|
|
},
|
|
|
closeTranscript() {
|
|
|
this.getTabBar().setData({
|
|
|
mask: false
|
|
|
})
|
|
|
- this.selectComponent("#popUp").hideModal()
|
|
|
+ this.setData({
|
|
|
+ state: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async toBuy() {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '提交中',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ // #if MP
|
|
|
+ let res = await buyVip({
|
|
|
+ productId: this.data.product.id
|
|
|
+ }).finally(() => {
|
|
|
+ wx.hideLoading()
|
|
|
+ })
|
|
|
+ userEvent({
|
|
|
+ action: 'ANDROID_PAY_ACTIVITY',
|
|
|
+ })
|
|
|
+ let {
|
|
|
+ timeStamp,
|
|
|
+ nonceStr,
|
|
|
+ signType,
|
|
|
+ paySign
|
|
|
+ } = res
|
|
|
+ // package保留字
|
|
|
+ wx.requestPayment({
|
|
|
+ timeStamp,
|
|
|
+ nonceStr,
|
|
|
+ package: res.package,
|
|
|
+ signType,
|
|
|
+ paySign,
|
|
|
+ success: async (res) => {
|
|
|
+ userEvent({
|
|
|
+ action: 'ANDROID_PAY_SUCCESS',
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ this.triggerEvent('reload')
|
|
|
+ this.closeTranscript()
|
|
|
+ }, 1500)
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "支付失败",
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // #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
|
|
|
+ })
|
|
|
+ },
|
|
|
+ complete: (res) => {
|
|
|
+ console.error('wx.miniapp.requestPayment complete:', res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ // #endif
|
|
|
},
|
|
|
}
|
|
|
})
|