import { useState, type ReactNode } from 'react' import { Button, ErrorBlock, List, Skeleton, Tag, Toast } from 'antd-mobile' import { LeftOutline } from 'antd-mobile-icons' import { Link, useNavigate, useParams } from 'react-router-dom' import { useQueryClient } from '@tanstack/react-query' import { BrandLogo } from '@/components/BrandLogo' import { useHandoffRecords, useMyOrder } from '@/features/orders/api' import { fetchOrderConversation } from '@/features/messages/api' import { MobileOrderActionPanel } from '@/features/mobile/MobileOrderActionPanel' import { checkoutStatusMeta, handoffStatusMeta, orderStatusMeta, settlementStatusMeta, } from '@/features/orders/labels' import { useSessionStore } from '@/stores/session' import { formatDateTime, formatMoney, formatText } from '@/shared/utils/format' const handoffRecordTypeMap: Record = { owner_handoff: '号主交接', platform_handoff: '平台代交接', renter_checkout: '结账记录', renter_return: '归还记录', } function StatusLine({ label, children }: { label: string; children: ReactNode }) { return (
{label} {children}
) } export function MobileOrderDetailPage() { const { id } = useParams() const navigate = useNavigate() const queryClient = useQueryClient() const token = useSessionStore(state => state.token) const hydrated = useSessionStore(state => state.hydrated) const query = useMyOrder(id, Boolean(token)) const handoffQuery = useHandoffRecords(id, Boolean(token)) const order = query.data const handoffRecords = handoffQuery.data ?? [] const [openingChat, setOpeningChat] = useState(false) const openOrderChat = async () => { if (!order || openingChat) return setOpeningChat(true) try { const conversation = await fetchOrderConversation(order.id) navigate(`/m/messages/${conversation.id}`) } catch (error) { Toast.show({ icon: 'fail', content: error instanceof Error ? error.message : '账号群暂时无法打开', }) } finally { setOpeningChat(false) } } if (!hydrated) { return (
) } if (!token) { return (

登录后查看订单详情

交接记录与结账明细只对交易双方可见。

) } if (query.isPending) { return (
) } if (query.isError || !order) { return (
) } const status = orderStatusMeta(order.status) const handoff = handoffStatusMeta(order.handoff_status) const settlement = settlementStatusMeta(order.settlement_status) const checkout = order.checkout return (
{order.order_no} {status.label}

{order.title}

{handoff.label} {settlement.label}
{formatMoney(order.display_amount_cent)} 押金 {formatMoney(order.deposit_amount_cent)}
商品编号 区服 登录平台 预计租期 租客租金 号主租金 平台服务费 实收押金 {order.deposit_waived_amount_cent > 0 ? ( 押金减免 ) : null} {order.refund_amount_cent > 0 ? ( 已退金额 ) : null} 下单时间 起租时间 预计结束 支付截止 {checkout ? ( {checkoutStatusMeta(checkout.status).label}}> 结账状态 协商轮次 {checkout.turn ? ( 当前轮到 ) : null} 消耗品费用 哈夫币消耗 其他费用 押金扣除 可退金额 号主到手 {checkout.shortfall_cent > 0 ? ( {formatMoney(checkout.shortfall_cent)}}> 押金缺口 ) : null} {checkout.content ? (
{checkout.content}
) : null}
) : null} {order.active_dispute ? ( 申诉单号 类型 状态 ) : null} {handoffRecords.length > 0 ? ( {handoffRecords.map(record => (
{handoffRecordTypeMap[record.type] ?? record.type} {formatDateTime(record.created_at)}

{record.content}

{record.confirmed_by_renter_at ? 租客已确认 : null} {record.confirmed_by_owner_at ? 号主已确认 : null}
))}
) : null}
{ await Promise.all([query.refetch(), handoffQuery.refetch()]) await queryClient.invalidateQueries({ queryKey: ['my-orders'] }) }} /> 返回我的订单
) }