|
@@ -1,6 +1,16 @@
|
|
|
import {
|
|
|
+ createStoreBindings
|
|
|
+} from 'mobx-miniprogram-bindings'
|
|
|
+import {
|
|
|
+ store
|
|
|
+} from '~/store/index'
|
|
|
+import {
|
|
|
getProducts,
|
|
|
+ userEvent
|
|
|
} from '~/api/global'
|
|
|
+import {
|
|
|
+ buyVip,
|
|
|
+} from '~/api/user'
|
|
|
import event from '~/mixins/event'
|
|
|
|
|
|
Page({
|
|
@@ -10,6 +20,15 @@ Page({
|
|
|
product: {},
|
|
|
mask: false
|
|
|
},
|
|
|
+ onLoad() {
|
|
|
+ // 手工绑定
|
|
|
+ this.storeBindings = createStoreBindings(this, {
|
|
|
+ store,
|
|
|
+ actions: {
|
|
|
+ setUser: 'setUser'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
onShow() {
|
|
|
this.getProducts()
|
|
|
},
|
|
@@ -26,16 +45,72 @@ Page({
|
|
|
selected({
|
|
|
currentTarget
|
|
|
}) {
|
|
|
- console.log(currentTarget.dataset.product);
|
|
|
this.setData({
|
|
|
active: currentTarget.dataset.product.id,
|
|
|
product: currentTarget.dataset.product
|
|
|
})
|
|
|
},
|
|
|
+ async toBuy() {
|
|
|
+ if (!this.data.active) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ wx.showLoading({
|
|
|
+ title: '提交中',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ let res = await buyVip({
|
|
|
+ productId: this.data.active
|
|
|
+ }).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) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ this.setUserInfo()
|
|
|
+ this.setData({
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ }, 1500)
|
|
|
+ userEvent({
|
|
|
+ action: 'ANDROID_PAY_SUCCESS',
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "支付失败",
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 设置用户信息及vip状态
|
|
|
+ async setUserInfo() {
|
|
|
+ let userInfo = await getMyInfo()
|
|
|
+ this.setUser(userInfo.user)
|
|
|
+ },
|
|
|
closeMask() {
|
|
|
this.setData({
|
|
|
mask: false,
|
|
|
})
|
|
|
// this.getWxCode()
|
|
|
},
|
|
|
+ onUnload() {
|
|
|
+ this.storeBindings.destroyStoreBindings();
|
|
|
+ }
|
|
|
})
|