feat: 实现订单支付功能并优化支付成功后的页面跳转逻辑

This commit is contained in:
邹方成 2025-12-26 13:38:40 +08:00
parent b9b60b15a1
commit a3ec9c102d
2 changed files with 89 additions and 6 deletions

View File

@ -312,7 +312,8 @@ function handlePay() {
.then(async () => { .then(async () => {
uni.hideLoading() uni.hideLoading()
uni.showToast({ title: '支付成功', icon: 'success' }) uni.showToast({ title: '支付成功', icon: 'success' })
await loadOrder() //
navigateToGame(ord)
}) })
.catch((e) => { .catch((e) => {
uni.hideLoading() uni.hideLoading()
@ -324,6 +325,32 @@ function handlePay() {
}) })
} }
function navigateToGame(ord) {
const playType = ord.play_type
const activityId = ord.activity_id
if (!activityId) {
// ID
uni.navigateBack()
return
}
let url = ''
if (playType === 'match') {
url = `/pages/activity/duiduipeng/index?activity_id=${activityId}`
} else if (playType === 'ichiban') {
url = `/pages/activity/yifanshang/index?activity_id=${activityId}`
} else if (playType === 'infinity') {
url = `/pages/activity/wuxianshang/index?activity_id=${activityId}`
}
if (url) {
uni.redirectTo({ url })
} else {
uni.navigateBack()
}
}
function copyText(text) { function copyText(text) {
if (!text) return if (!text) return
uni.setClipboardData({ uni.setClipboardData({

View File

@ -105,7 +105,7 @@
<!-- 快捷操作 --> <!-- 快捷操作 -->
<view class="order-actions" v-if="currentTab === 'pending'"> <view class="order-actions" v-if="currentTab === 'pending'">
<button class="action-btn secondary" @tap.stop="cancelOrder(item)">取消订单</button> <button class="action-btn secondary" @tap.stop="doCancelOrder(item)">取消订单</button>
<button class="action-btn primary" @tap.stop="payOrder(item)">立即支付</button> <button class="action-btn primary" @tap.stop="payOrder(item)">立即支付</button>
</view> </view>
</view> </view>
@ -128,7 +128,7 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { onLoad, onReachBottom } from '@dcloudio/uni-app' import { onLoad, onReachBottom } from '@dcloudio/uni-app'
import { getOrders, cancelOrder as cancelOrderApi } from '../../api/appUser' import { getOrders, cancelOrder as cancelOrderApi, createWechatOrder } from '../../api/appUser'
const currentTab = ref('pending') const currentTab = ref('pending')
const orders = ref([]) const orders = ref([])
@ -429,9 +429,65 @@ async function doCancelOrder(item) {
}) })
} }
function payOrder(item) { async function payOrder(item) {
// TODO: const openid = uni.getStorageSync('openid')
uni.showToast({ title: '支付功能开发中', icon: 'none' }) if (!openid) {
uni.showToast({ title: '缺少OpenID请重新登录', icon: 'none' })
return
}
if (!item || !item.order_no) return
uni.showLoading({ title: '拉起支付...' })
try {
const payRes = await createWechatOrder({ openid, order_no: item.order_no })
await new Promise((resolve, reject) => {
uni.requestPayment({
provider: 'wxpay',
timeStamp: payRes.timeStamp || payRes.timestamp,
nonceStr: payRes.nonceStr || payRes.noncestr,
package: payRes.package,
signType: payRes.signType || 'MD5',
paySign: payRes.paySign,
success: resolve,
fail: reject
})
})
uni.hideLoading()
uni.showToast({ title: '支付成功', icon: 'success' })
navigateToGame(item)
} catch (e) {
uni.hideLoading()
if (e?.errMsg && String(e.errMsg).includes('cancel')) {
uni.showToast({ title: '支付已取消', icon: 'none' })
return
}
uni.showToast({ title: e?.message || '支付失败', icon: 'none' })
}
}
function navigateToGame(item) {
const playType = item.play_type
const activityId = item.activity_id
if (!activityId) {
fetchOrders(false) //
return
}
let url = ''
if (playType === 'match') {
url = `/pages/activity/duiduipeng/index?activity_id=${activityId}`
} else if (playType === 'ichiban') {
url = `/pages/activity/yifanshang/index?activity_id=${activityId}`
} else if (playType === 'infinity') {
url = `/pages/activity/wuxianshang/index?activity_id=${activityId}`
}
if (url) {
uni.navigateTo({ url })
} else {
fetchOrders(false)
}
} }
onLoad((opts) => { onLoad((opts) => {