feat(mobile): 接入订单支付交接结账与申诉操作

This commit is contained in:
yml2213
2026-10-30 13:47:58 +08:00
parent dd1d00227c
commit 52b6d439bf
8 changed files with 1122 additions and 39 deletions
@@ -1,11 +1,12 @@
import { useState, type ReactNode } from 'react'
import { Button, Dialog, ErrorBlock, List, Skeleton, Tag, Toast } from 'antd-mobile'
import type { ReactNode } from 'react'
import { Button, ErrorBlock, List, Skeleton, Tag } from 'antd-mobile'
import { LeftOutline } from 'antd-mobile-icons'
import { useQueryClient } from '@tanstack/react-query'
import { Link, useNavigate, useParams } from 'react-router-dom'
import { useQueryClient } from '@tanstack/react-query'
import { BrandLogo } from '@/components/BrandLogo'
import { cancelMyOrder, useMyOrder } from '@/features/orders/api'
import { useHandoffRecords, useMyOrder } from '@/features/orders/api'
import { MobileOrderActionPanel } from '@/features/mobile/MobileOrderActionPanel'
import {
checkoutStatusMeta,
handoffStatusMeta,
@@ -15,6 +16,13 @@ import {
import { useSessionStore } from '@/stores/session'
import { formatDateTime, formatMoney, formatText } from '@/shared/utils/format'
const handoffRecordTypeMap: Record<string, string> = {
owner_handoff: '号主交接',
platform_handoff: '平台代交接',
renter_checkout: '结账记录',
renter_return: '归还记录',
}
function StatusLine({ label, children }: { label: string; children: ReactNode }) {
return (
<div className="mobile-order-detail__status-line">
@@ -31,32 +39,9 @@ export function MobileOrderDetailPage() {
const token = useSessionStore(state => state.token)
const hydrated = useSessionStore(state => state.hydrated)
const query = useMyOrder(id, Boolean(token))
const [cancelling, setCancelling] = useState(false)
const handoffQuery = useHandoffRecords(id, Boolean(token))
const order = query.data
const onCancel = async () => {
if (!order) return
const confirmed = await Dialog.confirm({
content: '取消后订单会关闭,已冻结的押金将按原路退回。确定取消吗?',
confirmText: '取消订单',
cancelText: '再想想',
})
if (!confirmed) return
setCancelling(true)
try {
await cancelMyOrder(order.id)
Toast.show({ icon: 'success', content: '订单已取消' })
await queryClient.invalidateQueries({ queryKey: ['my-orders'] })
await query.refetch()
} catch (error) {
Toast.show({
icon: 'fail',
content: error instanceof Error ? error.message : '取消失败,请稍后再试',
})
} finally {
setCancelling(false)
}
}
const handoffRecords = handoffQuery.data ?? []
if (!hydrated) {
return (
@@ -121,7 +106,6 @@ export function MobileOrderDetailPage() {
const handoff = handoffStatusMeta(order.handoff_status)
const settlement = settlementStatusMeta(order.settlement_status)
const checkout = order.checkout
const canCancel = order.price_role === 'renter' && order.status === 'pending_payment'
return (
<div className="mobile-order-detail">
@@ -192,12 +176,22 @@ export function MobileOrderDetailPage() {
结账状态
</List.Item>
<List.Item extra={`${checkout.round_count} / ${checkout.max_rounds}`}>协商轮次</List.Item>
{checkout.turn ? (
<List.Item extra={checkout.turn === 'owner' ? '号主处理' : '租客处理'}>
当前轮到
</List.Item>
) : null}
<List.Item extra={formatMoney(checkout.consumable_amount_cent)}>消耗品费用</List.Item>
<List.Item extra={`${checkout.coin_consumed_m} M`}>哈夫币消耗</List.Item>
<List.Item extra={formatMoney(checkout.other_amount_cent)}>其他费用</List.Item>
<List.Item extra={formatMoney(checkout.deposit_deduct_amount_cent)}>押金扣除</List.Item>
<List.Item extra={formatMoney(checkout.renter_refund_amount_cent)}>可退金额</List.Item>
<List.Item extra={formatMoney(checkout.owner_income_amount_cent)}>号主到手</List.Item>
{checkout.shortfall_cent > 0 ? (
<List.Item extra={<span className="mobile-order-detail__danger">{formatMoney(checkout.shortfall_cent)}</span>}>
押金缺口
</List.Item>
) : null}
{checkout.content ? (
<List.Item>
<div className="mobile-order-detail__checkout-content">{checkout.content}</div>
@@ -214,12 +208,34 @@ export function MobileOrderDetailPage() {
</List>
) : null}
{handoffRecords.length > 0 ? (
<List header="交接与结账记录" className="mobile-order-detail__list">
{handoffRecords.map(record => (
<List.Item key={record.id}>
<div className="mobile-order-detail__record">
<div className="mobile-order-detail__record-head">
<strong>{handoffRecordTypeMap[record.type] ?? record.type}</strong>
<span>{formatDateTime(record.created_at)}</span>
</div>
<p>{record.content}</p>
<div className="mobile-order-detail__record-tags">
{record.confirmed_by_renter_at ? <Tag color="success">租客已确认</Tag> : null}
{record.confirmed_by_owner_at ? <Tag color="success">号主已确认</Tag> : null}
</div>
</div>
</List.Item>
))}
</List>
) : null}
<div className="mobile-order-detail__actions">
{canCancel ? (
<Button block color="danger" fill="outline" loading={cancelling} onClick={() => void onCancel()}>
取消订单
</Button>
) : null}
<MobileOrderActionPanel
order={order}
onChanged={async () => {
await Promise.all([query.refetch(), handoffQuery.refetch()])
await queryClient.invalidateQueries({ queryKey: ['my-orders'] })
}}
/>
<Link to="/m/orders" className="mobile-order-detail__back-link">
返回我的订单
</Link>