fix(worker): 验收重复提交幂等,修复卡待验收与手动验收 500
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { PictureOutlined } from '@ant-design/icons'
|
||||
import { Button, Form, Input, Modal, Radio, Space, Tag, Typography } from 'antd'
|
||||
import type { FormInstance } from 'antd'
|
||||
import { useRef, useState } from 'react'
|
||||
|
||||
import ImageUpload from '@/components/files/ImageUpload'
|
||||
import VideoUpload from '@/components/files/VideoUpload'
|
||||
@@ -109,6 +110,22 @@ export function WorkerOrderModals({
|
||||
onSubmitGiftMaterial: (values: GiftMaterialFormValues) => void | Promise<void>
|
||||
}) {
|
||||
const feedbackItems = feedbacks.filter((item) => item.workOrderId === feedbackOrder?.workOrderId)
|
||||
// 验收提交/保存加锁:双击或慢响应时只允许一个请求在飞,避免后端重复结算。
|
||||
const acceptanceBusyRef = useRef(false)
|
||||
const [acceptanceBusy, setAcceptanceBusy] = useState(false)
|
||||
|
||||
async function runAcceptanceAction(action: () => void | Promise<void>) {
|
||||
if (acceptanceBusyRef.current) return
|
||||
acceptanceBusyRef.current = true
|
||||
setAcceptanceBusy(true)
|
||||
try {
|
||||
await action()
|
||||
} finally {
|
||||
acceptanceBusyRef.current = false
|
||||
setAcceptanceBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
@@ -237,18 +254,33 @@ export function WorkerOrderModals({
|
||||
<Space>
|
||||
<Button onClick={onCloseAcceptance}>取消</Button>
|
||||
{canSupplementAcceptedEvidence(editingOrder) ? (
|
||||
<Button type="primary" onClick={() => acceptanceForm.submit()}>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={acceptanceBusy}
|
||||
disabled={acceptanceBusy}
|
||||
onClick={() => acceptanceForm.submit()}
|
||||
>
|
||||
补充图片
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button
|
||||
onClick={() => void onSaveAcceptanceImages(acceptanceForm.getFieldsValue())}
|
||||
disabled={acceptanceBusy}
|
||||
onClick={() =>
|
||||
void runAcceptanceAction(() =>
|
||||
onSaveAcceptanceImages(acceptanceForm.getFieldsValue()),
|
||||
)
|
||||
}
|
||||
>
|
||||
{hasSubmittedAcceptance(editingOrder) ? '保存修改' : '保存暂存'}
|
||||
</Button>
|
||||
{canSubmitAcceptance(editingOrder) ? (
|
||||
<Button type="primary" onClick={() => acceptanceForm.submit()}>
|
||||
<Button
|
||||
type="primary"
|
||||
loading={acceptanceBusy}
|
||||
disabled={acceptanceBusy}
|
||||
onClick={() => acceptanceForm.submit()}
|
||||
>
|
||||
提交验收
|
||||
</Button>
|
||||
) : null}
|
||||
@@ -258,7 +290,11 @@ export function WorkerOrderModals({
|
||||
) : null
|
||||
}
|
||||
>
|
||||
<Form form={acceptanceForm} layout="vertical" onFinish={onSubmitAcceptance}>
|
||||
<Form
|
||||
form={acceptanceForm}
|
||||
layout="vertical"
|
||||
onFinish={(values) => runAcceptanceAction(() => onSubmitAcceptance(values))}
|
||||
>
|
||||
{!editingOrder || !canSupplementAcceptedEvidence(editingOrder) ? (
|
||||
<Form.Item label="完成说明" name="note">
|
||||
<Input.TextArea rows={3} placeholder="可补充代练结果、注意事项或截图说明。" />
|
||||
|
||||
Reference in New Issue
Block a user