|
@@ -79,15 +79,15 @@
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="popup-content-main-type">
|
|
<view class="popup-content-main-type">
|
|
- <view class="card">
|
|
|
|
|
|
+ <view v-if="showPayMethods" class="card">
|
|
<radio-group @change="radioChange">
|
|
<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">
|
|
<view class="name">
|
|
<uni-icons :color="item.color" class="mr-1" :type="item.icon" size="24" custom-prefix="iconfont"></uni-icons>
|
|
<uni-icons :color="item.color" class="mr-1" :type="item.icon" size="24" custom-prefix="iconfont"></uni-icons>
|
|
{{item.name}}
|
|
{{item.name}}
|
|
</view>
|
|
</view>
|
|
<view>
|
|
<view>
|
|
- <radio :value="item.value" :checked="index === payTypeCurrent" />
|
|
|
|
|
|
+ <radio :value="item.value" :disabled="item.disabled" :checked="item.checked" />
|
|
</view>
|
|
</view>
|
|
</label>
|
|
</label>
|
|
</radio-group>
|
|
</radio-group>
|
|
@@ -107,11 +107,12 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
|
+import { onHide, onShow } from '@dcloudio/uni-app';
|
|
import { ref, computed } from 'vue'
|
|
import { ref, computed } from 'vue'
|
|
import { getUserAvatar } from '@/utils/avatar'
|
|
import { getUserAvatar } from '@/utils/avatar'
|
|
import { userStore } from '@/store/user'
|
|
import { userStore } from '@/store/user'
|
|
import { getMembershipPackageList } from '@/api/vip'
|
|
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 useUserStore = userStore()
|
|
|
|
|
|
const baseInfo = computed(() => useUserStore?.baseInfo)
|
|
const baseInfo = computed(() => useUserStore?.baseInfo)
|
|
@@ -121,6 +122,7 @@ const userInfo = ref(useUserStore?.userInfo || {})
|
|
const memberList = ref([])
|
|
const memberList = ref([])
|
|
const recommend = ref(null)
|
|
const recommend = ref(null)
|
|
const chooseId = ref(null)
|
|
const chooseId = ref(null)
|
|
|
|
+const orderInfo = ref(null)
|
|
|
|
|
|
const popup = ref()
|
|
const popup = ref()
|
|
|
|
|
|
@@ -154,20 +156,27 @@ const list = computed(() => {
|
|
})
|
|
})
|
|
|
|
|
|
const current = ref(0)
|
|
const current = ref(0)
|
|
-const payType = ref([
|
|
|
|
|
|
+const payType = [
|
|
{
|
|
{
|
|
name: '微信支付',
|
|
name: '微信支付',
|
|
value: 'wx_lite',
|
|
value: 'wx_lite',
|
|
icon: 'icon-weixinzhifu',
|
|
icon: 'icon-weixinzhifu',
|
|
color: '#1AAD19'
|
|
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)
|
|
const chooseItem = ref(null)
|
|
@@ -244,6 +253,7 @@ const prepay = async (channel, orderData) => {
|
|
bindWeiXin()
|
|
bindWeiXin()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ // console.log('openid:', openid)
|
|
data.channelExtras.openid = openid
|
|
data.channelExtras.openid = openid
|
|
}
|
|
}
|
|
// 发起预支付 API 调用
|
|
// 发起预支付 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) => {
|
|
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) {
|
|
if (res?.code !== 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -280,14 +328,9 @@ const weChatMiniProgramPay = async (orderData) => {
|
|
signType: 'RSA',
|
|
signType: 'RSA',
|
|
paySign: payConfig.paySign,
|
|
paySign: payConfig.paySign,
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
|
+ initIntervalFun()
|
|
popup.value.close()
|
|
popup.value.close()
|
|
uni.showToast({ title: '支付成功', icon: 'none'})
|
|
uni.showToast({ title: '支付成功', icon: 'none'})
|
|
- setTimeout(async () => {
|
|
|
|
- const _userInfo = await useUserStore.getUserInfo()
|
|
|
|
- userInfo.value = _userInfo
|
|
|
|
- getMemberList()
|
|
|
|
- }, 1500)
|
|
|
|
- // this.payResult('success');
|
|
|
|
},
|
|
},
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
if (err.errMsg === 'requestPayment:fail cancel') {
|
|
if (err.errMsg === 'requestPayment:fail cancel') {
|
|
@@ -302,6 +345,10 @@ const weChatMiniProgramPay = async (orderData) => {
|
|
|
|
|
|
// 支付
|
|
// 支付
|
|
const handlePay = async () => {
|
|
const handlePay = async () => {
|
|
|
|
+ if (!channelValue.value) {
|
|
|
|
+ uni.showToast({ title: '请选择支付方式', icon: 'none'})
|
|
|
|
+ return
|
|
|
|
+ }
|
|
const val = chooseItem.value
|
|
const val = chooseItem.value
|
|
try {
|
|
try {
|
|
const res = await getOrder({
|
|
const res = await getOrder({
|
|
@@ -359,27 +406,47 @@ const getMemberList = async () => {
|
|
loading: false
|
|
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) {
|
|
} catch (error) {
|
|
uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
|
|
uni.showToast({ title: '查询数据失败,请重试', icon: 'none' })
|
|
}
|
|
}
|
|
}
|
|
}
|
|
getMemberList()
|
|
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>
|
|
</script>
|
|
|
|
|