feat: 订场页5秒自动刷新 + 支付页仅场地预约支持余额支付(修正business_type) + 清理冗余代码

This commit is contained in:
gqt
2026-07-29 13:17:22 +08:00
parent 1a3137bd12
commit 00f1bcd0fa
4 changed files with 37 additions and 27 deletions
@@ -24,7 +24,7 @@
<view class="card method-card"> <view class="card method-card">
<text class="card-title">支付方式</text> <text class="card-title">支付方式</text>
<view <view
v-if="!isStoredValueOrder" v-if="!isWechatOnlyOrder"
class="method-item" class="method-item"
:class="{ active: payMethod === 'balance', disabled: !canUseBalance }" :class="{ active: payMethod === 'balance', disabled: !canUseBalance }"
@tap="selectMethod('balance')" @tap="selectMethod('balance')"
@@ -74,9 +74,8 @@ const isSubmitting = ref(false)
const nowTimestamp = ref(Date.now()) const nowTimestamp = ref(Date.now())
let countdownTimer = null let countdownTimer = null
const isStoredValueOrder = computed(() => order.value?.business_type === 'stored_value') const isWechatOnlyOrder = computed(() => order.value?.business_type !== 'private_booking')
const canUseBalance = computed(() => { const canUseBalance = computed(() => {
if (isStoredValueOrder.value) return false
return toAmountNumber(balance.value.balance) >= toAmountNumber(order.value?.amount) return toAmountNumber(balance.value.balance) >= toAmountNumber(order.value?.amount)
}) })
const canPay = computed(() => order.value?.status === 'pending_pay' && (payMethod.value !== 'balance' || canUseBalance.value)) const canPay = computed(() => order.value?.status === 'pending_pay' && (payMethod.value !== 'balance' || canUseBalance.value))
@@ -107,16 +106,12 @@ onUnmounted(() => {
}) })
const loadPage = async () => { const loadPage = async () => {
const [orderData, balanceData] = await Promise.all([ order.value = await orderApi.getOrderDetail(orderId.value)
orderApi.getOrderDetail(orderId.value), if (isWechatOnlyOrder.value) {
memberApi.getBalance()
])
order.value = orderData
balance.value = balanceData
if (isStoredValueOrder.value) {
payMethod.value = 'wechat'
} else if (!canUseBalance.value) {
payMethod.value = 'wechat' payMethod.value = 'wechat'
} else {
balance.value = await memberApi.getBalance()
payMethod.value = canUseBalance.value ? 'balance' : 'wechat'
} }
updateCountdownTimer() updateCountdownTimer()
} }
@@ -140,22 +135,15 @@ const stopCountdown = () => {
const padTime = (value) => String(value).padStart(2, '0') const padTime = (value) => String(value).padStart(2, '0')
const selectMethod = (method) => { const selectMethod = (method) => {
if (method === 'balance') { if (method === 'balance' && !canUseBalance.value) {
if (isStoredValueOrder.value) { uni.showToast({ title: '余额不足', icon: 'none' })
uni.showToast({ title: '储值卡订单仅支持微信支付', icon: 'none' }) return
return
}
if (!canUseBalance.value) {
uni.showToast({ title: '余额不足', icon: 'none' })
return
}
} }
payMethod.value = method payMethod.value = method
} }
const pay = async () => { const pay = async () => {
if (!canPay.value || isSubmitting.value) return if (!canPay.value || isSubmitting.value) return
if (isStoredValueOrder.value && payMethod.value === 'balance') return
isSubmitting.value = true isSubmitting.value = true
try { try {
if (payMethod.value === 'balance') { if (payMethod.value === 'balance') {
@@ -372,7 +372,8 @@ async function refresh() {
} }
defineExpose({ defineExpose({
refresh refresh,
loadGrid
}) })
</script> </script>
+2 -1
View File
@@ -10,7 +10,8 @@
<script setup> <script setup>
defineExpose({ defineExpose({
refresh() {} refresh() {},
loadGrid() {}
}) })
</script> </script>
+23 -3
View File
@@ -7,7 +7,7 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { onShow } from '@dcloudio/uni-app' import { onShow, onHide } from '@dcloudio/uni-app'
import { getStoredVenue } from '@/utils/venue' import { getStoredVenue } from '@/utils/venue'
import ComprehensivePrivate from '@/pages/comprehensive/private/index.vue' import ComprehensivePrivate from '@/pages/comprehensive/private/index.vue'
import IcePrivate from '@/pages/ice/private/index.vue' import IcePrivate from '@/pages/ice/private/index.vue'
@@ -15,13 +15,33 @@ import IcePrivate from '@/pages/ice/private/index.vue'
const isComprehensive = getStoredVenue() === 'comprehensive' const isComprehensive = getStoredVenue() === 'comprehensive'
const contentRef = ref() const contentRef = ref()
let isFirstShow = true let isFirstShow = true
let autoRefreshTimer = null
const startAutoRefresh = () => {
stopAutoRefresh()
autoRefreshTimer = setInterval(() => {
contentRef.value?.loadGrid?.()
}, 5000)
}
const stopAutoRefresh = () => {
if (autoRefreshTimer) {
clearInterval(autoRefreshTimer)
autoRefreshTimer = null
}
}
onShow(() => { onShow(() => {
if (isFirstShow) { if (isFirstShow) {
isFirstShow = false isFirstShow = false
return } else {
contentRef.value?.refresh?.()
} }
contentRef.value?.refresh?.() startAutoRefresh()
})
onHide(() => {
stopAutoRefresh()
}) })
</script> </script>