From 7e0371134b9db3cb9a61ad6b1f5549b54f28e157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=BA=A2=E5=85=B5?= <374362909@qq.com> Date: Sun, 15 Mar 2026 17:39:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=9B=E6=A0=87=E6=96=87=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../purchasingrequisition/bidfile-audit.vue | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/views/purchase/purchasingrequisition/bidfile-audit.vue b/src/views/purchase/purchasingrequisition/bidfile-audit.vue index e43a639..683808c 100644 --- a/src/views/purchase/purchasingrequisition/bidfile-audit.vue +++ b/src/views/purchase/purchasingrequisition/bidfile-audit.vue @@ -255,7 +255,6 @@ (''); const candidatesOptions = ref([]); const candidatesLoading = ref(false); const randomCandidates = ref([]); +const selectedCandidatesMap = ref>(new Map()); // 存储已选候选人的完整信息 const currentRepresentor = ref(null); const representorType = ref('purchase_rep'); -const randomSelectLoading = ref(false); // ==================== 计算属性 ==================== @@ -763,43 +762,41 @@ const searchCandidates = async (query: string) => { }; const onCandidatesChange = (teacherNos: string[]) => { - // 保留已选中的选项,防止清空搜索时选项丢失 - const selectedMap = new Map(); - randomCandidates.value.forEach((no) => { - const existing = candidatesOptions.value.find((item) => item.teacherNo === no); + // 保留已选中的候选人的完整信息 + const newMap = new Map(); + teacherNos.forEach((no) => { + // 先从已有映射中查找 + const existing = selectedCandidatesMap.value.get(no); if (existing) { - selectedMap.set(no, existing); + newMap.set(no, existing); + } else { + // 从当前选项列表中查找 + const fromOptions = candidatesOptions.value.find((item) => item.teacherNo === no); + if (fromOptions) { + newMap.set(no, fromOptions); + } } }); - // 如果新选中的选项中有不在当前选项列表中的,需要从之前的结果中找 - if (teacherNos.length > 0 && currentRepresentor.value) { - const currentNo = currentRepresentor.value.teacherNo; - if (teacherNos.includes(currentNo)) { - selectedMap.set(currentNo, currentRepresentor.value); - } - } + selectedCandidatesMap.value = newMap; }; -const handleRandomSelect = async () => { +const handleRandomSelect = () => { if (randomCandidates.value.length < 2) { ElMessage.warning('请至少选择2名候选人'); return; } - try { - randomSelectLoading.value = true; - const res = await randomSelectRepresentor(effectivePurchaseId.value, randomCandidates.value.join(',')); - if (res.code === 0 && res.data) { - currentRepresentor.value = res.data; - ElMessage.success(`随机抽取成功:${res.data.realName}`); - } else { - ElMessage.error(res.msg || '随机抽取失败'); - } - } catch (e: any) { - ElMessage.error(e?.msg || '随机抽取失败'); - } finally { - randomSelectLoading.value = false; + // 从已选择的候选人中随机抽取 + const candidates = Array.from(selectedCandidatesMap.value.values()); + if (candidates.length === 0) { + ElMessage.warning('未找到候选人信息'); + return; } + + const randomIndex = Math.floor(Math.random() * candidates.length); + const selected = candidates[randomIndex]; + currentRepresentor.value = selected; + ElMessage.success(`随机抽取成功:${selected.realName || selected.name}`); }; // ==================== 生命周期 ====================