Quellcode durchsuchen

会员充值方式

lifanagju_citu vor 4 Monaten
Ursprung
Commit
84864da9d6
4 geänderte Dateien mit 132 neuen und 34 gelöschten Zeilen
  1. 28 1
      api/common.js
  2. 100 33
      pagesA/vipPackage/index.vue
  3. BIN
      static/iconfont.ttf
  4. 4 0
      static/iconfont.wxss

+ 28 - 1
api/common.js

@@ -350,7 +350,8 @@ export const getSubscribeTemplateList = async () => {
 // 求职端交易订单  创建
 export const orderCreated = async (data) => {
   return request({
-    url: '/app-api/menduner/system/trade/order/create',
+    // url: '/app-api/menduner/system/trade/order/create',
+    url: '/app-api/menduner/system/trade/order/wx-program/create',
     method: 'POST',
     data,
     custom: {
@@ -387,6 +388,32 @@ export const getSocialUser = async (type) => {
   })
 }
 
+//  获得支付订单 (轮巡支付状态)
+export const getOrderPayStatus = async (params) => {
+  return request({
+    url: '/app-api/pay/order/get',
+    method: 'GET',
+    params,
+    custom: {
+      showLoading: false,
+      auth: true
+    }
+  })
+}
+
+// 获得指定应用的开启的支付渠道编码列表
+export const getEnableCodeList = async (params) => {
+  return request({
+    url: '/app-api/pay/channel/get-enable-code-list',
+    method: 'GET',
+    params,
+    custom: {
+      showLoading: false,
+      auth: true
+    }
+  })
+}
+
 // 提交支付订单
 export const payOrderSubmit = async (data) => {
   return request({

+ 100 - 33
pagesA/vipPackage/index.vue

@@ -79,15 +79,15 @@
             </view>
           </view>
           <view class="popup-content-main-type">
-            <view class="card">
+            <view v-if="showPayMethods" class="card">
               <radio-group @change="radioChange">
-                <label class="card-label" v-for="(item, index) in payType" :key="item.value">
+                <label class="card-label" v-for="item in payTypeList" :key="item.value">
                   <view class="name">
                     <uni-icons :color="item.color" class="mr-1" :type="item.icon" size="24" custom-prefix="iconfont"></uni-icons>
                     {{item.name}}
                   </view>
                   <view>
-                    <radio :value="item.value" :checked="index === payTypeCurrent" />
+                    <radio :value="item.value" :disabled="item.disabled" :checked="item.checked" />
                   </view>
                 </label>
               </radio-group>
@@ -107,11 +107,12 @@
 </template>
 
 <script setup>
+import { onHide, onShow } from '@dcloudio/uni-app';
 import { ref, computed } from 'vue'
 import { getUserAvatar } from '@/utils/avatar'
 import { userStore } from '@/store/user'
 import { getMembershipPackageList } from '@/api/vip'
-import { orderCreated, getOrder, getSocialUser, socialUserBind, payOrderSubmit } from '@/api/common'
+import { orderCreated, getOrder, getSocialUser, socialUserBind, payOrderSubmit, getOrderPayStatus, getEnableCodeList } from '@/api/common'
 const useUserStore = userStore()
 
 const baseInfo = computed(() => useUserStore?.baseInfo)
@@ -121,6 +122,7 @@ const userInfo = ref(useUserStore?.userInfo || {})
 const memberList = ref([])
 const recommend = ref(null)
 const chooseId = ref(null)
+const orderInfo = ref(null)
 
 const popup = ref()
 
@@ -154,20 +156,27 @@ const list = computed(() => {
 })
 
 const current = ref(0)
-const payType = ref([
+const payType = [
   {
     name: '微信支付',
     value: 'wx_lite',
     icon: 'icon-weixinzhifu',
     color: '#1AAD19'
+  },
+  {
+    name: '钱包支付',
+    value: 'wallet',
+    disabled: true,
+    icon: 'icon-qianbao1',
+    // color: '#fd9702'
+    color: '#00897B'
   }
-])
+]
 
-const payTypeCurrent = ref(0)
-const channel = ref('')
-const radioChange = (index) => {
-  channel.value = payType[index].value
-  payTypeCurrent.value = index
+const channelValue = ref('')
+const radioChange = (e) => {
+  channelValue.value = e?.detail?.value || ''
+  // console.log('channelValue:',channelValue.value)
 }
 
 const chooseItem = ref(null)
@@ -244,6 +253,7 @@ const prepay = async (channel, orderData) => {
         bindWeiXin()
         return
       }
+      // console.log('openid:', openid)
       data.channelExtras.openid = openid
     }
     // 发起预支付 API 调用
@@ -264,8 +274,46 @@ const prepay = async (channel, orderData) => {
   })
 }
 
+let interTimer = null
+let payLoading = false
+const checkPayStatus = async (id) => {
+  if (!id) return
+  try {
+    if (payLoading || !interTimer) return
+    payLoading = true
+    const res = await getOrderPayStatus({ id })
+    if (res?.data?.status === 10) {
+      if (interTimer) clearInterval(interTimer)
+      // emit('paySuccess')
+      setTimeout(async () => {
+        const _userInfo = await useUserStore.getUserInfo()
+        userInfo.value = _userInfo
+        getMemberList() // 刷新套餐列表
+      }, 1500)
+    }
+  } catch (error) {
+    console.log(error)
+  } finally {
+    payLoading = false
+  }
+}
+
+// 计时器
+const initIntervalFun = () => {
+  if (interTimer) clearInterval(interTimer)
+
+  // 查询是否已经支付
+  const id = orderInfo.value?.payOrder?.id || orderInfo.value?.order?.payOrderId
+  if (id) {
+    interTimer = setInterval(() => {
+      checkPayStatus(id)
+    }, 1000)
+  }
+}
+
 const weChatMiniProgramPay = async (orderData) => {
-  let res = await prepay('wx_lite', orderData); // 预支付
+  orderInfo.value = orderData
+  let res = await prepay(channelValue.value, orderData); // 预支付
   if (res?.code !== 0) {
     return;
   }
@@ -280,14 +328,9 @@ const weChatMiniProgramPay = async (orderData) => {
     signType: 'RSA',
     paySign: payConfig.paySign,
     success: (res) => {
+      initIntervalFun()
       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') {
@@ -302,6 +345,10 @@ const weChatMiniProgramPay = async (orderData) => {
 
 // 支付
 const handlePay = async () => {
+  if (!channelValue.value) {
+    uni.showToast({ title: '请选择支付方式', icon: 'none'})
+    return
+  }
   const val = chooseItem.value
   try {
     const res = await getOrder({
@@ -359,27 +406,47 @@ const getMemberList = async () => {
         loading: false
       }
     })
-    // 低于当前套餐的(套餐)不展示
-    memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list
-    if ((!userInfo.value?.vipFlag || userInfo.value?.vipExpireDate - new Date().getTime() > 0 ) && typeof recommend.value === 'number') {
-      current.value = vipFlagIndex === 0 ? 0 : parseInt((vipFlagIndex || recommend.value) / 2)
-    }
-    // 设置选中项
-    const chooseIndex = vipFlagIndex !== null ? vipFlagIndex : recommend.value
-    handleChoose(memberList.value[chooseIndex])
+
+    memberList.value = vipFlagIndex ? list.slice(vipFlagIndex) : list // 低于当前套餐的(套餐)不展示
+    // 轮播current位置
+    // if ((!userInfo.value?.vipFlag || userInfo.value?.vipExpireDate - new Date().getTime() > 0 ) && typeof recommend.value === 'number') {
+    //   current.value = parseInt(recommend.value/2)
+    // }
+    handleChoose(memberList.value[0]) // 已购买或者未购买都选中第一个
   } catch (error) {
     uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
   }
 }
 getMemberList()
 
-// const getPayMethodsList = async () => {
-//   try {
-//   } catch (error) {
-//     // uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
-//   }
-// }
-// getPayMethodsList()
+onShow(() => {
+  if (orderInfo && orderInfo.value?.id) initIntervalFun()
+})
+onHide(() => {
+  if (interTimer) clearInterval(interTimer)
+})
+
+// 余额和其他还没有接暂时只支持微信支付
+let payTypeList = []
+const showPayMethods = ref(false)
+// 获取支付方式
+const getPayMethodsList = async () => {
+  showPayMethods.value = false
+  payTypeList = []
+  try {
+    const res = await getEnableCodeList({appId: 14})
+    if (!res?.data?.length) {
+      return
+    }
+    payTypeList.push(...payType.filter(e => res.data.includes(e.value)))
+    const result = payType.find(item => !item.disabled && item.value)
+    if (result) channelValue.value = result.value
+    showPayMethods.value = true
+  } catch (error) {
+    console.log(error)
+  }
+}
+getPayMethodsList()
 
 </script>
 

BIN
static/iconfont.ttf


+ 4 - 0
static/iconfont.wxss

@@ -11,6 +11,10 @@
   -moz-osx-font-smoothing: grayscale;
 }
 
+.icon-qianbao1:before {
+  content: "\e607";
+}
+
 .icon-weixinzhifu:before {
   content: "\e6e8";
 }