feat: 支付页仅保留微信支付,移除余额支付
This commit is contained in:
@@ -23,24 +23,12 @@
|
|||||||
|
|
||||||
<view class="card method-card">
|
<view class="card method-card">
|
||||||
<text class="card-title">支付方式</text>
|
<text class="card-title">支付方式</text>
|
||||||
<view
|
<view class="method-item active">
|
||||||
v-if="!isStoredValueOrder"
|
|
||||||
class="method-item"
|
|
||||||
:class="{ active: payMethod === 'balance', disabled: !canUseBalance }"
|
|
||||||
@tap="selectMethod('balance')"
|
|
||||||
>
|
|
||||||
<view>
|
|
||||||
<text class="method-title">余额支付</text>
|
|
||||||
<text class="method-sub">当前余额 ¥{{ balance.balance }}</text>
|
|
||||||
</view>
|
|
||||||
<text class="method-check">{{ payMethod === 'balance' ? '已选' : '' }}</text>
|
|
||||||
</view>
|
|
||||||
<view class="method-item" :class="{ active: payMethod === 'wechat' }" @tap="selectMethod('wechat')">
|
|
||||||
<view>
|
<view>
|
||||||
<text class="method-title">微信支付</text>
|
<text class="method-title">微信支付</text>
|
||||||
<text class="method-sub">使用微信支付完成订单</text>
|
<text class="method-sub">使用微信支付完成订单</text>
|
||||||
</view>
|
</view>
|
||||||
<text class="method-check">{{ payMethod === 'wechat' ? '已选' : '' }}</text>
|
<text class="method-check">已选</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -61,28 +49,19 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed, onUnmounted, ref } from 'vue'
|
import { computed, onUnmounted, ref } from 'vue'
|
||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { memberApi } from '@/modules/comprehensive/api/member'
|
|
||||||
import { orderApi } from '@/modules/comprehensive/api/order'
|
import { orderApi } from '@/modules/comprehensive/api/order'
|
||||||
import { formatDateTime } from '@/modules/comprehensive/utils/date'
|
import { formatDateTime } from '@/modules/comprehensive/utils/date'
|
||||||
import { toAmountNumber } from '@/modules/comprehensive/utils/money'
|
|
||||||
|
|
||||||
const orderId = ref('')
|
const orderId = ref('')
|
||||||
const order = ref(null)
|
const order = ref(null)
|
||||||
const balance = ref({ balance: '0.00' })
|
|
||||||
const payMethod = ref('balance')
|
|
||||||
const isSubmitting = ref(false)
|
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 canPay = computed(() => order.value?.status === 'pending_pay')
|
||||||
const canUseBalance = computed(() => {
|
|
||||||
if (isStoredValueOrder.value) return false
|
|
||||||
return toAmountNumber(balance.value.balance) >= toAmountNumber(order.value?.amount)
|
|
||||||
})
|
|
||||||
const canPay = computed(() => order.value?.status === 'pending_pay' && (payMethod.value !== 'balance' || canUseBalance.value))
|
|
||||||
const payButtonText = computed(() => {
|
const payButtonText = computed(() => {
|
||||||
if (order.value?.status !== 'pending_pay') return '订单不可支付'
|
if (order.value?.status !== 'pending_pay') return '订单不可支付'
|
||||||
return payMethod.value === 'balance' ? '余额支付' : '微信支付'
|
return '微信支付'
|
||||||
})
|
})
|
||||||
const paymentRemainingSeconds = computed(() => {
|
const paymentRemainingSeconds = computed(() => {
|
||||||
if (!order.value?.expire_at) return 0
|
if (!order.value?.expire_at) return 0
|
||||||
@@ -107,17 +86,7 @@ onUnmounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const loadPage = async () => {
|
const loadPage = async () => {
|
||||||
const [orderData, balanceData] = await Promise.all([
|
order.value = await orderApi.getOrderDetail(orderId.value)
|
||||||
orderApi.getOrderDetail(orderId.value),
|
|
||||||
memberApi.getBalance()
|
|
||||||
])
|
|
||||||
order.value = orderData
|
|
||||||
balance.value = balanceData
|
|
||||||
if (isStoredValueOrder.value) {
|
|
||||||
payMethod.value = 'wechat'
|
|
||||||
} else if (!canUseBalance.value) {
|
|
||||||
payMethod.value = 'wechat'
|
|
||||||
}
|
|
||||||
updateCountdownTimer()
|
updateCountdownTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,33 +108,13 @@ const stopCountdown = () => {
|
|||||||
|
|
||||||
const padTime = (value) => String(value).padStart(2, '0')
|
const padTime = (value) => String(value).padStart(2, '0')
|
||||||
|
|
||||||
const selectMethod = (method) => {
|
|
||||||
if (method === 'balance') {
|
|
||||||
if (isStoredValueOrder.value) {
|
|
||||||
uni.showToast({ title: '储值卡订单仅支持微信支付', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!canUseBalance.value) {
|
|
||||||
uni.showToast({ title: '余额不足', icon: 'none' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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') {
|
const paymentData = await orderApi.payOrderByWechat(order.value.id)
|
||||||
await orderApi.payOrderByBalance(order.value.id)
|
await requestWechatPayment(paymentData.wechat)
|
||||||
uni.showToast({ title: '支付成功', icon: 'success' })
|
uni.showToast({ title: '支付已提交', icon: 'success' })
|
||||||
} else {
|
|
||||||
const paymentData = await orderApi.payOrderByWechat(order.value.id)
|
|
||||||
await requestWechatPayment(paymentData.wechat)
|
|
||||||
uni.showToast({ title: '支付已提交', icon: 'success' })
|
|
||||||
}
|
|
||||||
await loadPage()
|
await loadPage()
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.redirectTo({ url: `/pages/comprehensive/orders/detail?id=${order.value.id}` })
|
uni.redirectTo({ url: `/pages/comprehensive/orders/detail?id=${order.value.id}` })
|
||||||
@@ -269,10 +218,6 @@ const requestWechatPayment = (wechatPayload) => new Promise((resolve, reject) =>
|
|||||||
color: $color-primary;
|
color: $color-primary;
|
||||||
}
|
}
|
||||||
|
|
||||||
.method-item.disabled {
|
|
||||||
opacity: 0.45;
|
|
||||||
}
|
|
||||||
|
|
||||||
.method-title,
|
.method-title,
|
||||||
.method-sub {
|
.method-sub {
|
||||||
display: block;
|
display: block;
|
||||||
|
|||||||
Reference in New Issue
Block a user