支付完成后跳转群消息
This commit is contained in:
@@ -32,7 +32,7 @@ export function useMobilePaymentCashier() {
|
|||||||
confirmButtonText: '知道了',
|
confirmButtonText: '知道了',
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
paidMessage: '支付成功,等待号主交接',
|
paidMessage: '支付成功,正在进入群消息',
|
||||||
pollIntervalMs: 2500,
|
pollIntervalMs: 2500,
|
||||||
qrWidth: 220,
|
qrWidth: 220,
|
||||||
openExternalURL: url => {
|
openExternalURL: url => {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export interface UseOrderActionsOptions {
|
|||||||
/**
|
/**
|
||||||
* 打开收银台 UI(二维码弹窗 / App 浏览器跳转)。由调用方注入。
|
* 打开收银台 UI(二维码弹窗 / App 浏览器跳转)。由调用方注入。
|
||||||
* 仅在 payment 未支付时被调用;payment 已支付的情况由 composable 自行提示并 loadOrder。
|
* 仅在 payment 未支付时被调用;payment 已支付的情况由 composable 自行提示并 loadOrder。
|
||||||
* onPaid:支付完成(轮询发现 paid)时的回调,通常传入 loadOrder。
|
* onPaid:支付完成(轮询发现 paid)时的回调,通常跳转到群消息。
|
||||||
*/
|
*/
|
||||||
startCashier: (payment: PaymentOrder, onPaid: () => Promise<void>) => void | Promise<void>
|
startCashier: (payment: PaymentOrder, onPaid: () => Promise<void>) => void | Promise<void>
|
||||||
/** 修改结账提交成功后触发(如关闭弹窗)。可选。 */
|
/** 修改结账提交成功后触发(如关闭弹窗)。可选。 */
|
||||||
@@ -270,11 +270,11 @@ export function useOrderActions(options: UseOrderActionsOptions) {
|
|||||||
try {
|
try {
|
||||||
const payment = await startOrderPayment(order.value.id, { pay_way: payWay })
|
const payment = await startOrderPayment(order.value.id, { pay_way: payWay })
|
||||||
if (payment.paid) {
|
if (payment.paid) {
|
||||||
options.notifySuccess('支付成功,等待号主交接')
|
options.notifySuccess('支付成功,正在进入群消息')
|
||||||
await loadOrder()
|
await openOrderChatAfterPayment()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await options.startCashier(payment, loadOrder)
|
await options.startCashier(payment, openOrderChatAfterPayment)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
options.notifyError(readError(error, '支付失败'))
|
options.notifyError(readError(error, '支付失败'))
|
||||||
} finally {
|
} finally {
|
||||||
@@ -520,12 +520,30 @@ export function useOrderActions(options: UseOrderActionsOptions) {
|
|||||||
|
|
||||||
async function openOrderChat() {
|
async function openOrderChat() {
|
||||||
if (!order.value || openingChat.value) return
|
if (!order.value || openingChat.value) return
|
||||||
|
await navigateToOrderChat(order.value.id, '订单群聊暂不可用')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openOrderChatAfterPayment() {
|
||||||
|
if (!order.value) return
|
||||||
|
const opened = await navigateToOrderChat(
|
||||||
|
order.value.id,
|
||||||
|
'支付成功,但群消息暂不可用,请稍后从消息进入'
|
||||||
|
)
|
||||||
|
if (!opened) {
|
||||||
|
await loadOrder()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function navigateToOrderChat(orderID: number, errorMessage: string) {
|
||||||
|
if (openingChat.value) return false
|
||||||
openingChat.value = true
|
openingChat.value = true
|
||||||
try {
|
try {
|
||||||
const chat = await fetchOrderChat(order.value.id)
|
const chat = await fetchOrderChat(orderID)
|
||||||
await router.push(`${options.chatPathPrefix}${chat.id}`)
|
await router.push(`${options.chatPathPrefix}${chat.id}`)
|
||||||
|
return true
|
||||||
} catch {
|
} catch {
|
||||||
options.notifyError('订单群聊暂不可用')
|
options.notifyError(errorMessage)
|
||||||
|
return false
|
||||||
} finally {
|
} finally {
|
||||||
openingChat.value = false
|
openingChat.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export interface UseOrderPaymentCashierOptions {
|
|||||||
* Mobile 用 vant dialog(带"知道了"按钮)做强提示,PC 用普通提示即可。
|
* Mobile 用 vant dialog(带"知道了"按钮)做强提示,PC 用普通提示即可。
|
||||||
*/
|
*/
|
||||||
notifyFallback: (message: string) => void
|
notifyFallback: (message: string) => void
|
||||||
/** 支付完成的提示文案,默认 "支付成功,等待号主交接"。 */
|
/** 支付完成的提示文案,默认 "支付成功,正在进入群消息"。 */
|
||||||
paidMessage?: string
|
paidMessage?: string
|
||||||
/** 轮询间隔,PC 3000 / Mobile 2500。 */
|
/** 轮询间隔,PC 3000 / Mobile 2500。 */
|
||||||
pollIntervalMs?: number
|
pollIntervalMs?: number
|
||||||
@@ -60,7 +60,7 @@ export function useOrderPaymentCashier(options: UseOrderPaymentCashierOptions) {
|
|||||||
|
|
||||||
const pollIntervalMs = options.pollIntervalMs ?? 2500
|
const pollIntervalMs = options.pollIntervalMs ?? 2500
|
||||||
const qrWidth = options.qrWidth ?? 220
|
const qrWidth = options.qrWidth ?? 220
|
||||||
const paidMessage = options.paidMessage ?? '支付成功,等待号主交接'
|
const paidMessage = options.paidMessage ?? '支付成功,正在进入群消息'
|
||||||
|
|
||||||
const payURL = computed(() => paymentPayURL(activePayment.value))
|
const payURL = computed(() => paymentPayURL(activePayment.value))
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
} from '@/features/orders/api/orders'
|
} from '@/features/orders/api/orders'
|
||||||
import MobilePaymentCashierPopup from '@/features/orders/components/MobilePaymentCashierPopup.vue'
|
import MobilePaymentCashierPopup from '@/features/orders/components/MobilePaymentCashierPopup.vue'
|
||||||
import { useMobilePaymentCashier } from '@/features/orders/composables/useMobilePaymentCashier'
|
import { useMobilePaymentCashier } from '@/features/orders/composables/useMobilePaymentCashier'
|
||||||
|
import { fetchOrderChat } from '@/features/chats/api/chats'
|
||||||
import { centToYuan, formatMoney } from '@/shared/utils/money'
|
import { centToYuan, formatMoney } from '@/shared/utils/money'
|
||||||
import { useSessionStore } from '@/stores/session'
|
import { useSessionStore } from '@/stores/session'
|
||||||
import { formatDateMinute } from '@/shared/utils/time'
|
import { formatDateMinute } from '@/shared/utils/time'
|
||||||
@@ -100,10 +101,10 @@ async function handlePay(order: Order) {
|
|||||||
try {
|
try {
|
||||||
const payment = await startOrderPayment(order.id, { pay_way: payWay })
|
const payment = await startOrderPayment(order.id, { pay_way: payWay })
|
||||||
if (payment.paid) {
|
if (payment.paid) {
|
||||||
showToast({ message: '支付成功,等待号主交接', icon: 'passed' })
|
showToast({ message: '支付成功,正在进入群消息', icon: 'passed' })
|
||||||
await loadOrders()
|
await openOrderChatAfterPayment(order)
|
||||||
} else {
|
} else {
|
||||||
await openMobilePaymentCashier(payment, loadOrders)
|
await openMobilePaymentCashier(payment, () => openOrderChatAfterPayment(order))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showToast({ message: readError(error, '支付失败'), icon: 'cross' })
|
showToast({ message: readError(error, '支付失败'), icon: 'cross' })
|
||||||
@@ -112,6 +113,16 @@ async function handlePay(order: Order) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openOrderChatAfterPayment(order: Order) {
|
||||||
|
try {
|
||||||
|
const chat = await fetchOrderChat(order.id)
|
||||||
|
await router.push(`/m/chats/${chat.id}`)
|
||||||
|
} catch {
|
||||||
|
showToast({ message: '支付成功,但群消息暂不可用,请稍后从消息进入', icon: 'warning-o' })
|
||||||
|
await loadOrders()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// selectPayWay 在列表快捷支付前让用户选择支付宝或微信。
|
// selectPayWay 在列表快捷支付前让用户选择支付宝或微信。
|
||||||
async function selectPayWay(): Promise<PaymentPayWay | null> {
|
async function selectPayWay(): Promise<PaymentPayWay | null> {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ const cashier = useOrderPaymentCashier({
|
|||||||
notifyError: message => ElMessage.error(message),
|
notifyError: message => ElMessage.error(message),
|
||||||
notifyInfo: message => ElMessage.info(message),
|
notifyInfo: message => ElMessage.info(message),
|
||||||
notifyFallback: message => ElMessage.warning(message),
|
notifyFallback: message => ElMessage.warning(message),
|
||||||
paidMessage: '支付成功,等待号主交接',
|
paidMessage: '支付成功,正在进入群消息',
|
||||||
pollIntervalMs: 3000,
|
pollIntervalMs: 3000,
|
||||||
qrWidth: 240,
|
qrWidth: 240,
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user