diff --git a/pages/case/components/archive-detail/follow-up-manage-tab.vue b/pages/case/components/archive-detail/follow-up-manage-tab.vue index 6e576c8..59dcabc 100644 --- a/pages/case/components/archive-detail/follow-up-manage-tab.vue +++ b/pages/case/components/archive-detail/follow-up-manage-tab.vue @@ -279,6 +279,8 @@ const typeOptions = [ ]; const teamOptions = ref([{ label: "全部", value: "ALL" }]); +const teamNameMap = ref({}); +const loadedTeamNameIds = new Set(); const query = reactive({ isMy: false, @@ -401,6 +403,89 @@ function getExecuteTeamId(todo) { .trim(); } +function resolveTeamName(id) { + const tid = String(id || "").trim(); + if (!tid) return ""; + const cached = teamNameMap.value?.[tid]; + if (cached) return String(cached); + const list = teamOptions.value || []; + const hit = list.find((i) => i && i.value === tid); + if (hit?.label && hit.label !== "全部") return String(hit.label); + return ""; +} + +let teamNameBatchInflight = null; +async function batchLoadTeamNames(teamIds) { + const ids = Array.isArray(teamIds) + ? teamIds.map((v) => String(v || "").trim()).filter(Boolean) + : []; + if (!ids.length) return; + const uniq = Array.from(new Set(ids)); + const unknown = uniq.filter((tid) => { + if (loadedTeamNameIds.has(tid)) return false; + const cached = teamNameMap.value?.[tid]; + if (cached) return false; + const list = teamOptions.value || []; + const hit = list.find((i) => i && i.value === tid); + return !hit?.label; + }); + if (!unknown.length) return; + + if (teamNameBatchInflight) return teamNameBatchInflight; + + await ensureDoctor(); + const corpId = getCorpId(); + if (!corpId) return; + unknown.forEach((tid) => loadedTeamNameIds.add(tid)); + + teamNameBatchInflight = (async () => { + try { + const res = await api("getTeamById", { corpId, teamIds: unknown }, false); + if (res?.success) { + const rows = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : []; + const patch = rows.reduce((acc, t) => { + const id = String(t?.teamId || t?.id || t?._id || "").trim(); + if (!id) return acc; + const name = String(t?.name || t?.teamName || t?.team || "").trim(); + if (!name) return acc; + const existing = teamNameMap.value?.[id]; + if (existing) return acc; + acc[id] = name; + return acc; + }, {}); + if (Object.keys(patch).length) teamNameMap.value = { ...(teamNameMap.value || {}), ...patch }; + return; + } + } catch { + // ignore + } + + // fallback + const limit = 4; + let idx = 0; + const workers = Array.from({ length: Math.min(limit, unknown.length) }, async () => { + while (idx < unknown.length) { + const tid = unknown[idx++]; + try { + const res = await api("getTeamData", { corpId, teamId: tid }, false); + if (!res?.success) continue; + const data = res?.data && typeof res.data === "object" ? res.data : {}; + const name = String(data?.name || data?.teamName || data?.team || "").trim(); + if (!name) continue; + if (!teamNameMap.value?.[tid]) teamNameMap.value = { ...(teamNameMap.value || {}), [tid]: name }; + } catch { + // ignore + } + } + }); + await Promise.allSettled(workers); + })().finally(() => { + teamNameBatchInflight = null; + }); + + return teamNameBatchInflight; +} + const loadedTeamMemberIds = new Set(); const teamMemberInflight = new Map(); async function loadTeamMembers(teamId) { @@ -572,14 +657,38 @@ async function ensureTodoNames(todos) { }); await Promise.allSettled(workers); + await batchLoadTeamNames(teamIds); await batchLoadCorpMembers(unknownUserIds); // 重新补齐列表显示 - list.value = (Array.isArray(list.value) ? list.value : []).map((t) => ({ - ...t, - executorName: normalizeName(t?.executorName) || resolveUserName(t?.executorUserId), - creatorName: normalizeName(t?.creatorName) || resolveUserName(t?.creatorUserId), - })); + list.value = (Array.isArray(list.value) ? list.value : []).map((t) => { + const uId = t?.executorUserId; + const uName = resolveUserName(uId); + const finalExecutorName = + uName && uName !== String(uId || "") + ? uName + : normalizeName(t?.executorName) || uName; + + const cId = t?.creatorUserId; + const cName = resolveUserName(cId); + const finalCreatorName = + cName && cName !== String(cId || "") + ? cName + : normalizeName(t?.creatorName) || cName; + + const tid = getExecuteTeamId(t); + const tName = resolveTeamName(tid); + const finalTeamName = tName + ? tName + : normalizeName(t?.executeTeamName || t?.teamName) || tName; + + return { + ...t, + executorName: finalExecutorName, + creatorName: finalCreatorName, + executeTeamName: finalTeamName, + }; + }); })().finally(() => { ensureNamesInflight = null; }); @@ -631,6 +740,22 @@ function formatTodo(todo) { const status = getStatus(todo); const plannedExecutionTime = todo?.plannedExecutionTime; const createTime = todo?.createTime; + const teamId = getExecuteTeamId(todo); + + const uId = todo?.executorUserId; + const uName = resolveUserName(uId); + const finalExecutorName = + uName && uName !== String(uId || "") + ? uName + : normalizeName(todo?.executorName) || uName; + + const cId = todo?.creatorUserId; + const cName = resolveUserName(cId); + const finalCreatorName = + cName && cName !== String(cId || "") + ? cName + : normalizeName(todo?.creatorName) || cName; + return { ...todo, status, @@ -644,8 +769,12 @@ function formatTodo(todo) { createTime && dayjs(createTime).isValid() ? dayjs(createTime).format("YYYY-MM-DD HH:mm") : "", - executorName: resolveUserName(todo?.executorUserId), - creatorName: resolveUserName(todo?.creatorUserId), + executorName: finalExecutorName, + creatorName: finalCreatorName, + executeTeamId: teamId, + executeTeamName: + normalizeName(todo?.executeTeamName || todo?.teamName) || + resolveTeamName(teamId), }; } diff --git a/pages/case/components/archive-detail/health-profile-tab.vue b/pages/case/components/archive-detail/health-profile-tab.vue index 9cf5e86..ad919f6 100644 --- a/pages/case/components/archive-detail/health-profile-tab.vue +++ b/pages/case/components/archive-detail/health-profile-tab.vue @@ -72,8 +72,10 @@