Compare commits

...

5 Commits

3 changed files with 183 additions and 43 deletions

View File

@ -55,7 +55,7 @@
<!-- History or Suggestions (when no search) --> <!-- History or Suggestions (when no search) -->
<view v-else class="search-tips"> <view v-else class="search-tips">
<text class="tips-text">输入患者名称手机号或病案号进行搜索</text> <!-- <text class="tips-text">输入患者名称手机号或病案号进行搜索</text> -->
</view> </view>
</view> </view>
</template> </template>

View File

@ -56,7 +56,9 @@
import { computed, onMounted, onUnmounted, ref } from 'vue'; import { computed, onMounted, onUnmounted, ref } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app'; import { onLoad, onShow } from '@dcloudio/uni-app';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
import api from '@/utils/api'; import api from '@/utils/api';
import useAccountStore from '@/store/account';
import { loading, hideLoading, toast } from '@/utils/widget'; import { loading, hideLoading, toast } from '@/utils/widget';
import { getVisitRecordTemplate } from './components/archive-detail/templates'; import { getVisitRecordTemplate } from './components/archive-detail/templates';
import { normalizeVisitRecordFormData } from './utils/visit-record'; import { normalizeVisitRecordFormData } from './utils/visit-record';
@ -65,6 +67,10 @@ import { normalizeFileUrl } from '@/utils/file';
const scrollHeight = ref(0); const scrollHeight = ref(0);
const accountStore = useAccountStore();
const { account, doctorInfo } = storeToRefs(accountStore);
const { getDoctorInfo } = accountStore;
const archiveId = ref(''); const archiveId = ref('');
const id = ref(''); const id = ref('');
const medicalType = ref(''); const medicalType = ref('');
@ -76,6 +82,8 @@ let recordChangedHandler = null;
const userNameMap = ref({}); const userNameMap = ref({});
const loadedMembersTeamId = ref(''); const loadedMembersTeamId = ref('');
const corpMemberNameInflight = new Map(); // userId -> Promise<string>
const corpMemberNameTried = new Set(); // avoid retry storms on failures
const files = computed(() => { const files = computed(() => {
const arr = record.value?.files; const arr = record.value?.files;
@ -155,9 +163,48 @@ function formatPositiveFind(v, { withOpinion = false } = {}) {
return normalizeText(v); return normalizeText(v);
} }
function getCorpId() { async function ensureDoctor() {
if (doctorInfo.value) return;
if (!account.value?.openid) return;
try {
await getDoctorInfo();
} catch {
// ignore
}
}
function extractDisplayNameFromAny(raw) {
const obj = raw && typeof raw === 'object' ? raw : {};
const candidate =
obj.anotherName ??
obj.name ??
obj.username ??
obj.userName ??
obj.nickname ??
obj.nickName ??
obj.realName ??
obj.memberName ??
obj.doctorName ??
obj.title ??
'';
return candidate ? String(candidate).trim() : '';
}
function extractDisplayNameFromCorpMember(row) {
const m = row && typeof row === 'object' ? row : {};
return String(m.anotherName || m.name || '').trim();
}
function getCorpIdForQuery() {
// 使
const d = doctorInfo.value || {};
const a = account.value || {};
const team = uni.getStorageSync('ykt_case_current_team') || {}; const team = uni.getStorageSync('ykt_case_current_team') || {};
return team?.corpId ? String(team.corpId) : ''; return String(d.corpId || a.corpId || team.corpId || '') || '';
}
function getCorpId() {
return getCorpIdForQuery();
} }
function getTeamId() { function getTeamId() {
@ -220,11 +267,107 @@ async function loadTeamMembers() {
} }
} }
async function prefetchCorpMemberName(userId) {
const id = normalizeUserId(userId);
if (!id || !isLikelyUserId(id)) return '';
const map = userNameMap.value || {};
const existing = String(map[id] || map[id.toLowerCase()] || '').trim();
if (existing && existing !== id) return existing;
if (corpMemberNameInflight.has(id)) return corpMemberNameInflight.get(id);
if (corpMemberNameTried.has(id)) return '';
const p = (async () => {
corpMemberNameTried.add(id);
await ensureDoctor();
const corpId = getCorpIdForQuery();
// 1) userid
try {
const res = await api('getCorpMemberHomepageInfo', { corpId, corpUserId: id }, false);
if (res?.success) {
const name =
extractDisplayNameFromAny(res?.data) ||
extractDisplayNameFromAny(res?.data?.data) ||
extractDisplayNameFromAny(res?.data?.member) ||
'';
if (name) return name;
}
} catch {
// ignore
}
// 1.1) userId
try {
const res = await api('getCorpMemberHomepageInfo', { corpId, userId: id }, false);
if (res?.success) {
const name =
extractDisplayNameFromAny(res?.data) ||
extractDisplayNameFromAny(res?.data?.data) ||
extractDisplayNameFromAny(res?.data?.member) ||
'';
if (name) return name;
}
} catch {
// ignore
}
// 2)
try {
const res = await api(
'getCorpMember',
{
corpId,
page: 1,
pageSize: 10,
params: {
corpId,
memberList: [id],
},
},
false
);
if (res?.success) {
const rows = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : [];
const row = rows.find((m) => normalizeUserId(m?.userid || m?.userId || m?.corpUserId || '') === id) || rows[0] || null;
const name = extractDisplayNameFromCorpMember(row) || '';
if (name) return name;
}
} catch {
// ignore
}
return '';
})()
.then((name) => {
const display = String(name || '').trim();
if (display) {
const next = { ...(userNameMap.value || {}) };
next[id] = display;
next[id.toLowerCase()] = display;
userNameMap.value = next;
}
return display;
})
.finally(() => {
corpMemberNameInflight.delete(id);
});
corpMemberNameInflight.set(id, p);
return p;
}
function resolveUserName(userId) { function resolveUserName(userId) {
const id = normalizeUserId(userId); const id = normalizeUserId(userId);
if (!id) return ''; if (!id) return '';
const map = userNameMap.value || {}; const map = userNameMap.value || {};
return String(map[id] || map[id.toLowerCase()] || id); const resolved = String(map[id] || map[id.toLowerCase()] || '').trim();
if (resolved) return resolved;
// teamId/ localStorage
void prefetchCorpMemberName(id);
return id;
} }
function parseAnyTimeMs(v) { function parseAnyTimeMs(v) {
@ -350,8 +493,8 @@ const sections = computed(() => {
}); });
async function loadTemplate(t) { async function loadTemplate(t) {
if (!t) return null;
const corpId = getCorpId(); const corpId = getCorpId();
if (!corpId || !t) return null;
try { try {
const res = await api('getCurrentTemplate', { corpId, templateType: t }); const res = await api('getCurrentTemplate', { corpId, templateType: t });
if (!res?.success) return null; if (!res?.success) return null;
@ -388,12 +531,9 @@ const topText = computed(() => {
}); });
async function fetchRecord({ silent = false } = {}) { async function fetchRecord({ silent = false } = {}) {
if (!archiveId.value || !id.value || !medicalType.value) return false; if (!archiveId.value || !id.value || !medicalType.value) return { ok: false, reason: 'request_failed' };
await ensureDoctor();
const corpId = getCorpId(); const corpId = getCorpId();
if (!corpId) {
if (!silent) toast('缺少 corpId');
return false;
}
if (!silent) loading('加载中...'); if (!silent) loading('加载中...');
try { try {
@ -404,19 +544,22 @@ async function fetchRecord({ silent = false } = {}) {
medicalType: medicalType.value, medicalType: medicalType.value,
}); });
const r = res?.record || res?.data?.record || null; const r = res?.record || res?.data?.record || null;
if (!res?.success || !r) return false; if (res?.success && r) {
const raw = String(r?.templateType || r?.medicalType || medicalType.value || '');
rawType.value = raw;
const ui = normalizeMedicalType(raw);
record.value = normalizeVisitRecordFormData(ui, r);
temp.value = await loadTemplate(raw);
uni.setNavigationBarTitle({ title: String(typeLabel.value || '病历详情') });
return { ok: true, reason: '' };
}
const raw = String(r?.templateType || r?.medicalType || medicalType.value || ''); const msg = String(res?.message || res?.msg || '').trim();
rawType.value = raw; const isNotFound = (res?.success && !r) || /不存在|not\s*found|not\s*exist/i.test(msg);
const ui = normalizeMedicalType(raw); return { ok: false, reason: isNotFound ? 'not_found' : 'request_failed' };
record.value = normalizeVisitRecordFormData(ui, r);
temp.value = await loadTemplate(raw);
uni.setNavigationBarTitle({ title: String(typeLabel.value || '病历详情') });
return true;
} catch (error) { } catch (error) {
console.error('获取病历记录失败:', error); console.error('获取病历记录失败:', error);
if (!silent) toast('加载失败'); return { ok: false, reason: 'request_failed' };
return false;
} finally { } finally {
if (!silent) hideLoading(); if (!silent) hideLoading();
} }
@ -442,9 +585,9 @@ onLoad(async (opt) => {
// xx // xx
void loadTeamMembers(); void loadTeamMembers();
const ok = await fetchRecord(); const result = await fetchRecord();
if (!ok) { if (!result?.ok) {
toast('记录不存在'); toast(result?.reason === 'not_found' ? '记录不存在' : '请求失败');
setTimeout(() => uni.navigateBack(), 300); setTimeout(() => uni.navigateBack(), 300);
} }
}); });

View File

@ -485,28 +485,25 @@ async function fetchCorpMemberDisplayName(userId) {
// ignore // ignore
} }
// 2) corpUserId // 2) memberList
try { try {
const res = await api('getCorpMemberData', { corpId, corpUserId: id }, false); const res = await api(
'getCorpMember',
{
page: 1,
pageSize: 10,
params: {
corpId,
memberList: [id],
},
},
false
);
if (res?.success) { if (res?.success) {
const name = const rows = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : [];
extractDisplayNameFromAny(res?.data) || const row =
extractDisplayNameFromAny(res?.data?.data) || rows.find((m) => normalizeUserId(m?.userid || m?.userId || m?.corpUserId || '') === id) || rows[0] || null;
''; const name = extractDisplayNameFromCorpMember(row) || '';
if (name) return name;
}
} catch {
// ignore
}
// 2.1) userId
try {
const res = await api('getCorpMemberData', { corpId, userId: id }, false);
if (res?.success) {
const name =
extractDisplayNameFromAny(res?.data) ||
extractDisplayNameFromAny(res?.data?.data) ||
'';
if (name) return name; if (name) return name;
} }
} catch { } catch {