Compare commits
5 Commits
6b740bda78
...
92cf611395
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92cf611395 | ||
| 6a6b8abf9f | |||
| c90b8e782b | |||
| 150c6072d7 | |||
| 292a5b0118 |
@ -55,7 +55,7 @@
|
||||
|
||||
<!-- History or Suggestions (when no search) -->
|
||||
<view v-else class="search-tips">
|
||||
<text class="tips-text">输入患者名称、手机号或病案号进行搜索</text>
|
||||
<!-- <text class="tips-text">输入患者名称、手机号或病案号进行搜索</text> -->
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@ -56,7 +56,9 @@
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||||
import dayjs from 'dayjs';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import api from '@/utils/api';
|
||||
import useAccountStore from '@/store/account';
|
||||
import { loading, hideLoading, toast } from '@/utils/widget';
|
||||
import { getVisitRecordTemplate } from './components/archive-detail/templates';
|
||||
import { normalizeVisitRecordFormData } from './utils/visit-record';
|
||||
@ -65,6 +67,10 @@ import { normalizeFileUrl } from '@/utils/file';
|
||||
|
||||
const scrollHeight = ref(0);
|
||||
|
||||
const accountStore = useAccountStore();
|
||||
const { account, doctorInfo } = storeToRefs(accountStore);
|
||||
const { getDoctorInfo } = accountStore;
|
||||
|
||||
const archiveId = ref('');
|
||||
const id = ref('');
|
||||
const medicalType = ref('');
|
||||
@ -76,6 +82,8 @@ let recordChangedHandler = null;
|
||||
|
||||
const userNameMap = ref({});
|
||||
const loadedMembersTeamId = ref('');
|
||||
const corpMemberNameInflight = new Map(); // userId -> Promise<string>
|
||||
const corpMemberNameTried = new Set(); // avoid retry storms on failures
|
||||
|
||||
const files = computed(() => {
|
||||
const arr = record.value?.files;
|
||||
@ -155,9 +163,48 @@ function formatPositiveFind(v, { withOpinion = false } = {}) {
|
||||
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') || {};
|
||||
return team?.corpId ? String(team.corpId) : '';
|
||||
return String(d.corpId || a.corpId || team.corpId || '') || '';
|
||||
}
|
||||
|
||||
function getCorpId() {
|
||||
return getCorpIdForQuery();
|
||||
}
|
||||
|
||||
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) {
|
||||
const id = normalizeUserId(userId);
|
||||
if (!id) return '';
|
||||
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) {
|
||||
@ -350,8 +493,8 @@ const sections = computed(() => {
|
||||
});
|
||||
|
||||
async function loadTemplate(t) {
|
||||
if (!t) return null;
|
||||
const corpId = getCorpId();
|
||||
if (!corpId || !t) return null;
|
||||
try {
|
||||
const res = await api('getCurrentTemplate', { corpId, templateType: t });
|
||||
if (!res?.success) return null;
|
||||
@ -388,12 +531,9 @@ const topText = computed(() => {
|
||||
});
|
||||
|
||||
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();
|
||||
if (!corpId) {
|
||||
if (!silent) toast('缺少 corpId');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!silent) loading('加载中...');
|
||||
try {
|
||||
@ -404,19 +544,22 @@ async function fetchRecord({ silent = false } = {}) {
|
||||
medicalType: medicalType.value,
|
||||
});
|
||||
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 || '');
|
||||
rawType.value = raw;
|
||||
const ui = normalizeMedicalType(raw);
|
||||
record.value = normalizeVisitRecordFormData(ui, r);
|
||||
temp.value = await loadTemplate(raw);
|
||||
uni.setNavigationBarTitle({ title: String(typeLabel.value || '病历详情') });
|
||||
return true;
|
||||
const msg = String(res?.message || res?.msg || '').trim();
|
||||
const isNotFound = (res?.success && !r) || /不存在|not\s*found|not\s*exist/i.test(msg);
|
||||
return { ok: false, reason: isNotFound ? 'not_found' : 'request_failed' };
|
||||
} catch (error) {
|
||||
console.error('获取病历记录失败:', error);
|
||||
if (!silent) toast('加载失败');
|
||||
return false;
|
||||
return { ok: false, reason: 'request_failed' };
|
||||
} finally {
|
||||
if (!silent) hideLoading();
|
||||
}
|
||||
@ -442,9 +585,9 @@ onLoad(async (opt) => {
|
||||
// 异步加载团队成员映射,用于展示“xx代建”的真实姓名
|
||||
void loadTeamMembers();
|
||||
|
||||
const ok = await fetchRecord();
|
||||
if (!ok) {
|
||||
toast('记录不存在');
|
||||
const result = await fetchRecord();
|
||||
if (!result?.ok) {
|
||||
toast(result?.reason === 'not_found' ? '记录不存在' : '请求失败');
|
||||
setTimeout(() => uni.navigateBack(), 300);
|
||||
}
|
||||
});
|
||||
|
||||
@ -485,28 +485,25 @@ async function fetchCorpMemberDisplayName(userId) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
// 2) 兜底:成员数据接口(部分环境可能支持 corpUserId)
|
||||
// 2) 兜底:成员列表接口(支持 memberList)
|
||||
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) {
|
||||
const name =
|
||||
extractDisplayNameFromAny(res?.data) ||
|
||||
extractDisplayNameFromAny(res?.data?.data) ||
|
||||
'';
|
||||
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) ||
|
||||
'';
|
||||
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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user