|
@@ -22,12 +22,13 @@ import {
|
|
|
Coins,
|
|
Coins,
|
|
|
CheckCircle2,
|
|
CheckCircle2,
|
|
|
Eye,
|
|
Eye,
|
|
|
|
|
+ Sparkles,
|
|
|
} from 'lucide-react';
|
|
} from 'lucide-react';
|
|
|
import LocalTime from '@/components/common/LocalTime';
|
|
import LocalTime from '@/components/common/LocalTime';
|
|
|
import { getPaymentProviderIcon } from '@/components/admin/payments/paymentIcons';
|
|
import { getPaymentProviderIcon } from '@/components/admin/payments/paymentIcons';
|
|
|
import { ExtendedOrderDetail, PaymentRecord } from '@/types';
|
|
import { ExtendedOrderDetail, PaymentRecord } from '@/types';
|
|
|
import { toast } from 'react-hot-toast';
|
|
import { toast } from 'react-hot-toast';
|
|
|
-import { paymentService, orderService, userService } from '@/lib/services';
|
|
|
|
|
|
|
+import { paymentService, orderService, userService, taskService } from '@/lib/services';
|
|
|
import { getCurrencySymbol } from '@/lib/currency';
|
|
import { getCurrencySymbol } from '@/lib/currency';
|
|
|
|
|
|
|
|
const FIELD_DISPLAY_ORDER = [
|
|
const FIELD_DISPLAY_ORDER = [
|
|
@@ -95,6 +96,8 @@ export default function OrderDetailDrawer({
|
|
|
const [loadingPayments, setLoadingPayments] = useState<boolean>(false);
|
|
const [loadingPayments, setLoadingPayments] = useState<boolean>(false);
|
|
|
const [events, setEvents] = useState<any[]>([]);
|
|
const [events, setEvents] = useState<any[]>([]);
|
|
|
const [loadingEvents, setLoadingEvents] = useState<boolean>(false);
|
|
const [loadingEvents, setLoadingEvents] = useState<boolean>(false);
|
|
|
|
|
+ const [task, setTask] = useState<any>(null);
|
|
|
|
|
+ const [loadingTask, setLoadingTask] = useState<boolean>(false);
|
|
|
const [userData, setUserData] = useState<any>(null);
|
|
const [userData, setUserData] = useState<any>(null);
|
|
|
const [loadingUser, setLoadingUser] = useState<boolean>(false);
|
|
const [loadingUser, setLoadingUser] = useState<boolean>(false);
|
|
|
const [qrDetails, setQrDetails] = useState<Record<number, PaymentQrDetail>>({});
|
|
const [qrDetails, setQrDetails] = useState<Record<number, PaymentQrDetail>>({});
|
|
@@ -105,16 +108,35 @@ export default function OrderDetailDrawer({
|
|
|
if (isOpen && order) {
|
|
if (isOpen && order) {
|
|
|
fetchPayments(order.id);
|
|
fetchPayments(order.id);
|
|
|
fetchEvents(order.id);
|
|
fetchEvents(order.id);
|
|
|
|
|
+ fetchTask(order.id);
|
|
|
if (order.user_id) {
|
|
if (order.user_id) {
|
|
|
fetchUserDetails(order.user_id);
|
|
fetchUserDetails(order.user_id);
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
setPaymentList([]);
|
|
setPaymentList([]);
|
|
|
setEvents([]);
|
|
setEvents([]);
|
|
|
|
|
+ setTask(null);
|
|
|
setUserData(null);
|
|
setUserData(null);
|
|
|
}
|
|
}
|
|
|
}, [isOpen, order]);
|
|
}, [isOpen, order]);
|
|
|
|
|
|
|
|
|
|
+ const fetchTask = async (orderId: string) => {
|
|
|
|
|
+ setLoadingTask(true);
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await taskService.getByOrder(orderId);
|
|
|
|
|
+ const list = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : [];
|
|
|
|
|
+ if (list.length > 0) {
|
|
|
|
|
+ setTask(list[0]);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ setTask(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ setTask(null);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ setLoadingTask(false);
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
const fetchPayments = async (orderId: string) => {
|
|
const fetchPayments = async (orderId: string) => {
|
|
|
setLoadingPayments(true);
|
|
setLoadingPayments(true);
|
|
|
try {
|
|
try {
|
|
@@ -233,6 +255,99 @@ export default function OrderDetailDrawer({
|
|
|
const displayNickname = userData?.nickname || order.user_name || order.user?.nickname || order.applicant_name || '-';
|
|
const displayNickname = userData?.nickname || order.user_name || order.user?.nickname || order.applicant_name || '-';
|
|
|
const displayPhone = userData?.phone || order.user?.phone || '-';
|
|
const displayPhone = userData?.phone || order.user?.phone || '-';
|
|
|
|
|
|
|
|
|
|
+ const renderTaskBadge = (t: any) => {
|
|
|
|
|
+ if (!t) return null;
|
|
|
|
|
+ const status = (t.status || '').toLowerCase();
|
|
|
|
|
+ const attempts = t.attempt_count ?? 0;
|
|
|
|
|
+ const grabbed = t.grabbed_history || {};
|
|
|
|
|
+ const tooltip = `任务 #${t.id} | 监控队列: ${t.routing_key || '未指定'} | 累计尝试: ${attempts}次`;
|
|
|
|
|
+
|
|
|
|
|
+ switch (status) {
|
|
|
|
|
+ case 'running':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="px-2 py-0.5 bg-emerald-100 text-emerald-950 border border-emerald-600 text-[10px] font-black uppercase shadow-[1px_1px_0px_#000] flex items-center gap-1 cursor-default"
|
|
|
|
|
+ title={tooltip}
|
|
|
|
|
+ >
|
|
|
|
|
+ <span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-ping inline-block" />
|
|
|
|
|
+ <span>⚡ 抢位中 ({attempts.toLocaleString()}次)</span>
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'grabbed':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className="flex items-center gap-1 flex-wrap" title={tooltip}>
|
|
|
|
|
+ <span className="px-2 py-0.5 bg-amber-300 text-black border border-black text-[10px] font-black uppercase shadow-[1px_1px_0px_#000] flex items-center gap-1 cursor-default">
|
|
|
|
|
+ <Sparkles size={10} className="text-black" />
|
|
|
|
|
+ <span>🏆 考位已锁定</span>
|
|
|
|
|
+ </span>
|
|
|
|
|
+ {grabbed.slot_date && (
|
|
|
|
|
+ <span className="px-1.5 py-0.5 bg-white border border-black text-[10px] font-mono font-black text-amber-950">
|
|
|
|
|
+ 📅 {grabbed.slot_date} {grabbed.slot_time || ''}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )}
|
|
|
|
|
+ {grabbed.urn && (
|
|
|
|
|
+ <span
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ navigator.clipboard.writeText(grabbed.urn);
|
|
|
|
|
+ toast.success('已复制 URN 预约号');
|
|
|
|
|
+ }}
|
|
|
|
|
+ className="px-1.5 py-0.5 bg-white hover:bg-neutral-100 border border-black text-[10px] font-mono font-bold text-black cursor-pointer flex items-center gap-1 transition"
|
|
|
|
|
+ title="点击复制 URN"
|
|
|
|
|
+ >
|
|
|
|
|
+ <span>URN: {grabbed.urn}</span>
|
|
|
|
|
+ <Copy size={9} />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'pending':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="px-2 py-0.5 bg-sky-100 text-sky-950 border border-sky-400 text-[10px] font-bold uppercase cursor-default"
|
|
|
|
|
+ title={tooltip}
|
|
|
|
|
+ >
|
|
|
|
|
+ ⏳ 排队调度中 (P{t.priority ?? 10})
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'pause':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="px-2 py-0.5 bg-neutral-200 text-neutral-700 border border-neutral-400 text-[10px] font-bold uppercase cursor-default"
|
|
|
|
|
+ title={tooltip}
|
|
|
|
|
+ >
|
|
|
|
|
+ ⏸️ 抢号暂停
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'completed':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="px-2 py-0.5 bg-emerald-200 text-emerald-950 border border-emerald-600 text-[10px] font-bold uppercase cursor-default"
|
|
|
|
|
+ title={tooltip}
|
|
|
|
|
+ >
|
|
|
|
|
+ ✔ 抢号完成
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ case 'cancelled':
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="px-2 py-0.5 bg-neutral-100 text-neutral-500 border border-neutral-300 text-[10px] uppercase cursor-default"
|
|
|
|
|
+ title={tooltip}
|
|
|
|
|
+ >
|
|
|
|
|
+ ✕ 任务已取消
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ default:
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ className="px-2 py-0.5 bg-neutral-100 text-neutral-600 border border-black text-[10px] uppercase font-mono cursor-default"
|
|
|
|
|
+ title={tooltip}
|
|
|
|
|
+ >
|
|
|
|
|
+ {t.status || '未知'}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className={`fixed inset-0 ${zIndex || 'z-50'} flex justify-end bg-black/60 backdrop-grayscale font-mono`}>
|
|
<div className={`fixed inset-0 ${zIndex || 'z-50'} flex justify-end bg-black/60 backdrop-grayscale font-mono`}>
|
|
|
<div className="absolute inset-0" onClick={onClose} />
|
|
<div className="absolute inset-0" onClick={onClose} />
|
|
@@ -265,21 +380,39 @@ export default function OrderDetailDrawer({
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
{/* Action Toolbar */}
|
|
{/* Action Toolbar */}
|
|
|
- <div className="bg-white px-5 py-2.5 border-b-2 border-black flex flex-wrap items-center justify-between gap-2 shrink-0">
|
|
|
|
|
- <div className="flex items-center gap-2 text-xs">
|
|
|
|
|
- <span className="font-bold text-neutral-500 uppercase">STATUS:</span>
|
|
|
|
|
- <span
|
|
|
|
|
- className={`px-2 py-0.5 border border-black text-[10px] font-black uppercase ${isPaid
|
|
|
|
|
- ? 'bg-amber-300 text-black shadow-[1px_1px_0px_#000]'
|
|
|
|
|
- : isPending
|
|
|
|
|
- ? 'bg-neutral-100 text-black'
|
|
|
|
|
- : isCancelled
|
|
|
|
|
- ? 'bg-neutral-200 text-neutral-600'
|
|
|
|
|
- : 'bg-rose-100 text-rose-800'
|
|
|
|
|
- }`}
|
|
|
|
|
- >
|
|
|
|
|
- {order.status}
|
|
|
|
|
- </span>
|
|
|
|
|
|
|
+ <div className="bg-white px-5 py-2.5 border-b-2 border-black flex flex-wrap items-center justify-between gap-2.5 shrink-0">
|
|
|
|
|
+ <div className="flex items-center gap-3 text-xs flex-wrap">
|
|
|
|
|
+ <div className="flex items-center gap-1.5">
|
|
|
|
|
+ <span className="font-bold text-neutral-500 uppercase">STATUS:</span>
|
|
|
|
|
+ <span
|
|
|
|
|
+ className={`px-2 py-0.5 border border-black text-[10px] font-black uppercase ${isPaid
|
|
|
|
|
+ ? 'bg-amber-300 text-black shadow-[1px_1px_0px_#000]'
|
|
|
|
|
+ : isPending
|
|
|
|
|
+ ? 'bg-neutral-100 text-black'
|
|
|
|
|
+ : isCancelled
|
|
|
|
|
+ ? 'bg-neutral-200 text-neutral-600'
|
|
|
|
|
+ : 'bg-rose-100 text-rose-800'
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ {order.status}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div className="flex items-center gap-1.5">
|
|
|
|
|
+ <span className="font-bold text-neutral-500 uppercase">TASK:</span>
|
|
|
|
|
+ {loadingTask ? (
|
|
|
|
|
+ <span className="flex items-center gap-1 text-[10px] text-neutral-400 font-mono">
|
|
|
|
|
+ <Loader2 size={10} className="animate-spin text-neutral-500" />
|
|
|
|
|
+ <span>查询中...</span>
|
|
|
|
|
+ </span>
|
|
|
|
|
+ ) : task ? (
|
|
|
|
|
+ renderTaskBadge(task)
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <span className="px-1.5 py-0.5 border border-neutral-300 text-neutral-400 text-[10px] font-mono uppercase bg-neutral-50">
|
|
|
|
|
+ 未挂载任务
|
|
|
|
|
+ </span>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex items-center gap-1.5">
|
|
<div className="flex items-center gap-1.5">
|