bayi 1 éve
szülő
commit
f47b8cbed0

+ 76 - 1
pages/commodity/index.js

@@ -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();
+    }
 })

+ 5 - 4
pages/commodity/index.less

@@ -1,10 +1,9 @@
 #container {
     overflow: hidden;
     width: 750rpx;
-    height: 3831rpx;
+    height: 3960rpx;
     background: url('http://reader-wx.ai160.com/images/reader/v3/bg.jpg') no-repeat;
-    background-size: 100% 100%;
-
+    background-size: 100% 3831rpx;
     .commoditys {
         display: flex;
         align-items: center;
@@ -19,7 +18,9 @@
         .commodity {
             position: relative;
             width: 192rpx;
+            background-clip: content-box !important;
             height: 192rpx;
+            border: 2px solid white;
             border-radius: 10rpx;
         }
 
@@ -75,7 +76,7 @@
         }
 
         .pay {
-            padding:14rpx 50rpx;
+            padding: 14rpx 50rpx;
             background: #ff9108;
             color: white;
             font-weight: 500;

+ 1 - 1
pages/commodity/index.wxml

@@ -22,7 +22,7 @@
             <span class="price">{{product.price/100}}</span>
         </view>
-        <view class="pay" bindtap="pay">立即支付</view>
+        <view class="pay" bindtap="toBuy">立即支付</view>
     </view>
     <view class="mask" wx:if="{{mask}}">
         <view class="payTips">

+ 4 - 2
pages/commodity/index.wxss

@@ -1,9 +1,9 @@
 #container {
   overflow: hidden;
   width: 750rpx;
-  height: 3831rpx;
+  height: 3960rpx;
   background: url('http://reader-wx.ai160.com/images/reader/v3/bg.jpg') no-repeat;
-  background-size: 100% 100%;
+  background-size: 100% 3831rpx;
 }
 #container .commoditys {
   display: flex;
@@ -19,7 +19,9 @@
 #container .commoditys .commodity {
   position: relative;
   width: 192rpx;
+  background-clip: content-box !important;
   height: 192rpx;
+  border: 2px solid white;
   border-radius: 10rpx;
 }
 #container .commoditys .active {

+ 3 - 3
utils/request.js

@@ -6,13 +6,13 @@ const {
         envVersion
     }
 } = wx.getAccountInfoSync();
-/* if (envVersion == 'develop') {
+if (envVersion == 'develop') {
     baseUrl = 'https://reader-api.efunbox.cn/wx'
     oldUrl = 'https://reader-api.efunbox.cn'
-} else { */
+} else {
     baseUrl = 'https://reader-api.ai160.com/wx'
     oldUrl = 'https://reader-api.ai160.com'
-// }
+}
 
 function request(url, method, data, oldBaseUrl = false, intercept = true) {
     let header = {