评审结果提交增加防抖

This commit is contained in:
孙景学
2025-08-05 18:22:26 +08:00
parent f432c6e519
commit 0232f4e35e
2 changed files with 64 additions and 45 deletions

View File

@ -50,11 +50,13 @@ const GroupLeaderModal: React.FC<GroupLeaderModalProps> = ({
dispatch, dispatch,
}) => { }) => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [suppliers, setSuppliers] = useState<any[]>([]); const [suppliers, setSuppliers] = useState < any[] > ([]);
const [items, setItems] = useState<any[]>([]); const [items, setItems] = useState < any[] > ([]);
const [supplierReviewerMap, setSupplierReviewerMap] = useState<Record<string, string[]>>({}); const [supplierReviewerMap, setSupplierReviewerMap] = useState < Record < string, string[]>> ({});
const [groupSummaryResult, setGroupSummaryResult] = useState<{ [k: string]: '0' | '1' | undefined }>({}); const [groupSummaryResult, setGroupSummaryResult] = useState < { [k: string]: '0' | '1' | undefined } > ({});
const [remarkModal, setRemarkModal] = useState({ open: false, remark: '', file: undefined as any }); const [remarkModal, setRemarkModal] = useState({ open: false, remark: '', file: undefined as any });
//提交防抖
const [submitting, setSubmitting] = useState(false);
// 适配新结构 // 适配新结构
useEffect(() => { useEffect(() => {
@ -66,7 +68,7 @@ const GroupLeaderModal: React.FC<GroupLeaderModalProps> = ({
setSuppliers(supplierList); setSuppliers(supplierList);
// ============ 1. 收集所有评审项itemType==='item' =========== // ============ 1. 收集所有评审项itemType==='item' ===========
const allItemsSet = new Set<string>(); const allItemsSet = new Set < string > ();
const allItemsArr: any[] = []; const allItemsArr: any[] = [];
supplierList.forEach((sup: any) => { supplierList.forEach((sup: any) => {
(sup.coscoAccessUserItemList || []).forEach((u: any) => { (sup.coscoAccessUserItemList || []).forEach((u: any) => {
@ -81,7 +83,7 @@ const GroupLeaderModal: React.FC<GroupLeaderModalProps> = ({
// ============ 2. 组员收集 ============= // ============ 2. 组员收集 =============
const tempReviewerMap: Record<string, string[]> = {}; const tempReviewerMap: Record<string, string[]> = {};
supplierList.forEach((sup: any) => { supplierList.forEach((sup: any) => {
const reviewerSet = new Set<string>(); const reviewerSet = new Set < string > ();
(sup.coscoAccessUserItemList || []).forEach((u: any) => { (sup.coscoAccessUserItemList || []).forEach((u: any) => {
if (u.itemType === 'item' && u.reviewBy) { if (u.itemType === 'item' && u.reviewBy) {
reviewerSet.add(u.reviewBy); reviewerSet.add(u.reviewBy);
@ -136,12 +138,20 @@ const GroupLeaderModal: React.FC<GroupLeaderModalProps> = ({
return return
} }
} }
if (submitting) return; // 防重复提交
setSubmitting(true);
try {
update({ coscoAccessUserItemList: summaryParams, accessWorkId }).then((res: any) => { update({ coscoAccessUserItemList: summaryParams, accessWorkId }).then((res: any) => {
if (res.code === 200) { if (res.code === 200) {
message.success('提交成功'); message.success('提交成功');
onSubmit && onSubmit(); onSubmit && onSubmit();
} }
}); });
}
finally {
setSubmitting(false); // 无论成功失败都解锁
}
}; };
// 构造二级表头 // 构造二级表头
@ -270,7 +280,7 @@ const GroupLeaderModal: React.FC<GroupLeaderModalProps> = ({
{view ? '关闭' : '取消'} {view ? '关闭' : '取消'}
</Button>, </Button>,
!view && ( !view && (
<Button key="submit" type="primary" onClick={handleSubmit}> <Button key="submit" type="primary" onClick={handleSubmit} disabled={submitting}>
</Button> </Button>
) )

View File

@ -8,7 +8,7 @@ import { connect } from 'umi';
interface ResultModalProps { interface ResultModalProps {
visible: boolean; visible: boolean;
view: boolean; view: boolean;
record?: { id?: string; [key: string]: any } | null; record?: { id?: string;[key: string]: any } | null;
onCancel: () => void; onCancel: () => void;
onSubmit: () => void; onSubmit: () => void;
dispatch: any; dispatch: any;
@ -61,19 +61,20 @@ const ResultModal: React.FC<ResultModalProps> = ({
onSubmit, onSubmit,
dispatch, dispatch,
}) => { }) => {
const [suppliers, setSuppliers] = useState<any[]>([]); const [suppliers, setSuppliers] = useState < any[] > ([]);
const [items, setItems] = useState<any[]>([]); const [items, setItems] = useState < any[] > ([]);
const [userItemMatrix, setUserItemMatrix] = useState<any[][]>([]); const [userItemMatrix, setUserItemMatrix] = useState < any[][] > ([]);
const [cellData, setCellData] = useState<{ [userItemId: string]: CellValue }>({}); const [cellData, setCellData] = useState < { [userItemId: string]: CellValue } > ({});
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
// 查看备注弹窗 // 查看备注弹窗
const [remarkModal, setRemarkModal] = useState({ open: false, remark: '', file: undefined as any }); const [remarkModal, setRemarkModal] = useState({ open: false, remark: '', file: undefined as any });
// 备注弹窗 // 备注弹窗
const [remarksModalVisible, setRemarksModalVisible] = useState(false); const [remarksModalVisible, setRemarksModalVisible] = useState(false);
const [remarks, setRemarks] = useState(''); const [remarks, setRemarks] = useState('');
const [fileList, setFileList] = useState<any[]>([]); const [fileList, setFileList] = useState < any[] > ([]);
const [currentUserItemId, setCurrentUserItemId] = useState<string | null>(null); const [currentUserItemId, setCurrentUserItemId] = useState < string | null > (null);
//提交防抖
const [submitting, setSubmitting] = useState(false);
// 拉取并整理表格数据 // 拉取并整理表格数据
useEffect(() => { useEffect(() => {
if (visible && record?.id) { if (visible && record?.id) {
@ -217,23 +218,31 @@ const ResultModal: React.FC<ResultModalProps> = ({
}); });
}); });
let accessWorkId = '' let accessWorkId = ''
if(record?.id) { if (record?.id) {
accessWorkId = record?.id accessWorkId = record?.id
} }
for (let index = 0; index < result.length; index++) { for (let index = 0; index < result.length; index++) {
if(result[index].reviewResult === null || result[index].reviewResult === undefined) { if (result[index].reviewResult === null || result[index].reviewResult === undefined) {
message.warning('有未评审项'); message.warning('有未评审项');
return return
} }
} }
if (submitting) return; // 防重复提交
setSubmitting(true);
try {
// 提交审核 // 提交审核
update( {coscoAccessUserItemList: result, accessWorkId }).then((res) => { update({ coscoAccessUserItemList: result, accessWorkId }).then((res) => {
if(res.code == 200) { if (res.code == 200) {
message.success('提交成功'); message.success('提交成功');
onSubmit() onSubmit()
} }
}) })
}
finally {
setSubmitting(false); // 无论成功失败都解锁
}
}; };
// 组装表头 // 组装表头
@ -273,13 +282,13 @@ const ResultModal: React.FC<ResultModalProps> = ({
<> <>
{view && ( {view && (
<> <>
<span style={{color: v.reviewResult === '0'? '#52c41a': '#f5222d' }}> {v.reviewResult === '0'? '合格': '不合格'}</span> <span style={{ color: v.reviewResult === '0' ? '#52c41a' : '#f5222d' }}> {v.reviewResult === '0' ? '合格' : '不合格'}</span>
<Button type="link" size="small" onClick={() => <Button type="link" size="small" onClick={() =>
setRemarkModal({ open: true, remark: v.remark || '', file: v.file }) setRemarkModal({ open: true, remark: v.remark || '', file: v.file })
}></Button> }></Button>
</> </>
)} )}
{ !view && ( {!view && (
<div> <div>
<Radio.Group <Radio.Group
value={ value={
@ -330,7 +339,7 @@ const ResultModal: React.FC<ResultModalProps> = ({
{view ? '关闭' : '取消'} {view ? '关闭' : '取消'}
</Button>, </Button>,
!view && ( !view && (
<Button key="submit" type="primary" onClick={handleSubmit}> <Button key="submit" type="primary" onClick={handleSubmit} disabled={submitting}>
</Button> </Button>
) )