开始增加支付-1
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed } from "vue";
|
||||
import { useRouter, useRoute } from "vue-router";
|
||||
import { showToast } from "vant";
|
||||
import { showDialog, showToast } from "vant";
|
||||
import MobileBottomNav from "@/components/MobileBottomNav.vue";
|
||||
|
||||
import { fetchOrders, payOrder, type Order } from "@/api/orders";
|
||||
import { fetchOrders, payOrder, queryOrderPayment, type Order, type PaymentOrder } from "@/api/orders";
|
||||
import { useSessionStore } from "@/stores/session";
|
||||
import { formatDateMinute } from "@/utils/time";
|
||||
|
||||
@@ -75,8 +75,12 @@ function goDetail(id: number) {
|
||||
async function handlePay(order: Order) {
|
||||
payingOrderId.value = order.id;
|
||||
try {
|
||||
await payOrder(order.id);
|
||||
showToast({ message: "支付成功", icon: "passed" });
|
||||
const payment = await payOrder(order.id);
|
||||
if (payment.paid) {
|
||||
showToast({ message: "支付成功", icon: "passed" });
|
||||
} else {
|
||||
await showPaymentDialog(order, payment);
|
||||
}
|
||||
await loadOrders();
|
||||
} catch (error) {
|
||||
showToast({ message: readError(error, "支付失败"), icon: "cross" });
|
||||
@@ -85,6 +89,51 @@ async function handlePay(order: Order) {
|
||||
}
|
||||
}
|
||||
|
||||
async function showPaymentDialog(order: Order, payment: PaymentOrder) {
|
||||
const payURL = payment.jspay_url || payment.td_code || payment.jspay_info || "";
|
||||
const message = payURL
|
||||
? `支付单已创建,金额 ¥${(payment.amount_cent / 100).toFixed(2)}。请复制或打开支付链接完成付款,付款后可刷新订单状态。\n\n${payURL}`
|
||||
: "支付单已创建,请完成付款后刷新订单状态。";
|
||||
await showDialog({
|
||||
title: "去支付",
|
||||
message,
|
||||
confirmButtonText: payURL ? "打开/复制" : "刷新状态",
|
||||
cancelButtonText: "刷新状态",
|
||||
showCancelButton: true,
|
||||
})
|
||||
.then(async () => {
|
||||
if (payURL) {
|
||||
await openOrCopyPayURL(payURL);
|
||||
}
|
||||
await refreshPayment(order.id);
|
||||
})
|
||||
.catch(async () => {
|
||||
await refreshPayment(order.id);
|
||||
});
|
||||
}
|
||||
|
||||
async function openOrCopyPayURL(payURL: string) {
|
||||
if (/^https?:\/\//.test(payURL)) {
|
||||
window.open(payURL, "_blank");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await navigator.clipboard?.writeText(payURL);
|
||||
showToast({ message: "支付链接已复制", icon: "passed" });
|
||||
} catch {
|
||||
showToast({ message: "请手动复制支付链接", icon: "warning-o" });
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshPayment(orderId: number) {
|
||||
const payment = await queryOrderPayment(orderId);
|
||||
if (payment.paid) {
|
||||
showToast({ message: "支付成功", icon: "passed" });
|
||||
} else {
|
||||
showToast({ message: "支付未完成", icon: "clock-o" });
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === "object" && error && "response" in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } })
|
||||
|
||||
Reference in New Issue
Block a user