bayi 2 rokov pred
rodič
commit
523425bb55

+ 9 - 5
pages/my/index.js

@@ -121,14 +121,15 @@ Page({
     async toBuy({
         currentTarget
     }) {
+        // return this.selectComponent('#vipModal').open({
+        //     type: 'svip'
+        // })
         wx.showLoading({
             title: '提交中',
             mask: true
         })
         let res = await buyVip({
             productId: currentTarget.dataset.id
-        }).finally(() => {
-            wx.hideLoading()
         })
         let {
             timeStamp,
@@ -144,11 +145,11 @@ Page({
             signType,
             paySign,
             success: (res) => {
-                this.selectComponent('#vipModal').open({
-                    type: 'svip'
-                })
                 setTimeout(() => {
                     this.setUserInfo()
+                    this.selectComponent('#vipModal').open({
+                        type: this.data.vipTime == '1' ? 'svip' : 'vip'
+                    })
                 }, 1500)
             },
             fail(res) {
@@ -157,6 +158,9 @@ Page({
                     icon: "none",
                     duration: 3000
                 })
+            },
+            complete: () => {
+                wx.hideLoading()
             }
         })
     },

+ 1 - 1
pages/my/index.less

@@ -210,7 +210,7 @@
             text-align: center;
             position: absolute;
             left: 90rpx;
-            top: 156rpx;
+            top: 160rpx;
             color: #39029B;
             font-size: 26rpx;
             font-weight: bold;

+ 1 - 0
pages/my/index.wxml

@@ -79,6 +79,7 @@
         <view class="renew">
             <view class="left">{{products[0].title}} <view class="money">+{{products[0].price/100}}元</view>
             </view>
+            <view class="pay" bindtap="toBuy" data-id="{{products[0].id}}">开通</view>
         </view>
         <view class="renew">
             <view class="left">{{products[1].title}} <view class="money">{{products[1].price/100}}元</view>

+ 1 - 1
pages/my/index.wxss

@@ -178,7 +178,7 @@
   text-align: center;
   position: absolute;
   left: 90rpx;
-  top: 156rpx;
+  top: 160rpx;
   color: #39029B;
   font-size: 26rpx;
   font-weight: bold;

+ 62 - 2
pages/reading/buyVip/index.js

@@ -1,3 +1,9 @@
+import {
+    getProducts
+} from '~/api/global'
+import {
+    buyVip,
+} from '~/api/user'
 Component({
     /**
      * 组件的属性列表
@@ -11,15 +17,19 @@ Component({
      */
     data: {
         show: false,
-        vipTime: ''
+        vipTime: '',
+        products: []
     },
 
     /**
      * 组件的方法列表
      */
     methods: {
-        open(vipTime) {
+        open({
+            vipTime
+        }) {
             console.log(vipTime);
+            this.getProducts()
             this.setData({
                 show: true,
                 vipTime
@@ -30,5 +40,55 @@ Component({
                 show: false
             })
         },
+        async toBuy({
+            currentTarget
+        }) {
+            wx.showLoading({
+                title: '提交中',
+                mask: true
+            })
+            let res = await buyVip({
+                productId: currentTarget.dataset.id
+            }).finally(() => {
+                wx.hideLoading()
+            })
+            let {
+                timeStamp,
+                nonceStr,
+                signType,
+                paySign
+            } = res
+            // package保留字
+            wx.requestPayment({
+                timeStamp,
+                nonceStr,
+                package: res.package,
+                signType,
+                paySign,
+                success: (res) => {
+                    this.selectComponent('#vipModal').open({
+                        type: 'svip'
+                    })
+                    setTimeout(() => {
+                        this.setUserInfo()
+                    }, 1500)
+                },
+                fail(res) {
+                    wx.showToast({
+                        title: "支付失败",
+                        icon: "none",
+                        duration: 3000
+                    })
+                }
+            })
+        },
+        async getProducts() {
+            let {
+                productList: products,
+            } = await getProducts()
+            this.setData({
+                products,
+            })
+        },
     }
 })

+ 6 - 6
pages/reading/buyVip/index.wxml

@@ -4,17 +4,17 @@
             <view class="h1">您还不是VIP会员</view>
             <view>选择下面的会员卡开通后使用!</view>
         </view>
-        <!-- <template> -->
-        <view class="payBox">
-        </view>
-        <view class="payBox payBox2">
-            <!--    <view class="buyBtn" bindtap="toBuy" data-id="{{products[1].id}}" wx:if="{{!vipTime}}">立即开通
+        <view wx:if="{{!vipTime}}">
+            <view class="payBox" bindtap="toBuy" data-id="{{products[0].id}}">
+            </view>
+            <view class="payBox payBox2" bindtap="toBuy" data-id="{{products[1].id}}">
+                <!--    <view class="buyBtn" bindtap="toBuy" data-id="{{products[1].id}}" wx:if="{{!vipTime}}">立即开通
                 </view>
                 <view class="buyBtn" style="font-size: 22rpx;" wx:else>
                     有效期:{{filters.formatDate(vipTime,5)}}
                 </view> -->
+            </view>
         </view>
-        <!-- </template> -->
     </view>
     <image src="/static/lollipop.png" class="close" catchtap="closeModal" />
 </view>