lifanagju_citu 4 mesi fa
parent
commit
b01c26b848
1 ha cambiato i file con 38 aggiunte e 37 eliminazioni
  1. 38 37
      pagesA/vipPackage/index.vue

+ 38 - 37
pagesA/vipPackage/index.vue

@@ -3,7 +3,7 @@
     <view class="vipBox">
       <view class="avatar">
         <img :src="getUserAvatar(baseInfo?.avatar, baseInfo?.sex)" alt="" class="img-box" :class="{'img-box-atc': userInfo?.vipExpireDate}">
-        <image v-if="userInfo.value?.vipExpireDate" src="/static/svg/vip.svg" class="vipIcon"></image>
+        <image v-if="userInfo?.vipExpireDate" src="/static/svg/vip.svg" class="vipIcon"></image>
       </view>
       <view class="nameBox">
         <view class="name font-weight-bold font-size-16">{{ baseInfo?.name || userInfo?.phone }}</view>
@@ -116,7 +116,8 @@ import { orderCreated, getOrder, getSocialUser, socialUserBind, payOrderSubmit }
 const useUserStore = userStore()
 
 const baseInfo = computed(() => useUserStore?.baseInfo)
-const userInfo = computed(() => useUserStore?.userInfo)
+// const userInfo = computed(() => useUserStore?.userInfo)
+const userInfo = ref(useUserStore?.userInfo || {})
 
 const memberList = ref([])
 const recommend = ref(null)
@@ -176,11 +177,9 @@ const radioChange = (index) => {
   payTypeCurrent.value = index
 }
 
-const chooseIndex = ref(0)
 const chooseItem = ref(null)
 const handleChoose = (val, index) => {
   chooseId.value = val.id
-  chooseIndex.value = index
   chooseItem.value = val
 }
 
@@ -274,36 +273,40 @@ const prepay = async (channel, orderData) => {
 }
 
 const weChatMiniProgramPay = async (orderData) => {
-    let res = await prepay('wx_lite', orderData); // 预支付
-    if (res?.code !== 0) {
-      return;
-    }
-    // 调用微信小程序支付
-    const payConfig = res?.data?.displayContent ? JSON.parse(res.data.displayContent) : null
-    if (!payConfig) return uni.showToast({ title: '购买失败', icon: 'none'})
-    uni.requestPayment({
-      provider: 'wxpay',
-      timeStamp: payConfig.timeStamp,
-      nonceStr: payConfig.nonceStr,
-      package: payConfig.packageValue,
-      signType: 'RSA',
-      paySign: payConfig.paySign,
-      success: (res) => {
-        popup.value.close()
-        uni.showToast({ title: '支付成功', icon: 'none'})
-        useUserStore.getUserInfo()
-        // this.payResult('success');
-      },
-      fail: (err) => {
-        if (err.errMsg === 'requestPayment:fail cancel') {
-          uni.showToast({ title: '支付已取消', icon: 'none'})
-        } else {
-          // this.payResult('fail');
-          uni.showToast({ title: '支付失败', icon: 'none'})
-        }
-      },
-    });
+  let res = await prepay('wx_lite', orderData); // 预支付
+  if (res?.code !== 0) {
+    return;
   }
+  // 调用微信小程序支付
+  const payConfig = res?.data?.displayContent ? JSON.parse(res.data.displayContent) : null
+  if (!payConfig) return uni.showToast({ title: '购买失败', icon: 'none'})
+  uni.requestPayment({
+    provider: 'wxpay',
+    timeStamp: payConfig.timeStamp,
+    nonceStr: payConfig.nonceStr,
+    package: payConfig.packageValue,
+    signType: 'RSA',
+    paySign: payConfig.paySign,
+    success: (res) => {
+      popup.value.close()
+      uni.showToast({ title: '支付成功', icon: 'none'})
+      setTimeout(async () => {
+        const _userInfo = await useUserStore.getUserInfo()
+        userInfo.value = _userInfo
+        getMemberList()
+      }, 1500)
+      // this.payResult('success');
+    },
+    fail: (err) => {
+      if (err.errMsg === 'requestPayment:fail cancel') {
+        uni.showToast({ title: '支付已取消', icon: 'none'})
+      } else {
+        // this.payResult('fail');
+        uni.showToast({ title: '支付失败', icon: 'none'})
+      }
+    },
+  });
+}
 
 // uni.showToast({ title: '支付升级中', icon: 'none'})
 // 支付
@@ -355,8 +358,6 @@ const getMemberList = async () => {
       }
       if (item.recommend) {
         recommend.value = index // 推荐套餐
-        chooseIndex.value = index
-        chooseItem.value = item
       }
       return {
         ...item,
@@ -371,9 +372,9 @@ const getMemberList = async () => {
     memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
     handleChoose(memberList.value[0], recommend.value)
     if ((!userInfo.value?.vipFlag || userInfo.value?.vipExpireDate - new Date().getTime() > 0 ) && typeof recommend.value === 'number') {
-      current.value = parseInt(recommend.value / 2)
+      // current.value = parseInt(recommend.value / 2)
+      current.value = vipFlagIndex === 0 ? 0 : parseInt((vipFlagIndex || recommend.value) / 2)
       chooseId.value = memberList.value[recommend.value]?.id
-      chooseIndex.value = recommend.value
       chooseItem.value = memberList.value[recommend.value]
     }
   } catch (error) {