feat(order-service): 增加提交资料确认与核对摘要
This commit is contained in:
@@ -56,7 +56,7 @@ function resolveErrorTitle(code: string) {
|
||||
}
|
||||
|
||||
export default function OrderServicePage() {
|
||||
const { message } = App.useApp()
|
||||
const { message, modal } = App.useApp()
|
||||
const navigate = useNavigate()
|
||||
const { orderNo: routeOrderNo } = useParams<{ orderNo?: string }>()
|
||||
const orderNo = String(routeOrderNo || '').trim()
|
||||
@@ -68,6 +68,7 @@ export default function OrderServicePage() {
|
||||
const [submittingId, setSubmittingId] = useState(0)
|
||||
const [screenshotsByOrder, setScreenshotsByOrder] = useState<Record<number, UploadedFile[]>>({})
|
||||
const submittingRef = useRef(false)
|
||||
const confirmationOpenRef = useRef(false)
|
||||
const requestSeqRef = useRef(0)
|
||||
const loadedOrderRef = useRef('')
|
||||
|
||||
@@ -146,9 +147,10 @@ export default function OrderServicePage() {
|
||||
void navigate(`/o/${encodeURIComponent(nextOrderNo)}`)
|
||||
}
|
||||
|
||||
async function handleSubmit(item: OrderServiceItem, values: Record<string, unknown>) {
|
||||
if (!orderNo || submittingRef.current) return
|
||||
function handleSubmit(item: OrderServiceItem, values: Record<string, unknown>) {
|
||||
if (!orderNo || submittingRef.current || confirmationOpenRef.current) return
|
||||
const screenshots = screenshotsByOrder[item.workOrderId] ?? item.screenshots ?? []
|
||||
const normalizedValues = normalizeFormFieldValues(item, values)
|
||||
const screenshotRule = item.screenshotsRule
|
||||
if (
|
||||
screenshotRule?.enabled &&
|
||||
@@ -159,12 +161,51 @@ export default function OrderServicePage() {
|
||||
return
|
||||
}
|
||||
|
||||
const confirmation = item.materialConfirmation
|
||||
if (!confirmation?.enabled) {
|
||||
void submitMaterial(item, normalizedValues, screenshots)
|
||||
return
|
||||
}
|
||||
|
||||
confirmationOpenRef.current = true
|
||||
modal.confirm({
|
||||
title: confirmation.title || '提交资料确认',
|
||||
content: (
|
||||
<MaterialConfirmationSummary
|
||||
item={item}
|
||||
platformOrderId={orderNo}
|
||||
values={normalizedValues}
|
||||
screenshots={screenshots}
|
||||
notice={
|
||||
confirmation.content ||
|
||||
'请确认资料填写准确无误。资料提交后不能修改,因个人资料填写错误导致的赠送错误,店铺概不负责!'
|
||||
}
|
||||
/>
|
||||
),
|
||||
okText: confirmation.confirmText || '确认提交',
|
||||
cancelText: confirmation.cancelText || '返回检查',
|
||||
centered: true,
|
||||
maskClosable: false,
|
||||
width: 560,
|
||||
onOk: () => submitMaterial(item, normalizedValues, screenshots),
|
||||
afterClose: () => {
|
||||
confirmationOpenRef.current = false
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async function submitMaterial(
|
||||
item: OrderServiceItem,
|
||||
fields: Record<string, string>,
|
||||
screenshots: UploadedFile[],
|
||||
) {
|
||||
if (!orderNo || submittingRef.current) return
|
||||
submittingRef.current = true
|
||||
setSubmittingId(item.workOrderId)
|
||||
try {
|
||||
const response = await submitOrderServiceMaterial(orderNo, {
|
||||
workOrderId: item.workOrderId,
|
||||
fields: normalizeFormFieldValues(item, values),
|
||||
fields,
|
||||
screenshots,
|
||||
})
|
||||
setSubmittedNames((current) => [
|
||||
@@ -261,31 +302,6 @@ export default function OrderServicePage() {
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{pageConfig?.announcement?.enabled && pageConfig.announcement.content ? (
|
||||
<section
|
||||
aria-label={pageConfig.announcement.title || '页面公告'}
|
||||
className="collect-link-announcement"
|
||||
style={{
|
||||
color: pageConfig.announcement.color,
|
||||
backgroundColor: pageConfig.announcement.backgroundColor,
|
||||
textAlign: pageConfig.announcement.textAlign,
|
||||
}}
|
||||
>
|
||||
<strong className="collect-link-announcement-title">
|
||||
{pageConfig.announcement.title || '公告'}
|
||||
</strong>
|
||||
<div
|
||||
className="collect-link-announcement-content"
|
||||
style={{
|
||||
fontSize: pageConfig.announcement.fontSize,
|
||||
fontWeight: pageConfig.announcement.fontWeight,
|
||||
}}
|
||||
>
|
||||
{pageConfig.announcement.content}
|
||||
</div>
|
||||
</section>
|
||||
) : null}
|
||||
|
||||
{submittedNames.length > 0 ? (
|
||||
<Alert
|
||||
type="success"
|
||||
@@ -509,6 +525,66 @@ function renderFieldInput(field: NonNullable<OrderServiceItem['fields']>[number]
|
||||
return <Input autoComplete="off" placeholder={placeholder} />
|
||||
}
|
||||
|
||||
function MaterialConfirmationSummary({
|
||||
item,
|
||||
platformOrderId,
|
||||
values,
|
||||
screenshots,
|
||||
notice,
|
||||
}: {
|
||||
item: OrderServiceItem
|
||||
platformOrderId: string
|
||||
values: Record<string, string>
|
||||
screenshots: UploadedFile[]
|
||||
notice: string
|
||||
}) {
|
||||
const screenshotRule = item.screenshotsRule
|
||||
return (
|
||||
<div className="collect-link-confirm">
|
||||
<div className="collect-link-confirm-meta">
|
||||
<span>{item.productName || item.categoryName || '订单商品'}</span>
|
||||
<span>订单号:{platformOrderId}</span>
|
||||
</div>
|
||||
|
||||
{item.fields && item.fields.length > 0 ? (
|
||||
<div className="collect-link-confirm-fields">
|
||||
{item.fields.map((field) => {
|
||||
const value = String(values[field.key] || '').trim()
|
||||
return (
|
||||
<div className="collect-link-confirm-field" key={field.key}>
|
||||
<span>{field.label}</span>
|
||||
<strong className={value ? '' : 'is-empty'}>{value || '未填写'}</strong>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{screenshotRule?.enabled ? (
|
||||
<div className="collect-link-confirm-screenshots">
|
||||
<div>
|
||||
<span>{screenshotRule.label || '截图'}</span>
|
||||
<strong>{screenshots.length} 张</strong>
|
||||
</div>
|
||||
{screenshots.length > 0 ? (
|
||||
<div className="collect-link-confirm-images">
|
||||
{screenshots.map((file) => (
|
||||
<img
|
||||
key={file.objectKey}
|
||||
alt={file.filename || '已上传截图'}
|
||||
src={file.thumbnailUrl || file.url}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="collect-link-confirm-content">{notice}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function normalizeFormFieldValues(item: OrderServiceItem, values: Record<string, unknown>) {
|
||||
const fields = new Map((item.fields || []).map((field) => [field.key, field]))
|
||||
return Object.fromEntries(
|
||||
|
||||
Reference in New Issue
Block a user