fix:优化再拼一次bug,优化打手端移动端拼单列表显示
This commit is contained in:
@@ -51,6 +51,7 @@ import {
|
||||
import type {
|
||||
WorkCategory,
|
||||
WorkOrder,
|
||||
WorkOrderShare,
|
||||
WorkerLeaderboardPeriod,
|
||||
WorkerUser,
|
||||
} from '@/types/worker-platform'
|
||||
@@ -361,17 +362,27 @@ export default function WorkerHallPage() {
|
||||
requestId: createRequestId('share'),
|
||||
})
|
||||
message.success('拼单成功,已进入我的订单')
|
||||
const joinedShare = result.data?.share
|
||||
const currentProgress = sharingOrder.sharingProgress
|
||||
// 本地即时反馈:把刚拿到的份额合并进行上的 myShares,按钮据此切成「再拼一次」。
|
||||
// 只写 myShare 虽然也能让按钮变一次,但连续拼单时「已参与 N 次」会一直停在 1,
|
||||
// 且后端广播不带个人份额,必须在本地维护完整列表。
|
||||
const previousShares = resolveHallMyShares(sharingOrder)
|
||||
const joinedQuantity = Number(joinedShare?.quantity || sharingQuantity)
|
||||
const nextShares = joinedShare
|
||||
? [...previousShares.filter((share) => share.shareId !== joinedShare.shareId), joinedShare]
|
||||
: previousShares
|
||||
queryClient.setQueriesData({ queryKey: ['worker-hall-orders'] }, (current: unknown) =>
|
||||
patchWorkerWorkOrderInfiniteEnvelope(current, {
|
||||
operation: 'upsert',
|
||||
entityId: sharingOrder.workOrderId,
|
||||
data: {
|
||||
...sharingOrder,
|
||||
myShare: { quantity: Number(result.data.share?.quantity || sharingQuantity) },
|
||||
myShare: joinedShare || sharingOrder.myShare || null,
|
||||
myShares: nextShares,
|
||||
sharingProgress: {
|
||||
joinedQuantity:
|
||||
Number(currentProgress?.joinedQuantity || 0) + Number(sharingQuantity || 0),
|
||||
...currentProgress,
|
||||
joinedQuantity: Number(currentProgress?.joinedQuantity || 0) + joinedQuantity,
|
||||
pendingSubmissionCount: Number(currentProgress?.pendingSubmissionCount || 0) + 1,
|
||||
},
|
||||
},
|
||||
@@ -1163,13 +1174,18 @@ type HallCardProps = {
|
||||
}
|
||||
|
||||
/**
|
||||
* 我在该工单的份额摘要:参与次数 + 累计份数。
|
||||
* 我在该工单的全部有效份额。
|
||||
*
|
||||
* 同一打手在同一工单可以多次拼单,`myShares` 是全部有效份额;旧数据只有 `myShare`。
|
||||
* 大厅按钮据此固定显示「再拼一次」,不再随参与次数改文案。
|
||||
*/
|
||||
function resolveHallMyShares(order: WorkOrder): WorkOrderShare[] {
|
||||
if (order.myShares?.length) return order.myShares
|
||||
return order.myShare ? [order.myShare] : []
|
||||
}
|
||||
|
||||
function resolveHallMyShareSummary(order: WorkOrder): { count: number; quantity: number } {
|
||||
const shares = order.myShares?.length ? order.myShares : order.myShare ? [order.myShare] : []
|
||||
const shares = resolveHallMyShares(order)
|
||||
return {
|
||||
count: shares.length,
|
||||
quantity: shares.reduce((total, share) => total + Number(share.quantity || 0), 0),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
CopyOutlined,
|
||||
DownOutlined,
|
||||
EditOutlined,
|
||||
EyeOutlined,
|
||||
MessageOutlined,
|
||||
@@ -8,6 +9,7 @@ import {
|
||||
SearchOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import { Alert, Button, Empty, Input, Pagination, Spin, Tag, Typography } from 'antd'
|
||||
import { useState } from 'react'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
import { DeadlineCountdown } from '@/components/DeadlineCountdown'
|
||||
@@ -238,6 +240,9 @@ function WorkerOrderMobileCard({
|
||||
| 'onRefresh'
|
||||
| 'onPageChange'
|
||||
> & { order: WorkOrder }) {
|
||||
/** 拼单明细默认折叠,点标题行展开;单份订单不显示该区块。 */
|
||||
const [sharesExpanded, setSharesExpanded] = useState(false)
|
||||
const shareCount = order.myShares?.length || 0
|
||||
const items = getMaterialDetailItems(order).filter((item) => String(item.value || '').trim())
|
||||
const screenshots = getMaterialScreenshots(order)
|
||||
const acceptanceFiles = getUniqueAcceptanceFiles(getWorkerAcceptance(order))
|
||||
@@ -343,12 +348,23 @@ function WorkerOrderMobileCard({
|
||||
<span className="worker-order-mobile-sub-time">{formatDateTime(order.assignedAt)}</span>
|
||||
</div>
|
||||
|
||||
{(order.myShares?.length || 0) > 1 && renderShareTable ? (
|
||||
{shareCount > 1 && renderShareTable ? (
|
||||
<div className="worker-order-mobile-shares">
|
||||
<Typography.Text strong style={{ fontSize: 12 }}>
|
||||
拼单明细({order.myShares?.length} 份)
|
||||
</Typography.Text>
|
||||
{renderShareTable(order)}
|
||||
<button
|
||||
type="button"
|
||||
className="worker-order-mobile-shares-toggle"
|
||||
aria-expanded={sharesExpanded}
|
||||
onClick={() => setSharesExpanded((previous) => !previous)}
|
||||
>
|
||||
<span>拼单明细({shareCount} 份)</span>
|
||||
<span className="worker-order-mobile-shares-hint">
|
||||
{sharesExpanded ? '收起' : '展开'}
|
||||
<DownOutlined rotate={sharesExpanded ? 180 : 0} />
|
||||
</span>
|
||||
</button>
|
||||
{sharesExpanded ? (
|
||||
<div className="worker-order-mobile-shares-body">{renderShareTable(order)}</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
|
||||
@@ -22,11 +22,14 @@ const SHARE_STATUS_META: Record<string, { label: string; color: string }> = {
|
||||
*/
|
||||
export function WorkerOrderShareTable({
|
||||
order,
|
||||
mobile = false,
|
||||
onOpenAcceptance,
|
||||
onOpenCancelRequest,
|
||||
onRemindAcceptance,
|
||||
}: {
|
||||
order: WorkOrder
|
||||
/** 移动端改成卡片列表,避免 9 列表格在窄屏被压成竖排文字。 */
|
||||
mobile?: boolean
|
||||
onOpenAcceptance: (order: WorkOrder, shareId: number) => void
|
||||
onOpenCancelRequest: (order: WorkOrder, shareId: number) => void
|
||||
onRemindAcceptance: (order: WorkOrder) => void
|
||||
@@ -41,6 +44,48 @@ export function WorkerOrderShareTable({
|
||||
|
||||
if (shares.length === 0) return null
|
||||
|
||||
const renderShareActions = (share: WorkOrderShare) => {
|
||||
const canAccept = !isTimedOut && share.status === 'joined'
|
||||
const canEdit = !isTimedOut && ['joined', 'submitted'].includes(String(share.status))
|
||||
const canRemind = !isTimedOut && share.status === 'submitted'
|
||||
const canCancel = !isTimedOut && ['joined', 'submitted'].includes(String(share.status))
|
||||
if (!canAccept && !canEdit && !canRemind && !canCancel) {
|
||||
return (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
无
|
||||
</Typography.Text>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Space size={6} wrap>
|
||||
{canAccept ? (
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
onClick={() => onOpenAcceptance(order, share.shareId)}
|
||||
>
|
||||
验收
|
||||
</Button>
|
||||
) : null}
|
||||
{canEdit && share.status === 'submitted' ? (
|
||||
<Button size="small" onClick={() => onOpenAcceptance(order, share.shareId)}>
|
||||
补充图片
|
||||
</Button>
|
||||
) : null}
|
||||
{canRemind ? (
|
||||
<Button size="small" onClick={() => onRemindAcceptance(order)}>
|
||||
催验收
|
||||
</Button>
|
||||
) : null}
|
||||
{canCancel ? (
|
||||
<Button danger size="small" onClick={() => onOpenCancelRequest(order, share.shareId)}>
|
||||
申请取消
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
)
|
||||
}
|
||||
|
||||
const columns: TableColumnsType<WorkOrderShare> = [
|
||||
{
|
||||
title: '份额',
|
||||
@@ -154,50 +199,79 @@ export function WorkerOrderShareTable({
|
||||
{
|
||||
title: '操作',
|
||||
width: 190,
|
||||
render: (_, share) => {
|
||||
const canAccept = !isTimedOut && share.status === 'joined'
|
||||
const canEdit = !isTimedOut && ['joined', 'submitted'].includes(String(share.status))
|
||||
const canRemind = !isTimedOut && share.status === 'submitted'
|
||||
const canCancel = !isTimedOut && ['joined', 'submitted'].includes(String(share.status))
|
||||
if (!canAccept && !canEdit && !canRemind && !canCancel) {
|
||||
return (
|
||||
<Typography.Text type="secondary" style={{ fontSize: 12 }}>
|
||||
无
|
||||
</Typography.Text>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Space size={6} wrap>
|
||||
{canAccept ? (
|
||||
<Button
|
||||
type="primary"
|
||||
size="small"
|
||||
onClick={() => onOpenAcceptance(order, share.shareId)}
|
||||
>
|
||||
验收
|
||||
</Button>
|
||||
) : null}
|
||||
{canEdit && share.status === 'submitted' ? (
|
||||
<Button size="small" onClick={() => onOpenAcceptance(order, share.shareId)}>
|
||||
补充图片
|
||||
</Button>
|
||||
) : null}
|
||||
{canRemind ? (
|
||||
<Button size="small" onClick={() => onRemindAcceptance(order)}>
|
||||
催验收
|
||||
</Button>
|
||||
) : null}
|
||||
{canCancel ? (
|
||||
<Button danger size="small" onClick={() => onOpenCancelRequest(order, share.shareId)}>
|
||||
申请取消
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
render: (_, share) => renderShareActions(share),
|
||||
},
|
||||
]
|
||||
|
||||
if (mobile) {
|
||||
return (
|
||||
<div className="worker-order-share-cards">
|
||||
{shares.map((share, index) => {
|
||||
const meta = SHARE_STATUS_META[String(share.status)] || {
|
||||
label: String(share.status || '-'),
|
||||
color: 'default',
|
||||
}
|
||||
const problemNote = String(share.problemNote || '').trim()
|
||||
const canAct = !isTimedOut && ['joined', 'submitted'].includes(String(share.status))
|
||||
return (
|
||||
<div className="worker-order-share-card" key={share.shareId}>
|
||||
<div className="worker-order-share-card-head">
|
||||
<Typography.Text strong className="worker-order-share-card-title">
|
||||
第 {index + 1} 份 · #{share.shareId}
|
||||
</Typography.Text>
|
||||
<Tag color={meta.color} style={{ marginInlineEnd: 0 }}>
|
||||
{meta.label}
|
||||
</Tag>
|
||||
</div>
|
||||
<div className="worker-order-share-card-meta">
|
||||
<div className="worker-order-share-card-meta-item">
|
||||
<span className="worker-order-share-card-meta-label">数量</span>
|
||||
<span className="worker-order-share-card-meta-value">{share.quantity} 份</span>
|
||||
</div>
|
||||
<div className="worker-order-share-card-meta-item">
|
||||
<span className="worker-order-share-card-meta-label">奖励</span>
|
||||
<span className="worker-order-share-card-meta-value" style={{ color: '#cf1322' }}>
|
||||
{formatMoney(share.shareReward)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="worker-order-share-card-meta-item">
|
||||
<span className="worker-order-share-card-meta-label">押金</span>
|
||||
<span className="worker-order-share-card-meta-value">
|
||||
{formatMoney(share.shareDeposit)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="worker-order-share-card-line">
|
||||
<span className="worker-order-share-card-line-label">截止时间</span>
|
||||
<span className="worker-order-share-card-line-value">
|
||||
{share.deadlineAt ? formatDateTime(share.deadlineAt) : '不限时'}
|
||||
</span>
|
||||
{share.deadlineAt && share.status === 'joined' && !isTimedOut ? (
|
||||
<DeadlineCountdown deadlineAt={share.deadlineAt} />
|
||||
) : null}
|
||||
</div>
|
||||
{share.problemMarked ? (
|
||||
<div className="worker-order-share-card-problem">
|
||||
<Tag color="red" style={{ marginInlineEnd: 6 }}>
|
||||
问题单
|
||||
</Tag>
|
||||
{problemNote || '后台已标记该份额有问题'}
|
||||
</div>
|
||||
) : null}
|
||||
<div className="worker-order-share-card-acceptance">
|
||||
<span className="worker-order-share-card-line-label">验收信息</span>
|
||||
<ShareAcceptanceCell share={share} />
|
||||
</div>
|
||||
{canAct ? (
|
||||
<div className="worker-order-share-card-actions">{renderShareActions(share)}</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<PercentTable<WorkOrderShare>
|
||||
rowKey="shareId"
|
||||
|
||||
@@ -592,6 +592,7 @@ export default function WorkerOrdersPage() {
|
||||
return (
|
||||
<WorkerOrderShareTable
|
||||
order={order}
|
||||
mobile={isMobile}
|
||||
onOpenAcceptance={openAcceptanceForShare}
|
||||
onOpenCancelRequest={openCancelRequestForShare}
|
||||
onRemindAcceptance={(target) => {
|
||||
|
||||
Reference in New Issue
Block a user