This commit is contained in:
huxuejian 2026-02-09 16:16:07 +08:00
commit 25a230ece7
41 changed files with 4316 additions and 2608 deletions

10
.env.production Normal file
View File

@ -0,0 +1,10 @@
MP_API_BASE_URL=https://ytk.youcan365.com
MP_IMAGE_URL=https://ytk.youcan365.com
MP_CACHE_PREFIX=production
MP_WX_APP_ID=wx1d8337a40c11d66c
MP_CORP_ID=wpLgjyawAA8N0gWmXgyJq8wpjGcOT7fg
MP_TIM_SDK_APP_ID=1600123876
MP_INVITE_TEAMMATE_QRCODE=https://ykt.youcan365.com/invite-teammate
MP_INVITE_PATIENT_QRCODE=https://ykt.youcan365.com/invite-patient
MP_PATIENT_PAGE_BASE_URL= 'https://www.youcan365.com/h5/#/'
MP_SURVEY_URL= 'https://www.youcan365.com/surveyDev/#/pages/survey/survey'

View File

@ -11,6 +11,11 @@
top: 0;
}
.form-cell-required {
margin-left: 4rpx;
color: #ff4d4f;
}
.form-content__wrapper {
width: 100%;
display: flex;

View File

@ -1,7 +1,7 @@
<template>
<view class="form-row" @click="handleClick">
<view class="form-row__label">
{{ name }}<text v-if="required" class="form-cell--required"></text>
{{ name }}<text v-if="required" class="form-cell-required">*</text>
</view>
<view class="form-row__content">
<slot></slot>

View File

@ -1,6 +1,8 @@
<template>
<view class="files-wrap">
<view class="files-label" :class="required ? 'form-cell--required' : ''">{{ name }}</view>
<view class="files-label">
{{ name }}<text v-if="required" class="form-cell-required">*</text>
</view>
<view class="grid">
<view v-for="(f, idx) in files" :key="idx" class="item" @click="preview(idx)">
<image class="thumb" :src="f.url" mode="aspectFill" />
@ -15,7 +17,7 @@
<script setup>
import { computed } from 'vue';
import { chooseAndUploadImage } from '@/utils/file';
import { chooseAndUploadImage, normalizeFileUrl } from '@/utils/file';
import { toast } from '@/utils/widget';
const emits = defineEmits(['change']);
@ -38,13 +40,13 @@ const files = computed(() => {
if (Array.isArray(v)) {
return v
.map((i) => {
if (typeof i === 'string') return { url: i };
if (i && typeof i === 'object' && i.url) return { url: String(i.url) };
if (typeof i === 'string') return { url: normalizeFileUrl(i) };
if (i && typeof i === 'object' && i.url) return { url: normalizeFileUrl(String(i.url)) };
return null;
})
.filter(Boolean);
}
if (typeof v === 'string' && v) return [{ url: v }];
if (typeof v === 'string' && v) return [{ url: normalizeFileUrl(v) }];
return [];
});
@ -141,4 +143,3 @@ async function add() {
line-height: 56rpx;
}
</style>

View File

@ -1,6 +1,8 @@
<template>
<view class="multi-wrap">
<view class="label" :class="required ? 'form-cell--required' : ''">{{ name }}</view>
<view class="label">
{{ name }}<text v-if="required" class="form-cell-required">*</text>
</view>
<view class="options" :class="hasOtherSelected ? 'with-other' : ''">
<view
v-for="opt in displayOptions"
@ -165,4 +167,3 @@ function onOtherInput(e) {
box-sizing: border-box;
}
</style>

View File

@ -1,6 +1,8 @@
<template>
<view class="form-row">
<view class="form-row__label" :class="required ? 'form-cell--required' : ''">{{ name }}</view>
<view class="form-row__label">
{{ name }}<text v-if="required" class="form-cell-required">*</text>
</view>
<view class="form-row__content runtime">
<input :disabled="disableChange" class="num" type="number" :value="year" @input="onInput($event, 'year')" />
<text class="unit"></text>
@ -86,4 +88,3 @@ function onInput(e, key) {
color: #333;
}
</style>

View File

@ -1,6 +1,8 @@
<template>
<view class="form-row">
<view class="form-row__label" :class="required ? 'form-cell--required' : ''">{{ name }}</view>
<view class="form-row__label">
{{ name }}<text v-if="required" class="form-cell-required">*</text>
</view>
<view class="form-row__content content">
<input
:disabled="disableChange"

View File

@ -1,7 +1,7 @@
<template>
<view class="textarea-row">
<view class="form-row__label">
{{ name }}<text v-if="required" class="form-cell--required"></text>
{{ name }}<text v-if="required" class="form-cell-required">*</text>
</view>
<view class="mt-10">
<textarea
@ -94,6 +94,8 @@ function change(e) {
</script>
<style lang="scss" scoped>
@import '../cell-style.css';
.textarea-row {
padding: 24rpx 30rpx;
border-bottom: 1px solid #eee;

View File

@ -7,7 +7,7 @@
@change="change"
/>
<form-diagnosis-picker
v-else-if="attrs.title === 'diagnosis' || attrs.title === 'diagnosisName'"
v-else-if="attrs.type === 'diagnosis' || attrs.__originType === 'diagnosis' || attrs.title === 'diagnosis' || attrs.title === 'diagnosisName'"
v-bind="attrs"
:form="form"
:disableChange="disableChange"

View File

@ -238,6 +238,12 @@
"navigationBarTitleText": "添加病历"
}
},
{
"path": "ai-medical-case-form",
"style": {
"navigationBarTitleText": "添加病历"
}
},
{
"path": "service-record-detail",
"style": {

View File

@ -0,0 +1,480 @@
<template>
<view class="medical-case-form">
<view class="form-container">
<!-- 动态渲染表单字段 -->
<view
v-for="field in currentFields"
:key="field.key"
class="form-item"
:class="{ required: field.required }"
>
<view class="item-label">{{ field.label }}</view>
<!-- 日期选择器 -->
<picker
v-if="field.type === 'date'"
mode="date"
:value="formData[field.key]"
@change="onDateChange(field.key, $event)"
:disabled="!isEditing"
>
<view class="picker-value">
{{ formData[field.key] || "暂无" }}
</view>
</picker>
<!-- 多行文本 -->
<textarea
v-else-if="field.type === 'textarea'"
class="item-textarea"
v-model="formData[field.key]"
placeholder="请输入"
:disabled="!isEditing"
/>
<!-- 单行文本 -->
<input
v-else
class="item-input"
v-model="formData[field.key]"
placeholder="暂无"
:disabled="!isEditing"
/>
</view>
</view>
<view class="footer-buttons">
<view class="btn-regenerate" @click="handleRegenerate">
<text class="btn-text">重新生成</text>
</view>
<view class="btn-save" @click="handleSave">
<text class="btn-text">保存至档案</text>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import useAccountStore from "@/store/account";
import api from "@/utils/api.js";
const caseType = ref("");
const formData = ref({});
const isEditing = ref(true);
const customerId = ref("");
const groupId = ref("");
const accountStore = useAccountStore();
const { doctorInfo } = storeToRefs(accountStore);
//
const CASE_TYPE_NAMES = {
outpatient: "门诊病历",
inhospital: "住院病历",
physicalExaminationTemplate: "体检记录",
preConsultation: "预问诊记录",
};
//
const FIELD_LABELS = {
//
visitTime: "就诊日期",
chiefComplaint: "主诉",
medicalHistorySummary: "病史概要",
examination: "检查",
diagnosisName: "门诊诊断",
//
inhosDate: "入院日期",
operation: "手术记录",
operationDate: "手术日期",
treatmentPlan: "治疗方案",
//
inspectTime: "体检日期",
inspectSummary: "体检小结",
positiveFind: "阳性发现及处理意见",
//
consultationDate: "问诊日期",
presentIllnessHistory: "现病史",
pastMedicalHistory: "既往史",
};
//
const FIELD_CONFIG = {
outpatient: [
{
key: "visitTime",
label: FIELD_LABELS.visitTime,
type: "date",
required: true,
},
{
key: "diagnosisName",
label: FIELD_LABELS.diagnosisName,
type: "textarea",
required: false,
},
{
key: "chiefComplaint",
label: FIELD_LABELS.chiefComplaint,
type: "textarea",
required: false,
},
{
key: "medicalHistorySummary",
label: FIELD_LABELS.medicalHistorySummary,
type: "textarea",
required: false,
},
{
key: "examination",
label: FIELD_LABELS.examination,
type: "textarea",
required: false,
},
{
key: "treatmentPlan",
label: "治疗方案",
type: "textarea",
required: false,
},
],
inhospital: [
{
key: "inhosDate",
label: FIELD_LABELS.inhosDate,
type: "date",
required: true,
},
{
key: "diagnosisName",
label: "住院主诊断",
type: "textarea",
required: true,
},
{
key: "operation",
label: FIELD_LABELS.operation,
type: "textarea",
required: false,
},
{
key: "operationDate",
label: FIELD_LABELS.operationDate,
type: "date",
required: false,
},
{
key: "treatmentPlan",
label: FIELD_LABELS.treatmentPlan,
type: "textarea",
required: false,
},
{
key: "chiefComplaint",
label: FIELD_LABELS.chiefComplaint,
type: "textarea",
required: false,
},
{
key: "medicalHistorySummary",
label: FIELD_LABELS.medicalHistorySummary,
type: "textarea",
required: false,
},
{
key: "examination",
label: FIELD_LABELS.examination,
type: "textarea",
required: false,
},
{
key: "treatmentPlan",
label: "治疗方案",
type: "textarea",
required: false,
},
],
physicalExaminationTemplate: [
{
key: "inspectTime",
label: FIELD_LABELS.inspectTime,
type: "date",
required: true,
},
{
key: "inspectSummary",
label: FIELD_LABELS.inspectSummary,
type: "textarea",
required: false,
},
{
key: "positiveFind",
label: FIELD_LABELS.positiveFind,
type: "textarea",
required: false,
},
],
preConsultation: [
{
key: "consultationDate",
label: FIELD_LABELS.consultationDate,
type: "date",
required: true,
},
{
key: "chiefComplaint",
label: FIELD_LABELS.chiefComplaint,
type: "textarea",
required: true,
},
{
key: "presentIllnessHistory",
label: FIELD_LABELS.presentIllnessHistory,
type: "textarea",
required: true,
},
{
key: "pastMedicalHistory",
label: FIELD_LABELS.pastMedicalHistory,
type: "textarea",
required: true,
},
],
};
//
const currentFields = computed(() => {
return FIELD_CONFIG[caseType.value] || [];
});
onMounted(() => {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
caseType.value = options.caseType || "";
customerId.value = options.patientId || "";
groupId.value = options.groupId || "";
// options
if (options.formData) {
try {
formData.value = JSON.parse(decodeURIComponent(options.formData));
} catch (e) {
console.error("解析表单数据失败:", e);
}
}
//
const title = CASE_TYPE_NAMES[caseType.value]
? `添加${CASE_TYPE_NAMES[caseType.value]}`
: "添加病历";
uni.setNavigationBarTitle({ title });
});
const onDateChange = (field, event) => {
formData.value[field] = event.detail.value;
};
const handleRegenerate = () => {
uni.showModal({
title: "提示",
content: "确定要重新生成吗?当前编辑的内容将被覆盖",
success: (res) => {
if (res.confirm) {
//
uni.navigateBack({
success: () => {
uni.$emit("regenerateMedicalCase", {
caseType: caseType.value,
customerId: customerId.value,
groupId: groupId.value,
});
},
});
}
},
});
};
const handleSave = async () => {
//
const requiredFields = getRequiredFields();
const missingFields = requiredFields.filter(
(field) => !formData.value[field.key]
);
if (missingFields.length > 0) {
uni.showToast({
title: `请填写${missingFields[0].label}`,
icon: "none",
});
return;
}
try {
uni.showLoading({ title: "保存中..." });
const result = await api("addMedicalRecord", {
medicalType: caseType.value,
memberId: customerId.value,
creator: doctorInfo.value.userid,
...formData.value,
});
uni.hideLoading();
if (result.success) {
uni.showToast({
title: "保存成功",
icon: "success",
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
} else {
uni.showToast({
title: result.message || "保存失败",
icon: "none",
});
}
} catch (error) {
uni.hideLoading();
console.error("保存病历失败:", error);
uni.showToast({
title: "保存失败,请重试",
icon: "none",
});
}
};
const getRequiredFields = () => {
return currentFields.value.filter((field) => field.required);
};
</script>
<style scoped lang="scss">
.medical-case-form {
min-height: 100vh;
background-color: #f5f5f5;
padding-bottom: 120rpx;
.form-container {
background-color: #ffffff;
padding: 32rpx;
.form-item {
margin-bottom: 32rpx;
&.required .item-label::before {
content: "*";
color: #ff4d4f;
margin-right: 8rpx;
}
.item-label {
font-size: 28rpx;
color: #333333;
margin-bottom: 16rpx;
}
.item-input,
.picker-value {
width: 100%;
height: 80rpx;
padding: 0 24rpx;
background-color: #f8f9fa;
border-radius: 8rpx;
font-size: 28rpx;
color: #333333;
&[disabled] {
color: #999999;
}
}
.picker-value {
display: flex;
align-items: center;
color: #999999;
}
.item-textarea {
width: 100%;
min-height: 100rpx;
padding: 20rpx 24rpx;
background-color: #f8f9fa;
border-radius: 8rpx;
font-size: 28rpx;
color: #333333;
height: 100px;
&[disabled] {
color: #999999;
}
}
}
.tips-box {
margin-top: 32rpx;
padding: 24rpx;
background-color: #fffbe6;
border-radius: 8rpx;
.tips-text {
display: block;
font-size: 24rpx;
color: #666666;
line-height: 1.6;
margin-bottom: 8rpx;
&:last-child {
margin-bottom: 0;
}
}
}
}
.footer-buttons {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
gap: 24rpx;
padding: 24rpx 32rpx;
background-color: #ffffff;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
.btn-regenerate,
.btn-save {
flex: 1;
height: 88rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 44rpx;
.btn-text {
font-size: 32rpx;
font-weight: 500;
}
}
.btn-regenerate {
background-color: #ffffff;
border: 2rpx solid #1890ff;
.btn-text {
color: #1890ff;
}
}
.btn-save {
background-color: #1890ff;
.btn-text {
color: #ffffff;
}
}
}
}
</style>

View File

@ -2,18 +2,12 @@
<view class="page">
<view class="card">
<view class="header">
<view class="avatar">
<image v-if="archive.avatar" class="avatar-img" :src="archive.avatar" mode="aspectFill" />
</view>
<view class="header-main">
<view class="name-row">
<text class="name">{{ archive.name || '-' }}</text>
<text v-if="sexOrAge" class="meta">{{ sexOrAge }}</text>
</view>
<view v-if="archive.mobile" class="sub-line">{{ archive.mobile }}</view>
<view v-if="idRows.length" class="id-rows">
<view v-for="row in idRows" :key="row.label" class="id-row">
<text class="id-label">{{ row.label }}</text>
@ -125,10 +119,10 @@
/>
</view>
<view v-if="showBindWechat" class="footer">
<button class="bind-btn" @click="bindWechat">
<uni-icons type="email" size="18" color="#fff" />
<text class="bind-text">关联患者微信</text>
<view v-if="showGoChat" class="footer">
<button class="bind-btn" @click="goChat">
<uni-icons type="chat-filled" size="18" color="#fff" />
<text class="bind-text">去聊天</text>
</button>
</view>
@ -268,6 +262,7 @@ const archive = ref({
creator: '',
createdByDoctor: true,
hasBindWechat: false,
chatGroupId: '',
notes: '',
groupIds: []
});
@ -289,6 +284,17 @@ function getCorpId() {
return String(d.corpId || a.corpId || team.corpId || '') || '';
}
function getCurrentTeamId() {
const team = uni.getStorageSync(CURRENT_TEAM_STORAGE_KEY) || {};
return String(team?.teamId || team?._id || team?.id || '') || '';
}
function normalizeGroupId(v) {
const s = String(v || '').trim();
if (!s) return '';
return s.startsWith('GROUP') ? s.slice(5) : s;
}
function normalizeArchiveFromApi(raw) {
const r = raw && typeof raw === 'object' ? raw : {};
const next = {
@ -296,7 +302,7 @@ function normalizeArchiveFromApi(raw) {
name: r.name || '',
sex: r.sex || r.gender || '',
age: r.age ?? '',
avatar: r.avatar || '',
avatar: r.avatar || r.avatarUrl || r.headImgUrl || r.headimgurl || r.headImageUrl || r.profilePhoto || r.photoUrl || r.photo || '',
mobile: r.mobile || r.phone1 || r.phone || '',
outpatientNo: r.outpatientNo || '',
inpatientNo: r.inpatientNo || '',
@ -308,6 +314,7 @@ function normalizeArchiveFromApi(raw) {
creator: r.creator || '',
notes: r.notes || r.remark || '',
groupIds: Array.isArray(r.groupIds) ? r.groupIds : [],
chatGroupId: normalizeGroupId(r.chatGroupId || r.groupId || r.groupID || r.imGroupId || r.imGroupID || r.consultGroupId || ''),
};
return next;
}
@ -336,6 +343,23 @@ async function fetchArchive() {
saveToStorage();
loadTeamMembers();
await fetchTeamGroups(true);
chatGroupId.value = normalizeGroupId(archive.value.chatGroupId || '');
if (!chatGroupId.value) {
refreshChatRoom();
} else {
const meta = await getChatRoomMeta(chatGroupId.value);
const ok = isChatRoomForArchive(meta, archiveId.value);
const currentTeamId = getCurrentTeamId();
const metaTeamId = String(meta?.teamId || meta?.team?.teamId || meta?.team?._id || '');
if (!ok || (currentTeamId && metaTeamId && metaTeamId !== currentTeamId)) {
chatGroupId.value = '';
archive.value.chatGroupId = '';
refreshChatRoom();
} else {
archive.value.chatGroupId = chatGroupId.value;
}
}
saveToStorage();
// tabs
nextTick(() => setTimeout(measureTabsTop, 30));
} catch (e) {
@ -479,16 +503,20 @@ onLoad((options) => {
fromChat.value = options?.fromChat === 'true' || options?.fromChat === true;
const cached = uni.getStorageSync(STORAGE_KEY);
if (cached && typeof cached === 'object') {
const cachedObj = cached && typeof cached === 'object' ? cached : null;
const cachedId = cachedObj ? String(cachedObj._id || cachedObj.id || '') : '';
const canUseCached = Boolean(cachedObj && (!cachedId || !archiveId.value || cachedId === archiveId.value));
if (canUseCached) {
archive.value = {
...archive.value,
...cached,
groupIds: Array.isArray(cached.groupIds) ? cached.groupIds : archive.value.groupIds
};
chatGroupId.value = normalizeGroupId(archive.value.chatGroupId || '');
}
if (!archive.value.mobile) {
const mobiles = cached && Array.isArray(cached.mobiles) ? cached.mobiles : [];
const mobiles = canUseCached && cachedObj && Array.isArray(cachedObj.mobiles) ? cachedObj.mobiles : [];
if (mobiles.length) archive.value.mobile = String(mobiles[0]);
}
@ -518,12 +546,14 @@ onReady(() => {
onShow(() => {
const cached = uni.getStorageSync(STORAGE_KEY);
if (cached && typeof cached === 'object') {
const cachedId = cached && typeof cached === 'object' ? String(cached._id || cached.id || '') : '';
if (cached && typeof cached === 'object' && (!cachedId || !archiveId.value || cachedId === archiveId.value)) {
archive.value = {
...archive.value,
...cached,
groupIds: Array.isArray(cached.groupIds) ? cached.groupIds : archive.value.groupIds,
};
chatGroupId.value = normalizeGroupId(archive.value.chatGroupId || '');
}
setTimeout(measureTabsTop, 30);
fetchArchive();
@ -562,12 +592,16 @@ const createText = computed(() => {
const creatorId = ['-', '—', '--'].includes(rawCreator.trim()) ? '' : rawCreator.trim();
const creatorName = creatorId ? resolveUserName(creatorId) : '';
if (time && creatorName) return `${time} ${creatorName}创建`;
if (time && !rawCreator.trim()) return `${time} 患者创建`;
if (time) return `${time} 创建`;
if (!rawCreator.trim()) return '患者创建';
return '';
});
const showBindWechat = computed(() => Boolean(archive.value.createdByDoctor && !archive.value.hasBindWechat));
const floatingBottom = computed(() => (showBindWechat.value ? 90 : 16));
const chatGroupId = ref('');
const currentChatGroupId = computed(() => normalizeGroupId(chatGroupId.value || ''));
const showGoChat = computed(() => Boolean(currentChatGroupId.value));
const floatingBottom = computed(() => (showGoChat.value ? 90 : 16));
// const contactTitle = computed(() => (archive.value.mobile ? '' : ''));
// const notesTitle = computed(() => (archive.value.notes ? '' : ''));
@ -581,10 +615,140 @@ const goEdit = () => {
uni.navigateTo({ url: `/pages/case/archive-edit?archiveId=${encodeURIComponent(archiveId.value || '')}` });
};
const bindWechat = () => {
uni.showToast({ title: '关联患者微信功能待接入', icon: 'none' });
const goChat = async () => {
let gid = normalizeGroupId(currentChatGroupId.value || '');
if (!gid) {
await refreshChatRoom();
gid = normalizeGroupId(currentChatGroupId.value || '');
}
if (!gid) {
toast('暂无可进入的会话');
return;
}
const meta = await getChatRoomMeta(gid);
const ok = isChatRoomForArchive(meta, archiveId.value);
const currentTeamId = getCurrentTeamId();
const metaTeamId = String(meta?.teamId || meta?.team?.teamId || meta?.team?._id || '');
if (!ok || (currentTeamId && metaTeamId && metaTeamId !== currentTeamId)) {
chatGroupId.value = '';
archive.value.chatGroupId = '';
saveToStorage();
await refreshChatRoom();
gid = normalizeGroupId(currentChatGroupId.value || '');
}
if (!gid) {
toast('暂无可进入的会话');
return;
}
const conversationID = `GROUP${gid}`;
uni.navigateTo({
url: `/pages/message/index?conversationID=${encodeURIComponent(conversationID)}&groupID=${encodeURIComponent(gid)}&fromCase=true`,
});
};
const isRefreshingChatRoom = ref(false);
let lastRefreshChatRoomAt = 0;
function isChatRoomForArchive(meta, customerId) {
const cid = String(meta?.customerId || '');
const pid = String(meta?.patientId || '');
const id = String(customerId || '');
if (!meta || !id) return false;
return (cid && cid === id) || (pid && pid === id);
}
async function getChatRoomMeta(groupId) {
const gid = normalizeGroupId(groupId || '');
if (!gid) return null;
try {
const res = await api('getGroupListByGroupId', { groupId: gid }, false);
if (!res?.success || !res?.data) return null;
return res.data;
} catch (e) {
return null;
}
}
function parseAnyTimeMs(v) {
if (v === null || v === undefined) return 0;
if (typeof v === 'number') return v;
const s = String(v).trim();
if (!s) return 0;
if (/^\d{10,13}$/.test(s)) return Number(s.length === 10 ? `${s}000` : s);
const d = dayjs(s);
return d.isValid() ? d.valueOf() : 0;
}
async function refreshChatRoom() {
const customerId = String(archiveId.value || '');
if (!customerId) return;
if (isRefreshingChatRoom.value) return;
const now = Date.now();
if (now - lastRefreshChatRoomAt < 5000) return;
lastRefreshChatRoomAt = now;
isRefreshingChatRoom.value = true;
try {
const corpId = getCorpId();
const teamId = getCurrentTeamId();
const baseQuery = {
corpId,
customerId,
page: 1,
pageSize: 50,
};
const queryWithTeam = teamId ? { ...baseQuery, teamId } : baseQuery;
let detailRes = await api('getGroupList', queryWithTeam, false);
let details = Array.isArray(detailRes?.data?.list) ? detailRes.data.list : [];
if (!details.length && teamId) {
detailRes = await api('getGroupList', baseQuery, false);
details = Array.isArray(detailRes?.data?.list) ? detailRes.data.list : [];
}
if (!detailRes?.success || !details.length) {
chatGroupId.value = '';
archive.value.chatGroupId = '';
return;
}
const currentTeamId = getCurrentTeamId();
const detailsForCurrentTeam = currentTeamId
? details.filter((g) => String(g?.teamId || g?.team?._id || g?.team?.teamId || '') === currentTeamId)
: [];
const candidates = detailsForCurrentTeam.length ? detailsForCurrentTeam : details;
const statusRank = (s) => (s === 'processing' ? 3 : s === 'pending' ? 2 : 1);
candidates.sort((a, b) => {
const ra = statusRank(String(a?.orderStatus || ''));
const rb = statusRank(String(b?.orderStatus || ''));
if (rb !== ra) return rb - ra;
const ta = parseAnyTimeMs(a?.updatedAt) || parseAnyTimeMs(a?.createdAt);
const tb = parseAnyTimeMs(b?.updatedAt) || parseAnyTimeMs(b?.createdAt);
return tb - ta;
});
const best = candidates[0] || {};
const gid = normalizeGroupId(best.groupId || best.groupID || best.group_id || '');
if (gid) {
chatGroupId.value = String(gid);
archive.value.chatGroupId = chatGroupId.value;
saveToStorage();
} else {
chatGroupId.value = '';
archive.value.chatGroupId = '';
}
} catch (e) {
// ignore
} finally {
isRefreshingChatRoom.value = false;
}
}
const makeCall = () => {
if (archive.value.mobile) {
uni.makePhoneCall({ phoneNumber: archive.value.mobile });
@ -778,25 +942,10 @@ const saveAddGroup = async () => {
border-bottom: 2rpx solid #f2f2f2;
}
.avatar {
width: 112rpx;
height: 112rpx;
border-radius: 12rpx;
border: 2rpx solid #e8e8e8;
background: #fafafa;
overflow: hidden;
flex-shrink: 0;
}
.avatar-img {
width: 112rpx;
height: 112rpx;
}
.header-main {
flex: 1;
min-width: 0;
padding: 0 20rpx;
padding: 0 20rpx 0 0;
}
.name-row {

View File

@ -1,37 +1,18 @@
<template>
<view class="transfer-container">
<view class="content">
<view class="section-title">选择新负责团队</view>
<view class="selector-item" @click="selectTeam">
<text :class="team ? '' : 'placeholder'">{{ team ? team.name : '请选择团队' }}</text>
<uni-icons type="arrowdown" size="16" color="#999" />
</view>
<template v-if="team">
<view class="section-title">选择责任人</view>
<view class="selector-item" @click="selectUser">
<text :class="userId ? '' : 'placeholder'">{{ userLabel || '请选择责任人' }}</text>
<uni-icons type="arrowdown" size="16" color="#999" />
</view>
</template>
<view class="tips">客户将与本团队解除服务关系本团队成员将没有权限查询到客户档案</view>
</view>
<view class="footer">
<button class="btn plain" @click="cancel">取消</button>
<button class="btn primary" @click="save">保存</button>
<view class="tips">处理中...</view>
</view>
</view>
</template>
<script setup>
import { computed, ref } from 'vue';
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { storeToRefs } from 'pinia';
import api from '@/utils/api';
import useAccountStore from '@/store/account';
import { hideLoading, loading, toast } from '@/utils/widget';
import { confirm as uniConfirm, hideLoading, loading as showLoading, toast } from '@/utils/widget';
const CURRENT_TEAM_STORAGE_KEY = 'ykt_case_current_team';
const NEED_RELOAD_STORAGE_KEY = 'ykt_case_need_reload';
@ -44,15 +25,6 @@ const { getDoctorInfo } = accountStore;
const customerIds = ref([]);
const currentTeam = ref(null);
const teams = ref([]);
const team = ref(null);
const teamMembers = ref([]);
const userId = ref('');
const userLabel = computed(() => {
const list = Array.isArray(teamMembers.value) ? teamMembers.value : [];
const found = list.find((m) => String(m?.userid || '') === String(userId.value));
return found ? String(found.anotherName || found.name || found.userid || '') : '';
});
function getUserId() {
const d = doctorInfo.value || {};
@ -71,6 +43,21 @@ function getCurrentTeamId() {
return String(currentTeam.value?.teamId || '') || '';
}
function showActionSheet(itemList = [], title = '') {
return new Promise((resolve, reject) => {
if (!Array.isArray(itemList) || itemList.length === 0) {
reject(new Error('empty'));
return;
}
uni.showActionSheet({
title,
itemList,
success: ({ tapIndex }) => resolve(tapIndex),
fail: () => reject(new Error('cancel')),
});
});
}
function normalizeTeam(raw) {
if (!raw || typeof raw !== 'object') return null;
const teamId = raw.teamId || raw.id || raw._id || '';
@ -94,114 +81,174 @@ async function loadTeams() {
await ensureDoctor();
const corpId = getCorpId();
const userId = getUserId();
if (!corpId || !userId) return;
if (!corpId || !userId) return [];
const res = await api('getTeamBymember', { corpId, corpUserId: userId });
if (!res?.success) {
toast(res?.message || '获取团队失败');
return;
return [];
}
const list = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : [];
teams.value = list.map(normalizeTeam).filter(Boolean);
return teams.value;
}
async function loadTeamMembers(teamId) {
async function fetchTeamMembers(teamId) {
const corpId = getCorpId();
if (!teamId) return;
if (!teamId) return [];
const res = await api('getTeamData', { corpId, teamId });
if (!res?.success) {
toast(res?.message || '获取团队成员失败');
teamMembers.value = [];
return;
return [];
}
const t = res?.data && typeof res.data === 'object' ? res.data : {};
teamMembers.value = Array.isArray(t.memberList) ? t.memberList : [];
return Array.isArray(t.memberList) ? t.memberList : [];
}
const selectTeam = async () => {
if (!teams.value.length) await loadTeams();
const currentId = getCurrentTeamId();
const candidates = teams.value.filter((t) => t.teamId !== currentId);
if (!candidates.length) {
toast('暂无可选团队');
return;
async function transferToCustomerPool() {
try {
await uniConfirm('客户将与本团队解除服务关系,本团队成员将没有权限查询到客户档案。');
} catch (e) {
return false;
}
uni.showActionSheet({
itemList: candidates.map((t) => t.name),
success: async (res) => {
team.value = candidates[res.tapIndex] || null;
userId.value = '';
teamMembers.value = [];
if (team.value) await loadTeamMembers(team.value.teamId);
},
});
};
const selectUser = () => {
const list = Array.isArray(teamMembers.value) ? teamMembers.value : [];
if (!list.length) {
toast('当前团队暂无可选成员');
return;
}
const labels = list.map((m) => String(m?.anotherName || m?.name || m?.userid || ''));
uni.showActionSheet({
itemList: labels,
success: (res) => {
const picked = list[res.tapIndex];
userId.value = picked?.userid ? String(picked.userid) : '';
},
});
};
const cancel = () => {
uni.navigateBack();
};
const save = async () => {
if (!team.value) return toast('请选择团队');
if (!userId.value) return toast('请选择负责人');
const corpId = getCorpId();
const currentTeamId = getCurrentTeamId();
const creatorUserId = getUserId();
if (!corpId || !currentTeamId || !creatorUserId) return toast('缺少用户/团队信息');
if (!corpId || !currentTeamId || !creatorUserId) {
toast('缺少用户/团队信息');
return false;
}
loading('保存中...');
showLoading('保存中...');
try {
const res = await api('transferCustomers', {
corpId,
customerIds: customerIds.value,
currentTeamId,
targetTeamId: team.value.teamId,
targetUserId: userId.value,
operationType: 'transferToCustomerPool',
creatorUserId,
});
if (!res?.success) {
toast(res?.message || '操作失败');
return false;
}
toast('操作成功');
return true;
} catch (e) {
toast('操作失败');
return false;
} finally {
hideLoading();
}
}
async function transferToOtherTeam() {
const corpId = getCorpId();
const currentTeamId = getCurrentTeamId();
const creatorUserId = getUserId();
if (!corpId || !currentTeamId || !creatorUserId) {
toast('缺少用户/团队信息');
return false;
}
if (!teams.value.length) await loadTeams();
const candidates = teams.value.filter((t) => String(t?.teamId || '') !== String(currentTeamId));
if (!candidates.length) {
toast('暂无可选团队');
return false;
}
let teamIndex;
try {
teamIndex = await showActionSheet(candidates.map((t) => t.name || ''), '选择新负责团队');
} catch (e) {
return false;
}
const pickedTeam = candidates[teamIndex];
if (!pickedTeam?.teamId) {
toast('团队信息异常');
return false;
}
const members = await fetchTeamMembers(pickedTeam.teamId);
if (!members.length) {
toast('当前团队暂无可选成员');
return false;
}
let userIndex;
try {
userIndex = await showActionSheet(
members.map((m) => String(m?.anotherName || m?.name || m?.userid || '')),
'选择责任人'
);
} catch (e) {
return false;
}
const targetUserId = String(members[userIndex]?.userid || '') || '';
if (!targetUserId) {
toast('责任人信息异常');
return false;
}
showLoading('保存中...');
try {
const res = await api('transferCustomers', {
corpId,
customerIds: customerIds.value,
currentTeamId,
targetTeamId: String(pickedTeam.teamId),
targetUserId,
operationType: 'transferToOtherTeam',
creatorUserId,
});
if (!res?.success) {
toast(res?.message || '操作失败');
return;
return false;
}
toast('操作成功');
uni.removeStorageSync(BATCH_CUSTOMER_IDS_KEY);
uni.setStorageSync(NEED_RELOAD_STORAGE_KEY, 1);
uni.navigateBack();
return true;
} catch (e) {
toast('操作失败');
return false;
} finally {
hideLoading();
}
};
}
onLoad(async () => {
async function runFlow(options = {}) {
let mode = options?.mode === 'pool' ? 'pool' : options?.mode === 'team' ? 'team' : '';
if (!mode) {
let pick;
try {
pick = await showActionSheet(['转移给其他团队', '转移至客户公共池']);
} catch (e) {
return false;
}
mode = pick === 0 ? 'team' : 'pool';
}
return mode === 'team' ? await transferToOtherTeam() : await transferToCustomerPool();
}
onLoad(async (options = {}) => {
customerIds.value = Array.isArray(uni.getStorageSync(BATCH_CUSTOMER_IDS_KEY))
? uni.getStorageSync(BATCH_CUSTOMER_IDS_KEY).map(String).filter(Boolean)
: [];
currentTeam.value = uni.getStorageSync(CURRENT_TEAM_STORAGE_KEY) || null;
if (!customerIds.value.length) {
toast('未选择客户');
setTimeout(() => uni.navigateBack(), 200);
return;
}
await loadTeams();
const ok = await runFlow(options);
if (ok) {
uni.removeStorageSync(BATCH_CUSTOMER_IDS_KEY);
uni.setStorageSync(NEED_RELOAD_STORAGE_KEY, 1);
}
setTimeout(() => uni.navigateBack(), 50);
});
</script>

View File

@ -40,13 +40,6 @@
<image class="pen" src="/static/icons/icon-pen.svg" />
</view>
<view class="rows">
<view class="row" @click="openTransferRecord">
<view class="label">院内来源</view>
<view class="val link">
{{ latestTransferRecord?.executeTeamName || '点击查看' }}
<uni-icons type="arrowright" size="14" color="#0877F1" />
</view>
</view>
<form-template
v-if="editing && effectiveInternalItems.length"
ref="internalFormRef"
@ -148,7 +141,15 @@ const fallbackInternalItems = [
];
const effectiveBaseItems = computed(() => (Array.isArray(props.baseItems) && props.baseItems.length ? props.baseItems : fallbackBaseItems));
const effectiveInternalItems = computed(() => (Array.isArray(props.internalItems) && props.internalItems.length ? props.internalItems : fallbackInternalItems));
function isInHospitalSourceItem(item) {
const title = String(item?.title || '');
const name = String(item?.name || '');
return title === 'inHospitalSource' || title === 'hospitalSource' || name.includes('院内来源');
}
const effectiveInternalItems = computed(() => {
const raw = Array.isArray(props.internalItems) && props.internalItems.length ? props.internalItems : fallbackInternalItems;
return raw.filter((i) => i && !isInHospitalSourceItem(i));
});
const filterRule = {
reference(formModel) {

View File

@ -90,11 +90,13 @@
</view>
</view>
<button
v-if="fromChat"
v-if="fromChat && isExecutor(i)"
class="action-btn send-btn"
:class="{ loading: sendingFollowUp }"
:disabled="sendingFollowUp"
@click.stop="sendFollowUp(i)"
>
发送
{{ sendingFollowUp ? "发送中..." : "发送" }}
</button>
</view>
<view v-if="i.status === 'treated'" class="result"
@ -238,6 +240,12 @@ function getUserId() {
return doctorInfo.value?.userid || "";
}
function isExecutor(todo) {
const currentUserId = getUserId();
const executorUserId = String(todo?.executorUserId || "");
return currentUserId && executorUserId && currentUserId === executorUserId;
}
function getCorpId() {
const team = uni.getStorageSync("ykt_case_current_team") || {};
return team.corpId || doctorInfo.value?.corpId || "";
@ -276,6 +284,7 @@ const pages = ref(1);
const loading = ref(false);
const userNameMap = ref({});
const sendingFollowUp = ref(false);
const moreStatus = computed(() => {
if (loading.value) return "loading";
@ -347,7 +356,6 @@ function eventTypeLabel(eventType) {
}
function resolveUserName(userId) {
const id = String(userId || "");
if (!id) return "";
const map = userNameMap.value || {};
return String(map[id] || "") || id;
@ -512,11 +520,18 @@ function toDetail(todo) {
}
async function sendFollowUp(todo) {
if (sendingFollowUp.value) {
toast("正在发送中,请稍候...");
return;
}
if (!todo.sendContent && (!todo.fileList || todo.fileList.length === 0)) {
toast("没有发送内容");
return;
}
sendingFollowUp.value = true;
try {
const messages = [];
// 1.
@ -552,15 +567,20 @@ async function sendFollowUp(todo) {
articleId: articleId,
},
});
} else if (file.file.type === "questionnaire" && file.file?.surveryId) {
//
} else if (
file.file.type === "questionnaire" &&
(file.file?.url || file.URL)
) {
// - URL surveryId
const surveryUrl = file.file?.url || file.URL;
const surveryId = extractSurveryIdFromUrl(surveryUrl);
messages.push({
type: "questionnaire",
content: {
_id: file.file?._id || file._id,
_id: surveryId,
name: file.file?.name || file.name || "问卷",
surveryId: file.file?.surveryId || file.surveryId,
url: file.file?.url || file.URL,
surveryId: surveryId,
url: surveryUrl,
},
});
}
@ -580,6 +600,9 @@ async function sendFollowUp(todo) {
toast("消息已发送");
uni.navigateBack();
}
} finally {
sendingFollowUp.value = false;
}
}
/**
@ -606,6 +629,24 @@ function extractIdFromUrl(url) {
}
}
/**
* 从问卷 URL 中提取 surveryId 参数
* @param {string} url - 完整的 URL格式如: https://www.youcan365.com/patientDeploy/#/pages/survery/fill?corpId=wwe3fb2faa52cf9dfb&surveryId=9ji5kg2oa9x52oyg9w4rj5k81769510562099
* @returns {string} 提取出的 surveryId
*/
function extractSurveryIdFromUrl(url) {
if (!url) return "";
try {
// 使 surveryId
// : ?surveryId=xxx &surveryId=xxx
const match = url.match(/[?&]surveryId=([^&]+)/);
return match ? decodeURIComponent(match[1]) : "";
} catch (error) {
console.error("解析问卷 URL 失败:", error);
return "";
}
}
// ---- filter popup ----
const filterPopupRef = ref(null);
const state = ref(null);
@ -976,6 +1017,14 @@ watch(
color: #fff;
}
.send-btn.loading {
opacity: 0.6;
}
.send-btn:disabled {
opacity: 0.6;
}
.empty {
padding: 120px 0;
text-align: center;

View File

@ -49,18 +49,30 @@
<view v-if="records.length === 0" class="empty">暂无数据</view>
</view>
<view class="fab" :style="{ bottom: `${floatingBottom}px` }" @click="add">
<picker
class="fab-picker"
mode="selector"
:range="selectableTemplates"
range-key="name"
:disabled="fabPickerDisabled"
:style="{ bottom: `${floatingBottom}px` }"
@change="pickAddType"
>
<view class="fab" :class="{ 'fab--disabled': selectableTemplates.length === 0 }" @tap="onFabTap">
<uni-icons type="plusempty" size="24" color="#fff" />
</view>
</picker>
</view>
</template>
<script setup>
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import dayjs from 'dayjs';
import { VISIT_RECORD_TEMPLATES } from './templates';
import api from '@/utils/api';
import { loading, hideLoading } from '@/utils/widget';
import { loading, hideLoading, toast } from '@/utils/widget';
import { normalizeTemplate } from '../../utils/template';
import { normalizeVisitRecordFormData } from '../../utils/visit-record';
import { normalizeFileUrl } from '@/utils/file';
const props = defineProps({
data: { type: Object, default: () => ({}) },
@ -68,7 +80,16 @@ const props = defineProps({
floatingBottom: { type: Number, default: 16 },
});
const templates = ref(VISIT_RECORD_TEMPLATES.map(t => ({ name: t.templateName, templateType: t.templateType })));
const FALLBACK_TEMPLATE_TYPES = ['outpatient', 'inhospital', 'preConsultation', 'physicalExaminationTemplate'];
const templates = ref([]);
const selectableTemplates = computed(() => templates.value.filter((i) => i && i.templateType && typeof i.name === 'string' && i.name.trim()));
const useActionSheet = computed(() => selectableTemplates.value.length > 0 && selectableTemplates.value.length <= 6);
const fabPickerDisabled = computed(() => selectableTemplates.value.length === 0 || useActionSheet.value);
const templateMap = computed(() => templates.value.reduce((m, t) => {
if (t?.templateType) m[String(t.templateType)] = t;
return m;
}, {}));
const availableTypes = computed(() => (templates.value.length ? templates.value.map((i) => i.templateType) : FALLBACK_TEMPLATE_TYPES));
const typeRange = computed(() => [{ name: '全部', value: 'ALL' }, ...templates.value.map((t) => ({ name: t.name, value: t.templateType }))]);
const currentType = ref({ name: '全部', value: 'ALL' });
@ -108,6 +129,72 @@ function getCorpId() {
return team?.corpId ? String(team.corpId) : '';
}
const loadedCorpId = ref('');
let loadVisitTemplatesPromise = null;
let loadVisitTemplatesCorpId = '';
async function loadVisitTemplates() {
const corpId = getCorpId();
if (!corpId) return;
if (loadedCorpId.value === corpId && templates.value.length) return;
if (loadVisitTemplatesPromise && loadVisitTemplatesCorpId === corpId) return loadVisitTemplatesPromise;
loadVisitTemplatesCorpId = corpId;
loadVisitTemplatesPromise = (async () => {
const groupRes = await api('getTemplateGroup', { corpId, parentType: 'medicalRecord' });
const group = groupRes?.data && Array.isArray(groupRes.data?.data) ? groupRes.data.data : Array.isArray(groupRes?.data) ? groupRes.data : [];
const list = Array.isArray(group) ? group : [];
const groupNameMap = list.reduce((m, i) => {
const t = i?.templateType ? String(i.templateType) : '';
const name = i?.name ? String(i.name) : '';
if (t && name) m[t] = name;
return m;
}, {});
const enabled = list.filter((i) => i && i.templateType !== 'healthTemplate' && i.templateStatus !== 'disable');
const typeList = enabled.map((i) => String(i.templateType || '')).filter(Boolean);
if (!typeList.length) return;
const detailRes = await api('getTemplateListByTemptype', { corpId, templateTypeList: typeList });
const detail = detailRes?.data && Array.isArray(detailRes.data?.data) ? detailRes.data.data : Array.isArray(detailRes?.data) ? detailRes.data : [];
const temps = Array.isArray(detail) ? detail : [];
const byType = temps.reduce((m, t) => {
const k = t?.templateType ? String(t.templateType) : '';
if (k) m[k] = t;
return m;
}, {});
const ordered = typeList.map((t) => byType[String(t)]).filter(Boolean);
const next = ordered
.map((t) => {
const temp = normalizeTemplate(t);
const rawType = String(temp?.templateType || '');
const name = String(groupNameMap[rawType] || temp?.name || temp?.templateName || temp?.templateTypeName || '') || rawType;
return {
templateType: rawType,
name,
service: temp?.service || {},
templateList: Array.isArray(temp?.templateList) ? temp.templateList : [],
};
})
.filter((i) => i && i.templateType);
if (next.length) {
templates.value = next;
loadedCorpId.value = corpId;
}
})()
.catch((e) => {
console.error('loadVisitTemplates error:', e);
})
.finally(() => {
if (loadVisitTemplatesCorpId === corpId) {
loadVisitTemplatesPromise = null;
loadVisitTemplatesCorpId = '';
}
});
return loadVisitTemplatesPromise;
}
const userNameMap = ref({});
const loadedTeamId = ref('');
function resolveUserName(userId) {
@ -138,10 +225,14 @@ async function loadTeamMembers() {
}
function getSortTimeTitle(templateType) {
if (templateType === 'outpatient') return 'visitTime';
if (templateType === 'inhospital') return 'inhosDate';
if (templateType === 'preConsultation') return 'consultDate';
if (templateType === 'physicalExaminationTemplate') return 'inspectDate';
const rawType = String(templateType || '');
const t = templateMap.value[rawType] || {};
if (t?.service?.timeTitle) return String(t.service.timeTitle);
const ui = normalizeMedicalType(rawType);
if (ui === 'outpatient') return 'visitTime';
if (ui === 'inhospital') return 'inhosDate';
if (ui === 'preConsultation') return 'consultDate';
if (ui === 'physicalExaminationTemplate') return 'inspectDate';
return '';
}
@ -172,20 +263,53 @@ function formatPositiveFind(v, { withOpinion = false } = {}) {
}
function getTemplateName(type) {
const t = VISIT_RECORD_TEMPLATES.find((i) => i && i.templateType === type);
return t?.templateName ? String(t.templateName) : '';
const t = templateMap.value[String(type || '')];
return t?.name ? String(t.name) : '';
}
function toDateStr(sortTime) {
if (!sortTime) return '';
const d = dayjs(sortTime);
return d.isValid() ? d.format('YYYY-MM-DD') : '';
return formatAnyDate(sortTime, 'YYYY-MM-DD');
}
function normalizeMedicalType(raw) {
const s = String(raw || '').trim();
if (!s) return '';
const lower = s.toLowerCase();
if (lower.includes('preconsult') || (lower.includes('pre') && lower.includes('consult'))) return 'preConsultation';
if (lower === 'outpatient' || lower === 'out_patient' || lower === 'out-patient') return 'outpatient';
if (lower === 'inhospital' || lower === 'in_hospital' || lower === 'in-hospital' || lower === 'inpatient') return 'inhospital';
if (lower === 'preconsultation' || lower === 'pre_consultation' || lower === 'pre-consultation') return 'preConsultation';
if (lower === 'physicalexaminationtemplate' || lower === 'physicalexamination' || lower === 'physical_examination') return 'physicalExaminationTemplate';
if (s === 'outPatient') return 'outpatient';
if (s === 'inHospital') return 'inhospital';
if (s === 'preConsultation') return 'preConsultation';
if (s === 'physicalExaminationTemplate') return 'physicalExaminationTemplate';
return s;
}
function parseAnyTimeMs(v) {
if (v === null || v === undefined) return 0;
if (typeof v === 'number') {
// 10
if (v > 1e9 && v < 1e12) return v * 1000;
return v;
}
const s = String(v).trim();
if (!s) return 0;
if (/^\d{10,13}$/.test(s)) return Number(s.length === 10 ? `${s}000` : s);
const d = dayjs(s);
return d.isValid() ? d.valueOf() : 0;
}
function formatAnyDate(v, fmt = 'YYYY-MM-DD') {
const ms = parseAnyTimeMs(v);
if (!ms) return '';
const d = dayjs(ms);
return d.isValid() ? d.format(fmt) : '';
}
function toDateTimeStr(ts) {
if (!ts) return '';
const d = dayjs(ts);
return d.isValid() ? d.format('YYYY-MM-DD HH:mm') : '';
return formatAnyDate(ts, 'YYYY-MM-DD HH:mm');
}
async function refreshList() {
@ -193,6 +317,7 @@ async function refreshList() {
const corpId = getCorpId();
if (!corpId) return;
await loadVisitTemplates();
loadTeamMembers();
loading('加载中...');
@ -201,7 +326,7 @@ async function refreshList() {
//
params.medicalType =
currentType.value.value === 'ALL' ? templates.value.map((i) => i.templateType) : currentType.value.value;
currentType.value.value === 'ALL' ? availableTypes.value : currentType.value.value;
//
if (Array.isArray(dateRange.value) && dateRange.value.length === 2 && dateRange.value[0] && dateRange.value[1]) {
@ -219,21 +344,31 @@ async function refreshList() {
? res.list
: Array.isArray(res?.data?.list)
? res.data.list
: Array.isArray(res?.data?.data)
? res.data.data
: Array.isArray(res?.data?.data?.list)
? res.data.data.list
: Array.isArray(res?.data)
? res.data
: [];
if (list.length) {
const mapped = list.map((r) => {
const t = String(r?.medicalType || r?.templateType || '') || '';
const timeTitle = getSortTimeTitle(t);
const dateStr = timeTitle ? normalizeText(r?.[timeTitle]) : '';
const rawType = String(r?.medicalType || r?.templateType || '') || '';
const uiType = normalizeMedicalType(rawType);
const normalized = normalizeVisitRecordFormData(uiType, r);
const timeTitle = getSortTimeTitle(rawType);
const rawTime = timeTitle ? (normalized?.[timeTitle] ?? r?.[timeTitle]) : '';
const dateStr = rawTime ? formatAnyDate(rawTime, 'YYYY-MM-DD') : '';
return {
...r,
templateType: t,
...normalized,
medicalType: rawType,
templateType: uiType,
rawTemplateType: rawType,
dateStr: dateStr || toDateStr(r?.sortTime),
createDateStr: r?.createTime ? dayjs(r.createTime).format('YYYY-MM-DD') : '',
createDateStr: r?.createTime ? formatAnyDate(r.createTime, 'YYYY-MM-DD') : '',
createTimeStr: toDateTimeStr(r?.createTime),
tempName: r?.tempName || getTemplateName(t) || '病历',
tempName: r?.tempName || getTemplateName(rawType) || '病历',
};
});
@ -258,9 +393,21 @@ const tagClass = {
physicalExaminationTemplate: 'bg-green',
};
function resolveRecordType(r) {
if (!r) return '';
const direct = normalizeMedicalType(r.uiType || r.templateType || r.rawTemplateType || r.medicalType || '');
if (direct) return direct;
// fallback by known fields
if (r.inspectDate || r.positiveFind || r.inspectSummary) return 'physicalExaminationTemplate';
if (r.inhosDate || r.surgeryName || r.surgeryDate || r.operationDate) return 'inhospital';
if (r.visitTime || r.disposePlan || r.treatmentPlan) return 'outpatient';
if (r.consultDate || r.presentIllness || r.presentIllnessHistory || r.pastHistory) return 'preConsultation';
return '';
}
function getDiagnosis(r) {
if (!r) return '--';
const t = r.templateType || r.medicalType;
const t = resolveRecordType(r);
if (t === 'preConsultation') return normalizeText(r.chiefComplaint) || normalizeText(r.summary) || '--';
if (t === 'physicalExaminationTemplate') return formatPositiveFind(r.positiveFind) || normalizeText(r.summary) || '--';
if (t === 'outpatient' || t === 'inhospital') return normalizeText(r.diagnosisName || r.diagnosis) || normalizeText(r.summary) || '--';
@ -273,7 +420,7 @@ function firstLine(v) {
}
function getDisplayLines(r) {
const t = r?.templateType || r?.medicalType;
const t = resolveRecordType(r);
if (t === 'outpatient') {
return [{ label: '门诊诊断:', value: firstLine(r.diagnosisName || r.diagnosis) }];
}
@ -284,12 +431,12 @@ function getDisplayLines(r) {
return lines;
}
if (t === 'physicalExaminationTemplate') {
return [{ label: '体检小结:', value: firstLine(r.summary) }];
return [{ label: '体检小结:', value: firstLine(r.summary || r.inspectSummary) }];
}
if (t === 'preConsultation') {
const lines = [
{ label: '主诉:', value: firstLine(r.chiefComplaint) },
{ label: '现病史:', value: firstLine(r.presentIllness) },
{ label: '现病史:', value: firstLine(r.presentIllness || r.presentIllnessHistory) },
];
const past = normalizeText(r.pastHistory);
if (past) lines.push({ label: '既往史:', value: past });
@ -320,7 +467,11 @@ function pickTimeRange(val) {
function getFiles(r) {
const arr = r?.files;
return Array.isArray(arr) ? arr.filter((i) => i && i.url) : [];
return Array.isArray(arr)
? arr
.filter((i) => i && i.url)
.map((i) => ({ ...i, url: normalizeFileUrl(i.url) }))
: [];
}
function previewFiles(r, idx) {
@ -329,18 +480,58 @@ function previewFiles(r, idx) {
uni.previewImage({ urls, current: urls[idx] });
}
function add() {
uni.showActionSheet({
itemList: templates.value.map((i) => i.name),
success: ({ tapIndex }) => {
const t = templates.value[tapIndex];
function goAdd(t) {
if (!t?.templateType) return;
uni.navigateTo({
url: `/pages/case/visit-record-detail?archiveId=${encodeURIComponent(props.archiveId)}&type=${encodeURIComponent(t.templateType)}&name=${encodeURIComponent(props.data?.name || '')}`,
});
}
function pickAddType(e) {
if (!props.archiveId) return toast('缺少档案信息');
const idx = Number(e?.detail?.value ?? -1);
const t = selectableTemplates.value[idx];
if (!t) return;
goAdd(t);
}
function showAddActionSheet() {
if (!props.archiveId) return toast('缺少档案信息');
const list = selectableTemplates.value;
if (!list.length) return toast('暂无可用病历模板');
uni.showActionSheet({
itemList: list.map((i) => i.name),
success: ({ tapIndex }) => {
const t = list[tapIndex];
if (!t) return;
goAdd(t);
},
fail: (e) => {
//
const errMsg = String(e?.errMsg || '');
if (errMsg && errMsg.includes('cancel')) return;
if (errMsg) console.warn('[health-profile-tab] showActionSheet fail:', errMsg);
},
});
}
async function onFabTap() {
if (!props.archiveId) return toast('缺少档案信息');
//
if (!templates.value.length) {
loading('加载模板...');
try {
await loadVisitTemplates();
} finally {
hideLoading();
}
}
// <=6 actionSheet>6 picker
if (useActionSheet.value) showAddActionSheet();
}
function edit(record) {
const type = String(record?.medicalType || record?.templateType || '') || '';
uni.navigateTo({
@ -349,8 +540,6 @@ function edit(record) {
}
onMounted(() => {
// archiveId watch
refreshList();
uni.$on('archive-detail:visit-record-changed', refreshList);
});
@ -533,9 +722,14 @@ watch(
font-size: 26rpx;
}
.fab {
.fab-picker {
position: fixed;
right: 32rpx;
width: 104rpx;
height: 104rpx;
z-index: 20;
}
.fab {
width: 104rpx;
height: 104rpx;
border-radius: 52rpx;
@ -544,6 +738,8 @@ watch(
align-items: center;
justify-content: center;
box-shadow: 0 20rpx 36rpx rgba(79, 110, 247, 0.35);
z-index: 20;
}
.fab--disabled {
opacity: 0.5;
}
</style>

View File

@ -40,8 +40,8 @@
</view>
<view class="meta">
<view class="tag">{{ i.typeStr }}</view>
<view class="meta-text">{{ i.executorName }}</view>
<view class="meta-text truncate">{{ i.executeTeamName }}</view>
<view class="meta-text">{{ executorText(i) }}</view>
<view class="meta-text truncate">{{ executeTeamText(i) }}</view>
</view>
<view class="body">
<view class="content" :class="{ clamp: !expandMap[i._id] }">
@ -79,6 +79,31 @@
</view>
</view>
</uni-popup>
<!-- 编辑服务内容 -->
<uni-popup ref="editPopupRef" type="bottom" :mask-click="true" @maskClick="closeEditPopup">
<view class="edit-sheet">
<view class="edit-header">
<view class="edit-header-left" />
<view class="edit-title">修改服务内容</view>
<view class="edit-close" @click="closeEditPopup">
<uni-icons type="closeempty" size="18" color="#333" />
</view>
</view>
<view class="edit-body">
<textarea
v-model="editContent"
class="edit-textarea"
placeholder="请输入服务内容"
:maxlength="1000"
/>
<view class="counter">{{ (editContent || '').length }}/1000</view>
</view>
<view class="edit-footer">
<button class="btn primary" @click="saveEdit">保存</button>
</view>
</view>
</uni-popup>
</view>
</template>
@ -130,7 +155,8 @@ async function ensureDoctor() {
function getUserId() {
const d = doctorInfo.value || {};
const a = account.value || {};
return String(d.userid || d.userId || d.corpUserId || a.userid || a.userId || '') || '';
const t = uni.getStorageSync('ykt_case_current_team') || {};
return String(d.userid || d.userId || d.corpUserId || a.userid || a.userId || t.userId || t.userid || t.corpUserId || '') || '';
}
function getCorpId() {
@ -145,6 +171,58 @@ function getCurrentTeamId() {
return String(t.teamId || '') || '';
}
function normalizeName(v) {
const s = v === 0 ? '0' : v ? String(v) : '';
const trimmed = s.trim();
if (!trimmed) return '';
if (['-', '—', '--'].includes(trimmed)) return '';
return trimmed;
}
function getExecutorId(r) {
const row = r && typeof r === 'object' ? r : {};
return String(
row.executorUserId ||
row.executorId ||
row.executor ||
row.creatorUserId ||
row.creator ||
row.updateUserId ||
''
) || '';
}
function executorText(r) {
const row = r && typeof r === 'object' ? r : {};
const fromRow = normalizeName(row.executorName || row.executorUserName || row.creatorName || row.updateUserName || '');
if (fromRow) return fromRow;
const uid = getExecutorId(row);
const mapped = normalizeName(resolveUserName(uid));
return mapped || (uid ? uid : '--');
}
function getExecuteTeamId(r) {
const row = r && typeof r === 'object' ? r : {};
return String(row.executeTeamId || row.teamId || row.teamID || '') || '';
}
function resolveTeamName(teamId) {
const tid = String(teamId || '') || '';
if (!tid) return '';
const list = teamList.value || [];
const hit = list.find((i) => i && i.value === tid);
return hit?.label ? String(hit.label) : '';
}
function executeTeamText(r) {
const row = r && typeof r === 'object' ? r : {};
const fromRow = normalizeName(row.executeTeamName || row.teamName || '');
if (fromRow) return fromRow;
const tid = getExecuteTeamId(row) || getCurrentTeamId();
const mapped = normalizeName(resolveTeamName(tid));
return mapped || (tid ? tid : '--');
}
function resolveUserName(userId) {
const id = String(userId || '');
if (!id) return '';
@ -181,9 +259,12 @@ function displayTaskContent(r) {
return formatTaskContent(String(r?.taskContent || ''));
}
const loadedTeamMemberIds = new Set();
async function loadTeamMembers(teamId) {
const tid = String(teamId || '') || '';
if (!tid) return;
if (loadedTeamMemberIds.has(tid)) return;
loadedTeamMemberIds.add(tid);
await ensureDoctor();
const corpId = getCorpId();
if (!corpId) return;
@ -216,6 +297,8 @@ function mapRow(i) {
return {
...i,
_id: String(i?._id || i?.id || ''),
executorUserId: getExecutorId(i),
executeTeamId: getExecuteTeamId(i),
hasFile,
fileType,
timeStr: i.executionTime ? dayjs(i.executionTime).format('YYYY-MM-DD HH:mm') : '--',
@ -288,6 +371,10 @@ async function getMore() {
const mapped = arr.map(mapRow).filter((i) => i && i._id);
list.value = page.value === 1 ? mapped : [...list.value, ...mapped];
page.value += 1;
//
const teamIds = mapped.map((i) => i.executeTeamId).filter(Boolean);
Array.from(new Set(teamIds)).forEach((tid) => loadTeamMembers(tid));
} finally {
loading.value = false;
}
@ -330,21 +417,10 @@ function add() {
}
function edit(record) {
const archive = props.data || {};
const customerUserId = String(archive.externalUserId || archive.customerUserId || '') || '';
uni.setStorageSync('service-record-detail', {
customerId: String(props.archiveId),
customerName: String(archive.name || ''),
customerUserId,
id: String(record?._id || ''),
executionTime: record?.executionTime || 0,
executeTeamId: String(record?.executeTeamId || ''),
executeTeamName: String(record?.executeTeamName || ''),
eventType: String(record?.eventType || ''),
taskContent: String(record?.taskContent || ''),
pannedEventSendFile: record?.pannedEventSendFile || null,
});
uni.navigateTo({ url: `/pages/case/service-record-detail?archiveId=${encodeURIComponent(props.archiveId)}&mode=edit&id=${encodeURIComponent(record._id)}` });
if (!record?._id) return;
editingRecord.value = record;
editContent.value = String(record?.taskContent || '') || '';
editPopupRef.value?.open?.();
}
const filePopupRef = ref(null);
@ -380,6 +456,45 @@ function copyFile() {
closeFilePopup();
}
const editPopupRef = ref(null);
const editingRecord = ref(null);
const editContent = ref('');
function closeEditPopup() {
editPopupRef.value?.close?.();
editingRecord.value = null;
}
async function saveEdit() {
const r = editingRecord.value;
if (!r?._id) return;
if (!String(editContent.value || '').trim()) return toast('请输入服务内容');
await ensureDoctor();
const corpId = getCorpId();
const userId = getUserId();
if (!corpId || !userId) return toast('缺少用户信息');
const res = await api('updateServiceRecord', {
corpId,
id: String(r._id),
params: {
taskContent: String(editContent.value || ''),
updateUserId: userId,
},
});
if (!res?.success) return toast(res?.message || '修改失败');
//
const idx = list.value.findIndex((i) => i && i._id === String(r._id));
if (idx > -1) list.value[idx] = { ...list.value[idx], taskContent: String(editContent.value || '') };
uni.$emit('archive-detail:service-record-changed');
uni.showToast({ title: '保存成功', icon: 'success' });
closeEditPopup();
}
async function loadTeams() {
await ensureDoctor();
const corpId = getCorpId();
@ -640,4 +755,56 @@ watch(
background: #0877F1;
color: #fff;
}
.edit-sheet {
background: #fff;
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
overflow: hidden;
padding-bottom: calc(24rpx + env(safe-area-inset-bottom));
}
.edit-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 28rpx;
border-bottom: 2rpx solid #f0f0f0;
}
.edit-header-left {
width: 36rpx;
height: 36rpx;
}
.edit-title {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.edit-close {
width: 36rpx;
height: 36rpx;
display: flex;
align-items: center;
justify-content: center;
}
.edit-body {
padding: 28rpx 28rpx 0;
}
.edit-textarea {
width: 100%;
height: 260rpx;
padding: 20rpx;
border: 2rpx solid #e5e7eb;
border-radius: 12rpx;
font-size: 28rpx;
box-sizing: border-box;
}
.counter {
margin-top: 12rpx;
text-align: right;
font-size: 24rpx;
color: #999;
}
.edit-footer {
padding: 24rpx 28rpx 0;
}
</style>

View File

@ -8,9 +8,9 @@ export const VISIT_RECORD_TEMPLATES = [
{ title: 'chiefComplaint', name: '主诉', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请输入或说话录音转录问题', rows: 1, autoHeight: true },
{ title: 'medicalHistory', name: '病史概要', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 500, placeholder: '请简述患者情况,量键既往病史、用药史等', rows: 3, autoHeight: true },
{ title: 'examination', name: '检查', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 500, placeholder: '请填写关键项目或异常结果描述', rows: 1, autoHeight: true },
{ title: 'diagnosis', name: '诊断', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请填写诊断名称', supportVoice: true, rows: 1, autoHeight: true },
{ title: 'diagnosis', name: '诊断', type: 'diagnosis', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请选择诊断', supportVoice: true, rows: 1, autoHeight: true },
{ title: 'treatmentPlan', name: '治疗方案', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 1000, placeholder: '请简述治疗方案及效果', rows: 3, autoHeight: true },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持≤5M文件pdf文件格式)', maxSize: 5, accept: 'pdf' },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持拍摄/相册选择图片,≤5M)', maxSize: 5, accept: 'image' },
],
},
{
@ -22,11 +22,11 @@ export const VISIT_RECORD_TEMPLATES = [
{ title: 'chiefComplaint', name: '主诉', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请输入病症与转诊问题', rows: 1, autoHeight: true },
{ title: 'medicalHistory', name: '病史概要', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 500, placeholder: '请简述患者情况,量键既往病史、用药史等症状', rows: 3, autoHeight: true },
{ title: 'examination', name: '检查', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 500, placeholder: '请填写关键项目或异常结果描述', rows: 1, autoHeight: true },
{ title: 'diagnosis', name: '住院主诊断', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请填写诊断名称', rows: 1, autoHeight: true },
{ title: 'diagnosis', name: '住院主诊断', type: 'diagnosis', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请选择诊断', rows: 1, autoHeight: true },
{ title: 'surgeryDate', name: '手术日期', type: 'date', operateType: 'formCell', required: false, format: 'YYYY-MM-DD', placeholder: '请选择手术日期' },
{ title: 'surgeryName', name: '手术名称', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 100, placeholder: '请填写手术名称', rows: 1, autoHeight: true },
{ title: 'treatmentPlan', name: '治疗方案', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 1000, placeholder: '请简述治疗方案及效果', rows: 3, autoHeight: true },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持≤5M文件pdf文件格式)', maxSize: 5, accept: 'pdf' },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持拍摄/相册选择图片,≤5M)', maxSize: 5, accept: 'image' },
],
},
{
@ -37,7 +37,7 @@ export const VISIT_RECORD_TEMPLATES = [
{ title: 'chiefComplaint', name: '主诉', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请输入症状及转诊问题', rows: 1, autoHeight: true },
{ title: 'presentIllness', name: '现病史', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 800, placeholder: '请述述发病的过程、发展、诊疗经过及当前病情', rows: 3, autoHeight: true },
{ title: 'pastHistory', name: '既往史', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 800, placeholder: '请填写既往疾病、手术/外伤史、药物/食物过敏史', rows: 3, autoHeight: true },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持≤5M文件pdf文件格式)', maxSize: 5, accept: 'pdf' },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持拍摄/相册选择图片,≤5M)', maxSize: 5, accept: 'image' },
],
},
{
@ -48,7 +48,7 @@ export const VISIT_RECORD_TEMPLATES = [
{ title: 'inspectDate', name: '体检日期', type: 'date', operateType: 'formCell', required: false, format: 'YYYY-MM-DD', placeholder: '请选择体检日期' },
{ title: 'summary', name: '体检小结', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200, placeholder: '请填写本次体检的小结', rows: 3, autoHeight: true },
{ title: 'positiveFind', name: '阳性发现及处理意见', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 500, placeholder: '可参照医客通现有模式', rows: 3, refNote: '可参照医客通现有模式', autoHeight: true },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持≤5M文件pdf文件格式)', maxSize: 5, accept: 'pdf' },
{ title: 'files', name: '文件上传', type: 'files', required: false, desc: '(支持拍摄/相册选择图片,≤5M)', maxSize: 5, accept: 'image' },
],
},
];

View File

@ -2,7 +2,7 @@
<view class="manage-container">
<view class="group-list">
<scroll-view scroll-y class="sort-scroll">
<movable-area class="drag-area" :style="{ height: dragAreaHeight + 'px' }">
<movable-area :key="areaKey" class="drag-area" :style="{ height: dragAreaHeight + 'px' }">
<movable-view
v-for="(item, index) in groups"
:key="item._id"
@ -81,7 +81,7 @@
</template>
<script setup>
import { ref, computed } from 'vue';
import { ref, computed, nextTick } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { storeToRefs } from 'pinia';
import api from '@/utils/api';
@ -91,6 +91,8 @@ import { hideLoading, loading, toast } from '@/utils/widget';
// State
const groups = ref([]);
const originalGroups = ref([]);
const areaKey = ref(0);
const loadSeq = ref(0);
const ITEM_HEIGHT = 74; // px
const draggingId = ref('');
@ -151,6 +153,7 @@ async function ensureDoctor() {
}
async function loadGroups() {
const seq = (loadSeq.value += 1);
await ensureDoctor();
const corpId = getCorpId();
const teamId = getTeamId();
@ -166,9 +169,17 @@ async function loadGroups() {
}
const list = Array.isArray(res.data) ? res.data : Array.isArray(res.data?.data) ? res.data.data : [];
const sorted = sortGroupList(list);
groups.value = sorted.map((i, idx) => ({ ...i, _y: idx * ITEM_HEIGHT }));
originalGroups.value = sorted.map((i, idx) => ({ ...i, _y: idx * ITEM_HEIGHT }));
if (seq !== loadSeq.value) return;
const next = sorted.map((i, idx) => ({ ...i, _y: idx * ITEM_HEIGHT }));
// movable-view key movable-area
groups.value = [];
await nextTick();
if (seq !== loadSeq.value) return;
groups.value = next;
originalGroups.value = next.map((i) => ({ ...i }));
lastSavedOrderKey.value = getOrderKey(groups.value);
areaKey.value += 1;
} catch (e) {
toast('获取分组失败');
} finally {

View File

@ -1,473 +1,277 @@
<template>
<view class="medical-case-form">
<view class="form-container">
<!-- 动态渲染表单字段 -->
<view
v-for="field in currentFields"
:key="field.key"
class="form-item"
:class="{ required: field.required }"
>
<view class="item-label">{{ field.label }}</view>
<!-- 日期选择器 -->
<picker
v-if="field.type === 'date'"
mode="date"
:value="formData[field.key]"
@change="onDateChange(field.key, $event)"
:disabled="!isEditing"
>
<view class="picker-value">
{{ formData[field.key] || "暂无" }}
</view>
</picker>
<!-- 多行文本 -->
<textarea
v-else-if="field.type === 'textarea'"
class="item-textarea"
v-model="formData[field.key]"
placeholder="请输入"
:disabled="!isEditing"
/>
<!-- 单行文本 -->
<input
v-else
class="item-input"
v-model="formData[field.key]"
placeholder="暂无"
:disabled="!isEditing"
/>
</view>
<view class="page">
<view class="body">
<scroll-view scroll-y class="scroll">
<view class="header">
<view class="header-title">{{ pageTitle }}</view>
</view>
<view class="footer-buttons">
<view class="btn-regenerate" @click="handleRegenerate">
<text class="btn-text">重新生成</text>
<view class="form-wrap">
<FormTemplate v-if="temp" ref="formRef" :items="showItems" :form="form" @change="onChange" />
</view>
<view class="btn-save" @click="handleSave">
<text class="btn-text">保存至档案</text>
<view style="height: 240rpx;"></view>
</scroll-view>
<view class="footer">
<button class="btn plain" @click="handleRegenerate">重新生成</button>
<button class="btn primary" @click="handleSave">保存至档案</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref, computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import useAccountStore from "@/store/account";
import api from "@/utils/api.js";
const caseType = ref("");
const formData = ref({});
const isEditing = ref(true);
const customerId = ref("");
const groupId = ref("");
import { computed, reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
import FormTemplate from '@/components/form-template/index.vue';
import api from '@/utils/api.js';
import useAccountStore from '@/store/account';
import { toast, confirm, loading as uniLoading, hideLoading } from '@/utils/widget';
import { normalizeVisitRecordFormData } from './utils/visit-record';
import { normalizeTemplate, unwrapTemplateResponse } from './utils/template';
const caseType = ref('');
const customerId = ref('');
const groupId = ref('');
const accountStore = useAccountStore();
const { doctorInfo } = storeToRefs(accountStore);
//
const CASE_TYPE_NAMES = {
outpatient: "门诊病历",
inhospital: "住院病历",
physicalExaminationTemplate: "体检记录",
preConsultation: "预问诊记录",
};
const { account, doctorInfo } = storeToRefs(accountStore);
const { getDoctorInfo } = accountStore;
//
const FIELD_LABELS = {
//
visitTime: "就诊日期",
chiefComplaint: "主诉",
medicalHistorySummary: "病史概要",
examination: "检查",
diagnosisName: "门诊诊断",
//
inhosDate: "入院日期",
operation: "手术记录",
operationDate: "手术日期",
treatmentPlan: "治疗方案",
//
inspectTime: "体检日期",
inspectSummary: "体检小结",
positiveFind: "阳性发现及处理意见",
//
presentIllnessHistory: "现病史",
pastMedicalHistory: "既往史",
};
//
const FIELD_CONFIG = {
outpatient: [
{
key: "visitTime",
label: FIELD_LABELS.visitTime,
type: "date",
required: false,
},
{
key: "diagnosisName",
label: FIELD_LABELS.diagnosisName,
type: "textarea",
required: false,
},
{
key: "chiefComplaint",
label: FIELD_LABELS.chiefComplaint,
type: "textarea",
required: false,
},
{
key: "medicalHistorySummary",
label: FIELD_LABELS.medicalHistorySummary,
type: "textarea",
required: false,
},
{
key: "examination",
label: FIELD_LABELS.examination,
type: "textarea",
required: false,
},
{
key: "treatmentPlan",
label: "治疗方案",
type: "textarea",
required: false,
},
],
inhospital: [
{
key: "inhosDate",
label: FIELD_LABELS.inhosDate,
type: "date",
required: false,
},
{
key: "diagnosisName",
label: "住院主诊断",
type: "textarea",
required: false,
},
{
key: "operation",
label: FIELD_LABELS.operation,
type: "textarea",
required: false,
},
{
key: "operationDate",
label: FIELD_LABELS.operationDate,
type: "date",
required: false,
},
{
key: "treatmentPlan",
label: FIELD_LABELS.treatmentPlan,
type: "textarea",
required: false,
},
{
key: "chiefComplaint",
label: FIELD_LABELS.chiefComplaint,
type: "textarea",
required: false,
},
{
key: "medicalHistorySummary",
label: FIELD_LABELS.medicalHistorySummary,
type: "textarea",
required: false,
},
{
key: "examination",
label: FIELD_LABELS.examination,
type: "textarea",
required: false,
},
{
key: "treatmentPlan",
label: "治疗方案",
type: "textarea",
required: false,
},
],
physicalExaminationTemplate: [
{
key: "inspectTime",
label: FIELD_LABELS.inspectTime,
type: "date",
required: false,
},
{
key: "inspectSummary",
label: FIELD_LABELS.inspectSummary,
type: "textarea",
required: false,
},
{
key: "positiveFind",
label: FIELD_LABELS.positiveFind,
type: "textarea",
required: false,
},
],
preConsultation: [
{
key: "chiefComplaint",
label: FIELD_LABELS.chiefComplaint,
type: "textarea",
required: false,
},
{
key: "presentIllnessHistory",
label: FIELD_LABELS.presentIllnessHistory,
type: "textarea",
required: false,
},
{
key: "pastMedicalHistory",
label: FIELD_LABELS.pastMedicalHistory,
type: "textarea",
required: false,
},
],
};
//
const currentFields = computed(() => {
return FIELD_CONFIG[caseType.value] || [];
});
onMounted(() => {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const options = currentPage.options;
caseType.value = options.caseType || "";
customerId.value = options.patientId || "";
groupId.value = options.groupId || "";
// options
if (options.formData) {
async function ensureDoctor() {
if (doctorInfo.value) return;
if (!account.value?.openid) return;
try {
formData.value = JSON.parse(decodeURIComponent(options.formData));
} catch (e) {
console.error("解析表单数据失败:", e);
}
await getDoctorInfo();
} catch {
// ignore
}
}
//
const title = CASE_TYPE_NAMES[caseType.value]
? `添加${CASE_TYPE_NAMES[caseType.value]}`
: "添加病历";
uni.setNavigationBarTitle({ title });
function getUserId() {
const d = doctorInfo.value || {};
const a = account.value || {};
return String(d.userid || d.userId || d.corpUserId || a.userid || a.userId || '') || '';
}
function getCorpId() {
const d = doctorInfo.value || {};
const a = account.value || {};
const t = uni.getStorageSync('ykt_case_current_team') || {};
return String(d.corpId || a.corpId || t.corpId || '') || '';
}
const temp = ref(null);
const titleText = computed(() => {
const t = temp.value || {};
return String(t.name || t.templateName || t.templateTypeName || '').trim();
});
const pageTitle = computed(() => {
const name = titleText.value;
return name ? `添加${name}` : '添加病历';
});
const onDateChange = (field, event) => {
formData.value[field] = event.detail.value;
};
const form = reactive({});
const forms = computed(() => form);
const showItems = computed(() => {
const list = temp.value?.templateList || [];
return list.filter((i) => {
if (i?.type === 'files') return false;
if (i && typeof i.referenceField === 'string') {
return forms.value[i.referenceField] === i.referenceValue;
}
return true;
});
});
const handleRegenerate = () => {
uni.showModal({
title: "提示",
content: "确定要重新生成吗?当前编辑的内容将被覆盖",
success: (res) => {
if (res.confirm) {
//
const formRef = ref(null);
function onChange({ title, value }) {
form[title] = value;
const item = showItems.value.find((i) => i.title === title);
if (!item) return;
const relat = (temp.value?.templateList || []).filter((i) => i.referenceField === title);
relat.forEach((i) => (form[i.title] = ''));
}
function setDefaultDates() {
const timeKey = temp.value?.service?.timeTitle || '';
if (timeKey && !form[timeKey]) form[timeKey] = dayjs().format('YYYY-MM-DD');
}
function applyInitialFormData(raw) {
const normalized = normalizeVisitRecordFormData(caseType.value, raw);
Object.assign(form, normalized);
setDefaultDates();
}
async function loadTemplate(t) {
const corpId = getCorpId();
if (!corpId) return null;
try {
const res = await api('getCurrentTemplate', { corpId, templateType: t });
if (!res?.success) {
toast(res?.message || '获取模板失败');
return null;
}
const raw = unwrapTemplateResponse(res);
return normalizeTemplate(raw);
} catch (e) {
console.error('loadTemplate error:', e);
toast('获取模板失败');
return null;
}
}
onLoad(async (options) => {
caseType.value = options?.caseType || options?.type || '';
customerId.value = options?.patientId || options?.memberId || '';
groupId.value = options?.groupId || '';
if (!caseType.value) caseType.value = 'outpatient';
temp.value = await loadTemplate(caseType.value);
if (temp.value?.templateType) caseType.value = String(temp.value.templateType);
if (options?.formData) {
try {
const parsed = JSON.parse(decodeURIComponent(options.formData));
applyInitialFormData(parsed);
} catch (e) {
console.error('解析表单数据失败:', e);
applyInitialFormData({});
}
} else {
applyInitialFormData({});
}
uni.setNavigationBarTitle({ title: pageTitle.value });
});
async function handleRegenerate() {
try {
await confirm('确定要重新生成吗?当前编辑的内容将被覆盖');
} catch {
return;
}
uni.navigateBack({
success: () => {
uni.$emit("regenerateMedicalCase", {
uni.$emit('regenerateMedicalCase', {
caseType: caseType.value,
customerId: customerId.value,
groupId: groupId.value,
});
},
});
}
},
});
};
}
const handleSave = async () => {
//
const requiredFields = getRequiredFields();
const missingFields = requiredFields.filter(
(field) => !formData.value[field.key]
);
async function handleSave() {
if (!customerId.value) return toast('缺少患者信息');
await ensureDoctor();
const corpId = getCorpId();
const userId = getUserId();
if (!corpId || !userId) return toast('缺少用户信息');
if (formRef.value?.verify && !formRef.value.verify()) return;
if (missingFields.length > 0) {
uni.showToast({
title: `请填写${missingFields[0].label}`,
icon: "none",
});
return;
}
try {
uni.showLoading({ title: "保存中..." });
const result = await api("addMedicalRecord", {
medicalType: caseType.value,
const params = {
...form,
corpId,
memberId: customerId.value,
creator: doctorInfo.value.userid,
...formData.value,
});
medicalType: caseType.value,
creator: userId,
};
uni.hideLoading();
// /diagnosisName
if ((caseType.value === 'outpatient' || caseType.value === 'inhospital') && form.diagnosis && !form.diagnosisName) {
params.diagnosisName = form.diagnosis;
}
if (result.success) {
uni.showToast({
title: "保存成功",
icon: "success",
});
setTimeout(() => {
uni.navigateBack();
}, 1500);
const sortTimeKey = temp.value?.service?.timeTitle || '';
if (sortTimeKey && form[sortTimeKey] && dayjs(form[sortTimeKey]).isValid()) {
params.sortTime = dayjs(form[sortTimeKey]).valueOf();
} else {
uni.showToast({
title: result.message || "保存失败",
icon: "none",
});
params.sortTime = Date.now();
}
uniLoading('保存中...');
try {
const res = await api('addMedicalRecord', params);
hideLoading();
if (res.success) {
uni.$emit('archive-detail:visit-record-changed');
toast(res.message || '保存成功');
setTimeout(() => uni.navigateBack(), 300);
} else {
toast(res.message || '保存失败');
}
} catch (error) {
uni.hideLoading();
console.error("保存病历失败:", error);
uni.showToast({
title: "保存失败,请重试",
icon: "none",
});
}
};
const getRequiredFields = () => {
return currentFields.value.filter((field) => field.required);
};
</script>
<style scoped lang="scss">
.medical-case-form {
min-height: 100vh;
background-color: #f5f5f5;
padding-bottom: 120rpx;
.form-container {
background-color: #ffffff;
padding: 32rpx;
.form-item {
margin-bottom: 32rpx;
&.required .item-label::before {
content: "*";
color: #ff4d4f;
margin-right: 8rpx;
}
.item-label {
font-size: 28rpx;
color: #333333;
margin-bottom: 16rpx;
}
.item-input,
.picker-value {
width: 100%;
height: 80rpx;
padding: 0 24rpx;
background-color: #f8f9fa;
border-radius: 8rpx;
font-size: 28rpx;
color: #333333;
&[disabled] {
color: #999999;
}
}
.picker-value {
display: flex;
align-items: center;
color: #999999;
}
.item-textarea {
width: 100%;
min-height: 100rpx;
padding: 20rpx 24rpx;
background-color: #f8f9fa;
border-radius: 8rpx;
font-size: 28rpx;
color: #333333;
height: 100px;
&[disabled] {
color: #999999;
}
}
}
.tips-box {
margin-top: 32rpx;
padding: 24rpx;
background-color: #fffbe6;
border-radius: 8rpx;
.tips-text {
display: block;
font-size: 24rpx;
color: #666666;
line-height: 1.6;
margin-bottom: 8rpx;
&:last-child {
margin-bottom: 0;
}
}
}
}
.footer-buttons {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
gap: 24rpx;
padding: 24rpx 32rpx;
background-color: #ffffff;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
.btn-regenerate,
.btn-save {
flex: 1;
height: 88rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 44rpx;
.btn-text {
font-size: 32rpx;
font-weight: 500;
}
}
.btn-regenerate {
background-color: #ffffff;
border: 2rpx solid #1890ff;
.btn-text {
color: #1890ff;
}
}
.btn-save {
background-color: #1890ff;
.btn-text {
color: #ffffff;
}
}
hideLoading();
console.error('保存病历失败:', error);
toast('保存失败,请重试');
}
}
</script>
<style scoped>
.page {
min-height: 100vh;
background: #f5f6f8;
padding-bottom: calc(152rpx + env(safe-area-inset-bottom));
}
.body {
height: 100vh;
display: flex;
flex-direction: column;
}
.scroll {
flex: 1;
}
.header {
background: #fff;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
}
.header-title {
padding: 28rpx 28rpx;
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.form-wrap {
background: #fff;
margin-top: 20rpx;
padding: 8rpx 0;
}
.footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: #fff;
padding: 24rpx 28rpx calc(24rpx + env(safe-area-inset-bottom));
display: flex;
gap: 24rpx;
box-shadow: 0 -8rpx 24rpx rgba(0, 0, 0, 0.06);
}
.btn {
flex: 1;
height: 88rpx;
line-height: 88rpx;
border-radius: 12rpx;
font-size: 30rpx;
}
.btn::after {
border: none;
}
.btn.plain {
background: #fff;
color: #0877F1;
border: 2rpx solid #0877F1;
}
.btn.primary {
background: #0877F1;
color: #fff;
}
</style>

View File

@ -267,6 +267,12 @@ function isTagItem(i) {
return title === 'tagIds' || title === 'tag' || type === 'tag' || name.includes('标签');
}
function isInHospitalSourceItem(i) {
const title = String(i?.title || '');
const name = String(i?.name || '');
return title === 'inHospitalSource' || title === 'hospitalSource' || name.includes('院内来源');
}
async function loadInternalTemplate() {
const corpId = String(account.value?.corpId || doctorInfo.value?.corpId || '') || '';
if (!corpId) return;
@ -304,6 +310,7 @@ async function loadInternalTemplate() {
items.value = list
.filter((i) => i && i.fieldStatus !== 'disable')
.filter((i) => i.operateType !== 'onlyRead')
.filter((i) => !isInHospitalSourceItem(i))
.map(normalizeTemplateItem);
const debugStage = items.value.find(isStageItem);
@ -392,6 +399,20 @@ function buildPayload(base, inner) {
return { payload, team };
}
function getCreatedCustomerId(res) {
const root = res && typeof res === 'object' ? res : {};
const d = root.data && typeof root.data === 'object' ? root.data : {};
return String(
d._id ||
d.id ||
d.customerId ||
d.memberId ||
root.customerId ||
root.memberId ||
''
) || '';
}
async function save() {
if (formRef.value?.verify && !formRef.value.verify()) return;
@ -420,10 +441,23 @@ async function save() {
}
toast('新增成功');
const createdId = getCreatedCustomerId(res);
uni.removeStorageSync(BASE_KEY);
uni.removeStorageSync(INNER_KEY);
uni.setStorageSync(NEED_RELOAD_STORAGE_KEY, 1);
uni.navigateBack({ delta: 2 });
uni.navigateBack({
delta: 2,
success: () => {
if (!createdId) return;
setTimeout(() => {
uni.navigateTo({ url: `/pages/case/archive-detail?id=${encodeURIComponent(createdId)}` });
}, 30);
},
fail: () => {
if (!createdId) return;
uni.redirectTo({ url: `/pages/case/archive-detail?id=${encodeURIComponent(createdId)}` });
},
});
} catch (e) {
hideLoading();
toast('新增失败');

View File

@ -1,7 +1,7 @@
<template>
<view class="page">
<!-- Mobile 来源: ykt-management-mobile/src/pages/customer/service-record-detail/service-record-detail.vue -->
<view class="body">
<view v-if="!recordId" class="body">
<scroll-view scroll-y class="scroll">
<view class="card">
<view class="section-title">执行日期</view>
@ -31,12 +31,11 @@
</picker>
<view class="section-title">所属团队</view>
<picker mode="selector" :range="teamOptions" range-key="label" @change="pickTeam" :disabled="Boolean(recordId)">
<view class="picker-box between">
<picker mode="selector" :range="teamOptions" range-key="label" :disabled="true">
<view class="picker-box">
<view class="picker-text" :class="{ muted: !currentTeam?.value }">
{{ currentTeam?.value ? currentTeam.label : '请选择所属团队' }}
</view>
<uni-icons type="arrowright" size="16" color="#999" />
</view>
</picker>
@ -55,14 +54,37 @@
</view>
</view>
<view v-if="recordId" class="delete-fab" @click="remove">
<uni-icons type="trash" size="22" color="#ff4d4f" />
<!-- 编辑仅支持修改服务内容底部弹层 -->
<uni-popup v-else ref="editPopupRef" type="bottom" :mask-click="true" @maskClick="closeEdit">
<view class="sheet">
<view class="sheet-header">
<view class="sheet-header-left" />
<view class="sheet-title">修改服务内容</view>
<view class="sheet-close" @click="closeEdit">
<uni-icons type="closeempty" size="18" color="#333" />
</view>
</view>
<view class="sheet-body">
<textarea
v-model="form.taskContent"
class="sheet-textarea"
placeholder="请输入服务内容"
:maxlength="1000"
/>
<view class="counter">{{ (form.taskContent || '').length }}/1000</view>
</view>
<view class="sheet-footer">
<button class="primary-btn" @click="saveEdit">保存</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script setup>
import { reactive, ref } from 'vue';
import { nextTick, reactive, ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
@ -107,7 +129,8 @@ async function ensureDoctor() {
function getUserId() {
const d = doctorInfo.value || {};
const a = account.value || {};
return String(d.userid || d.userId || d.corpUserId || a.userid || a.userId || '') || '';
const t = uni.getStorageSync('ykt_case_current_team') || {};
return String(d.userid || d.userId || d.corpUserId || a.userid || a.userId || t.userId || t.userid || t.corpUserId || '') || '';
}
function getCorpId() {
@ -124,25 +147,6 @@ function getCurrentTeam() {
return teamId ? { value: teamId, label: name || teamId } : null;
}
async function loadTeams() {
await ensureDoctor();
const corpId = getCorpId();
const userId = getUserId();
if (!corpId || !userId) return;
const res = await api('getTeamBymember', { corpId, corpUserId: userId });
if (!res?.success) return;
const list = Array.isArray(res?.data) ? res.data : Array.isArray(res?.data?.data) ? res.data.data : [];
teamOptions.value = list
.map((raw) => {
if (!raw || typeof raw !== 'object') return null;
const teamId = raw.teamId || raw.id || raw._id || '';
const name = raw.name || raw.teamName || raw.team || '';
if (!teamId) return null;
return { label: String(name || teamId), value: String(teamId) };
})
.filter(Boolean);
}
onLoad((options) => {
archiveId.value = options?.archiveId ? String(options.archiveId) : '';
recordId.value = options?.id ? String(options.id) : '';
@ -162,26 +166,22 @@ onLoad((options) => {
const seedType = String(seed?.eventType || '') || '';
currentType.value = typeOptions.find((i) => i.value === seedType) || null;
const seedTeamId = String(seed?.executeTeamId || '') || '';
const seedTeamName = String(seed?.executeTeamName || '') || '';
if (seedTeamId) currentTeam.value = { value: seedTeamId, label: seedTeamName || seedTeamId };
else currentTeam.value = getCurrentTeam();
loadTeams().then(() => {
if (seedTeamId) currentTeam.value = teamOptions.value.find((t) => t.value === seedTeamId) || currentTeam.value;
else {
//
const cur = getCurrentTeam();
if (cur) currentTeam.value = teamOptions.value.find((t) => t.value === cur.value) || cur;
currentTeam.value = cur;
teamOptions.value = cur ? [cur] : [];
if (recordId.value) {
uni.setNavigationBarTitle({ title: '修改服务内容' });
nextTick(() => editPopupRef.value?.open?.());
} else {
uni.setNavigationBarTitle({ title: '新建服务记录' });
}
});
});
function pickType(e) {
currentType.value = typeOptions[e.detail.value] || null;
}
function pickTeam(e) {
currentTeam.value = teamOptions.value[e.detail.value] || null;
}
function pickDate(e) {
date.value = e.detail.value || '';
}
@ -205,6 +205,45 @@ function save() {
submit(executionTime);
}
const editPopupRef = ref(null);
function closeEdit() {
editPopupRef.value?.close?.();
setTimeout(() => uni.navigateBack(), 200);
}
function saveEdit() {
if (!String(form.taskContent || '').trim()) return uni.showToast({ title: '请输入服务内容', icon: 'none' });
submitEdit();
}
async function submitEdit() {
await ensureDoctor();
const corpId = getCorpId();
const userId = getUserId();
if (!corpId || !userId) {
toast('缺少用户/团队信息');
return;
}
if (!recordId.value) return;
const res = await api('updateServiceRecord', {
corpId,
id: recordId.value,
params: {
taskContent: form.taskContent,
updateUserId: userId,
},
});
if (!res?.success) {
toast(res?.message || '修改失败');
return;
}
uni.$emit('archive-detail:service-record-changed');
uni.showToast({ title: '保存成功', icon: 'success' });
setTimeout(() => uni.navigateBack(), 300);
}
async function submit(executionTime) {
await ensureDoctor();
const corpId = getCorpId();
@ -252,27 +291,6 @@ async function submit(executionTime) {
uni.showToast({ title: '保存成功', icon: 'success' });
setTimeout(() => uni.navigateBack(), 300);
}
function remove() {
uni.showModal({
title: '提示',
content: '确定删除当前记录?',
success: async (res) => {
if (!res.confirm) return;
await ensureDoctor();
const corpId = getCorpId();
if (!corpId || !recordId.value) return;
const resp = await api('removeServiceRecord', { corpId, id: recordId.value });
if (!resp?.success) {
toast(resp?.message || '删除失败');
return;
}
uni.$emit('archive-detail:service-record-changed');
uni.showToast({ title: '已删除', icon: 'success' });
setTimeout(() => uni.navigateBack(), 300);
},
});
}
</script>
<style scoped>
@ -377,18 +395,60 @@ function remove() {
color: #fff;
}
.delete-fab {
position: fixed;
right: 16px;
bottom: calc(96px + env(safe-area-inset-bottom));
width: 52px;
height: 52px;
border-radius: 26px;
.sheet {
background: #fff;
border-top-left-radius: 14px;
border-top-right-radius: 14px;
padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.sheet-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px;
border-bottom: 1px solid #f0f0f0;
}
.sheet-header-left {
width: 24px;
height: 24px;
}
.sheet-title {
font-size: 16px;
font-weight: 600;
color: #333;
}
.sheet-close {
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 10px 18px rgba(0, 0, 0, 0.12);
z-index: 30;
}
.sheet-body {
padding: 14px 16px 0;
}
.sheet-textarea {
width: 100%;
height: 180px;
padding: 12px;
border: 1px solid #e6e6e6;
border-radius: 8px;
font-size: 14px;
box-sizing: border-box;
}
.sheet-footer {
padding: 12px 16px 0;
}
.primary-btn {
width: 100%;
height: 44px;
line-height: 44px;
border-radius: 6px;
background: #0877F1;
color: #fff;
font-size: 15px;
}
.primary-btn::after {
border: none;
}
</style>

View File

@ -0,0 +1,94 @@
function normalizeOptions(options) {
if (!Array.isArray(options)) return [];
if (!options.length) return [];
if (typeof options[0] === 'string') return options.filter((i) => typeof i === 'string');
if (typeof options[0] === 'object') {
return options
.map((i) => {
const label = i?.label ?? i?.name ?? i?.text ?? i?.title ?? '';
const value = i?.value ?? i?.id ?? i?.key ?? label;
if (!label && (value === undefined || value === null || value === '')) return null;
return { label: String(label || value), value: String(value) };
})
.filter(Boolean);
}
return [];
}
export function normalizeTemplateItem(item) {
const next = { ...(item || {}) };
if (next.operateType === 'custom') next.operateType = 'formCell';
const originalType = next.type;
const customTypeMap = {
customerSource: 'select',
customerStage: 'select',
tag: 'multiSelectAndOther',
reference: 'input',
selectWwuser: 'select',
files: 'files',
corpProject: 'select',
diagnosis: 'diagnosis',
BMI: 'input',
bloodPressure: 'textarea',
selfMultipleDiseases: 'textarea',
};
if (originalType && customTypeMap[originalType]) {
next.__originType = originalType;
next.type = customTypeMap[originalType];
}
const aliasTypeMap = {
text: 'input',
string: 'input',
number: 'input',
integer: 'input',
int: 'input',
};
if (next.type && aliasTypeMap[next.type]) {
next.type = aliasTypeMap[next.type];
if (!next.inputType && (originalType === 'number' || originalType === 'integer' || originalType === 'int')) next.inputType = 'number';
}
const rawRange = next.range || next.options || next.optionList || next.values || [];
const range = normalizeOptions(rawRange);
if (next.type === 'select' || next.type === 'selectAndOther' || next.type === 'selectAndImage') {
next.range = range;
} else if (next.type === 'radio') {
// wxapp 目前 radio 组件只支持字符串列表;模板如为对象选项则降级为 select
if (range.length && typeof range[0] === 'object') {
next.type = 'select';
next.range = range;
} else {
next.range = Array.isArray(rawRange) ? rawRange : [];
}
}
if (!next.operateType) next.operateType = 'formCell';
next.required = Boolean(next.required);
if (next.type === 'input' && (next.wordLimit === undefined || next.wordLimit === null || next.wordLimit === '')) next.wordLimit = 20;
if (next.type === 'textarea' && (next.wordLimit === undefined || next.wordLimit === null || next.wordLimit === '')) next.wordLimit = 200;
return next;
}
export function unwrapTemplateResponse(res) {
const d = res?.data;
if (d && typeof d === 'object') {
if (d.data && typeof d.data === 'object') return d.data;
return d;
}
return res && typeof res === 'object' ? res : {};
}
export function normalizeTemplate(temp) {
const t = temp && typeof temp === 'object' ? { ...temp } : {};
const list = Array.isArray(t.templateList) ? t.templateList : [];
t.templateList = list
.filter((i) => i && i.fieldStatus !== 'disable')
.filter((i) => i.operateType !== 'onlyRead')
.map(normalizeTemplateItem);
return t;
}

View File

@ -0,0 +1,40 @@
function isEmpty(v) {
if (v === null || v === undefined) return true;
if (Array.isArray(v)) return v.length === 0;
if (typeof v === 'string') return v.trim() === '';
return false;
}
const ALIAS_MAP = {
outpatient: {
diagnosisName: 'diagnosis',
medicalHistorySummary: 'medicalHistory',
},
inhospital: {
diagnosisName: 'diagnosis',
medicalHistorySummary: 'medicalHistory',
operationDate: 'surgeryDate',
operation: 'surgeryName',
},
physicalExaminationTemplate: {
inspectTime: 'inspectDate',
inspectSummary: 'summary',
},
preConsultation: {
presentIllnessHistory: 'presentIllness',
pastMedicalHistory: 'pastHistory',
},
};
export function normalizeVisitRecordFormData(templateType, raw) {
const input = raw && typeof raw === 'object' ? raw : {};
const out = { ...input };
const map = ALIAS_MAP[String(templateType || '')] || {};
Object.entries(map).forEach(([from, to]) => {
if (isEmpty(out[to]) && !isEmpty(out[from])) out[to] = out[from];
});
return out;
}

View File

@ -3,29 +3,8 @@
<!-- Mobile 来源: ykt-management-mobile/src/pages/customer/visit-record-detail/visit-record-detail.vue -->
<view class="body">
<scroll-view scroll-y class="scroll">
<view class="header">
<view class="header-title">{{ template?.templateName || '健康档案' }}</view>
</view>
<view class="form-wrap">
<FormTemplate v-if="template" ref="formRef" :items="showItems" :form="forms" @change="onChange" />
</view>
<!-- 附件上传FormTemplate 不支持 files单独实现 -->
<view v-if="hasFilesField" class="upload-wrap">
<view class="upload-row">
<view class="upload-label">文件上传</view>
<view class="upload-desc">支持5M文件pdf文件格式</view>
</view>
<view class="upload-grid">
<view v-for="(f, idx) in fileList" :key="idx" class="upload-item" @click="previewFile(idx)">
<image class="upload-thumb" :src="f.url" mode="aspectFill" />
<view class="upload-remove" @click.stop="removeFile(idx)">×</view>
</view>
<view class="upload-add" @click="addFiles">
<view class="plus">+</view>
</view>
</view>
<FormTemplate v-if="temp" ref="formRef" :items="showItems" :form="forms" @change="onChange" />
</view>
<view style="height: 240rpx;"></view>
@ -49,10 +28,11 @@ import { onLoad } from '@dcloudio/uni-app';
import dayjs from 'dayjs';
import { storeToRefs } from 'pinia';
import FormTemplate from '@/components/form-template/index.vue';
import { getVisitRecordTemplate } from './components/archive-detail/templates';
import api from '@/utils/api';
import useAccountStore from '@/store/account';
import { toast, confirm, loading as uniLoading, hideLoading } from '@/utils/widget';
import { normalizeVisitRecordFormData } from './utils/visit-record';
import { normalizeTemplate, unwrapTemplateResponse } from './utils/template';
const accountStore = useAccountStore();
const { account, doctorInfo } = storeToRefs(accountStore);
@ -84,17 +64,43 @@ function getCorpId() {
const memberId = ref('');
const recordId = ref('');
const templateType = ref('');
const customerName = ref('');
const template = computed(() => getVisitRecordTemplate(templateType.value));
const temp = ref(null);
const titleText = computed(() => {
const t = temp.value || {};
return String(t.name || t.templateName || t.templateTypeName || '').trim();
});
const detail = ref({});
const form = reactive({});
const forms = computed(() => ({ ...detail.value, ...form }));
const HIDDEN_FIELD_NAMES = {
outpatient: ['就诊机构', '就诊科室', '机构名称', '责任医生'],
inhospital: ['就诊机构', '机构名称'],
};
const HIDDEN_FIELD_TITLES = {
// systemFieldName/title
// - : corp
// - : deptName
// - : corpName
// - : doctor
outpatient: ['corp', 'deptName', 'corpName', 'doctor'],
// - : corp
// - : corpName
inhospital: ['corp', 'corpName'],
};
function shouldHideField(item) {
const t = String(templateType.value || '');
const name = item?.name ? String(item.name).trim() : '';
const title = item?.title ? String(item.title).trim() : '';
const hiddenNames = HIDDEN_FIELD_NAMES[t] || [];
const hiddenTitles = HIDDEN_FIELD_TITLES[t] || [];
return (name && hiddenNames.includes(name)) || (title && hiddenTitles.includes(title));
}
const showItems = computed(() => {
const list = template.value?.templateList || [];
const list = temp.value?.templateList || [];
// referenceField mobile
return list.filter((i) => {
if (i?.type === 'files') return false;
if (shouldHideField(i)) return false;
if (i && typeof i.referenceField === 'string') {
return forms.value[i.referenceField] === i.referenceValue;
}
@ -102,16 +108,7 @@ const showItems = computed(() => {
});
});
const hasFilesField = computed(() => {
const list = template.value?.templateList || [];
return list.some((i) => i && (i.type === 'files' || i.title === 'files'));
});
const formRef = ref(null);
const fileList = computed(() => {
const arr = forms.value?.files;
return Array.isArray(arr) ? arr.filter((i) => i && i.url) : [];
});
function ensureFilesField() {
if (form.files !== undefined) return;
@ -119,30 +116,43 @@ function ensureFilesField() {
form.files = [];
}
async function loadTemplate(t) {
const corpId = getCorpId();
if (!corpId) return null;
try {
const res = await api('getCurrentTemplate', { corpId, templateType: t });
if (!res?.success) {
toast(res?.message || '获取模板失败');
return null;
}
const raw = unwrapTemplateResponse(res);
return normalizeTemplate(raw);
} catch (e) {
console.error('loadTemplate error:', e);
toast('获取模板失败');
return null;
}
}
onLoad(async (options) => {
memberId.value = options?.memberId || options?.archiveId || '';
recordId.value = options?.id || '';
templateType.value = options?.type || '';
customerName.value = decodeURIComponent(options?.customerName || '');
if (recordId.value) {
await getDetail();
} else {
if (!templateType.value) templateType.value = 'outpatient';
temp.value = await loadTemplate(templateType.value);
if (temp.value?.templateType) templateType.value = String(temp.value.templateType);
ensureFilesField();
//
if (templateType.value === 'outpatient') {
form.visitTime = dayjs().format('YYYY-MM-DD');
}
//
if (templateType.value === 'inhospital') {
form.inhosDate = dayjs().format('YYYY-MM-DD');
}
//
if (templateType.value === 'physicalExaminationTemplate') {
form.inspectDate = dayjs().format('YYYY-MM-DD');
}
//
const timeKey = temp.value?.service?.timeTitle || '';
if (timeKey && !form[timeKey]) form[timeKey] = dayjs().format('YYYY-MM-DD');
}
if (titleText.value) uni.setNavigationBarTitle({ title: titleText.value });
});
async function getDetail() {
@ -162,14 +172,14 @@ async function getDetail() {
const record = res?.record || res?.data?.record || null;
if (res?.success && record) {
templateType.value = record.templateType || record.medicalType || templateType.value;
// wxapp 使 diagnosis diagnosisName
if ((record.medicalType === 'outpatient' || record.medicalType === 'inhospital') && !record.diagnosis && record.diagnosisName) {
record.diagnosis = record.diagnosisName;
}
detail.value = record;
detail.value = normalizeVisitRecordFormData(templateType.value, record);
ensureFilesField();
// templateType
if (!temp.value || temp.value?.templateType !== templateType.value) {
temp.value = await loadTemplate(templateType.value);
if (temp.value?.templateType) templateType.value = String(temp.value.templateType);
if (titleText.value) uni.setNavigationBarTitle({ title: titleText.value });
}
} else {
toast(res.message || '加载失败');
}
@ -185,7 +195,7 @@ function onChange({ title, value }) {
const item = showItems.value.find((i) => i.title === title);
if (!item) return;
// mobile
const relat = (template.value?.templateList || []).filter((i) => i.referenceField === title);
const relat = (temp.value?.templateList || []).filter((i) => i.referenceField === title);
relat.forEach((i) => (form[i.title] = ''));
}
@ -224,7 +234,7 @@ async function save() {
}
// sortTime使
const sortTimeKey = template.value?.service?.timeTitle || '';
const sortTimeKey = temp.value?.service?.timeTitle || '';
if (sortTimeKey && form[sortTimeKey] && dayjs(form[sortTimeKey]).isValid()) {
params.sortTime = dayjs(form[sortTimeKey]).valueOf();
} else {
@ -252,8 +262,12 @@ async function save() {
}
}
function remove() {
confirm('确定删除当前记录?', async () => {
async function remove() {
try {
await confirm('确定删除当前记录?');
} catch {
return;
}
if (!memberId.value || !recordId.value) return toast('缺少必要信息');
await ensureDoctor();
const corpId = getCorpId();
@ -279,49 +293,8 @@ function remove() {
console.error('remove error:', error);
toast('删除失败');
}
});
}
function addFiles() {
const fileConfig = template.value?.templateList?.find(i => i.type === 'files');
const maxSize = fileConfig?.maxSize || 5; // MB
const accept = fileConfig?.accept || 'pdf';
uni.chooseMessageFile({
count: 9,
type: 'file',
extension: [accept],
success: (res) => {
const files = Array.isArray(res.tempFiles) ? res.tempFiles : [];
const maxBytes = maxSize * 1024 * 1024;
//
const invalidFiles = files.filter(f => f.size > maxBytes);
if (invalidFiles.length > 0) {
toast(`文件大小不能超过${maxSize}M`);
return;
}
const next = files.map((f) => ({
url: f.path,
name: f.name || '',
size: f.size
}));
const cur = Array.isArray(forms.value.files) ? forms.value.files : [];
form.files = [...cur, ...next];
},
});
}
function removeFile(idx) {
const cur = Array.isArray(forms.value.files) ? forms.value.files : [];
form.files = cur.filter((_, i) => i !== idx);
}
function previewFile(idx) {
const urls = fileList.value.map((i) => i.url);
uni.previewImage({ urls, current: urls[idx] });
}
</script>
<style scoped>
@ -354,71 +327,6 @@ function previewFile(idx) {
padding: 8rpx 0;
}
.upload-wrap {
background: #fff;
padding: 24rpx 30rpx;
border-bottom: 2rpx solid #eee;
}
.upload-row {
display: flex;
align-items: baseline;
margin-bottom: 18rpx;
}
.upload-label {
font-size: 28rpx;
line-height: 42rpx;
color: #111827;
flex-shrink: 0;
}
.upload-desc {
font-size: 24rpx;
color: #9ca3af;
margin-left: 8rpx;
}
.upload-grid {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
}
.upload-item {
width: 180rpx;
height: 140rpx;
position: relative;
border: 2rpx solid #e5e7eb;
border-radius: 8rpx;
overflow: hidden;
background: #f9fafb;
}
.upload-thumb {
width: 100%;
height: 100%;
}
.upload-remove {
position: absolute;
right: 0;
top: 0;
width: 36rpx;
height: 36rpx;
line-height: 36rpx;
text-align: center;
background: rgba(0, 0, 0, 0.55);
color: #fff;
font-size: 28rpx;
}
.upload-add {
width: 180rpx;
height: 140rpx;
border: 2rpx dashed #d1d5db;
border-radius: 8rpx;
display: flex;
align-items: center;
justify-content: center;
color: #9ca3af;
}
.plus {
font-size: 52rpx;
line-height: 52rpx;
}
.footer {
position: fixed;
left: 0;

View File

@ -12,10 +12,10 @@
<view class="value">{{ typeLabel }}</view>
</view>
<view class="row">
<view class="label">就诊日期</view>
<view class="label">{{ visitDateLabel }}</view>
<view class="value">{{ visitDate || '--' }}</view>
</view>
<view class="row">
<view v-if="showDiagnosisRow" class="row">
<view class="label">诊断</view>
<view class="value">{{ diagnosisText }}</view>
</view>
@ -30,7 +30,7 @@
<view class="p">{{ s.value }}</view>
</view>
<view class="section">
<view v-if="showFilesSection" class="section">
<view class="h2">文件上传</view>
<view v-if="files.length" class="files">
<view v-for="(f, idx) in files" :key="idx" class="file" @click="preview(idx)">
@ -55,24 +55,70 @@ import dayjs from 'dayjs';
import api from '@/utils/api';
import { loading, hideLoading, toast } from '@/utils/widget';
import { getVisitRecordTemplate } from './components/archive-detail/templates';
import { normalizeVisitRecordFormData } from './utils/visit-record';
import { normalizeTemplate, unwrapTemplateResponse } from './utils/template';
import { normalizeFileUrl } from '@/utils/file';
const archiveId = ref('');
const id = ref('');
const medicalType = ref('');
const rawType = ref('');
const record = ref({});
const temp = ref(null);
const files = computed(() => {
const arr = record.value?.files;
return Array.isArray(arr) ? arr.filter((i) => i && i.url) : [];
return Array.isArray(arr)
? arr
.filter((i) => i && i.url)
.map((i) => ({ ...i, url: normalizeFileUrl(i.url) }))
: [];
});
const templateType = computed(() => record.value?.templateType || record.value?.medicalType || '');
function normalizeMedicalType(raw) {
const s = String(raw || '').trim();
if (!s) return '';
const lower = s.toLowerCase();
if (lower.includes('preconsult') || (lower.includes('pre') && lower.includes('consult'))) return 'preConsultation';
if (lower === 'outpatient' || lower === 'out_patient' || lower === 'out-patient') return 'outpatient';
if (lower === 'inhospital' || lower === 'in_hospital' || lower === 'in-hospital' || lower === 'inpatient') return 'inhospital';
if (lower === 'preconsultation' || lower === 'pre_consultation' || lower === 'pre-consultation') return 'preConsultation';
if (lower === 'physicalexaminationtemplate' || lower === 'physicalexamination' || lower === 'physical_examination') return 'physicalExaminationTemplate';
if (s === 'outPatient') return 'outpatient';
if (s === 'inHospital') return 'inhospital';
if (s === 'preConsultation') return 'preConsultation';
if (s === 'physicalExaminationTemplate') return 'physicalExaminationTemplate';
return s;
}
const typeLabel = computed(() => record.value?.tempName || getVisitRecordTemplate(templateType.value || medicalType.value)?.templateName || '病历');
const templateType = computed(() => normalizeMedicalType(rawType.value || medicalType.value || record.value?.templateType || record.value?.medicalType || ''));
const typeLabel = computed(() => record.value?.tempName || temp.value?.name || getVisitRecordTemplate(templateType.value || medicalType.value)?.templateName || '病历');
function getDefaultTimeTitle(t) {
if (t === 'outpatient') return 'visitTime';
if (t === 'inhospital') return 'inhosDate';
if (t === 'preConsultation') return 'consultDate';
if (t === 'physicalExaminationTemplate') return 'inspectDate';
return '';
}
function getDefaultTimeName(t) {
if (t === 'outpatient') return '就诊日期';
if (t === 'inhospital') return '入院日期';
if (t === 'preConsultation') return '问诊日期';
if (t === 'physicalExaminationTemplate') return '体检日期';
return '日期';
}
function normalizeText(v) {
if (Array.isArray(v)) return v.filter((i) => i !== null && i !== undefined && String(i).trim()).join('');
if (v === 0) return '0';
if (v && typeof v === 'object') {
const o = v;
const candidate = o.label ?? o.name ?? o.text ?? o.title ?? o.value ?? o.code ?? '';
return candidate ? String(candidate) : '';
}
return v ? String(v) : '';
}
@ -101,68 +147,139 @@ function getCorpId() {
return team?.corpId ? String(team.corpId) : '';
}
function parseAnyTimeMs(v) {
if (v === null || v === undefined) return 0;
if (typeof v === 'number') {
// 10
if (v > 1e9 && v < 1e12) return v * 1000;
return v;
}
const s = String(v).trim();
if (!s) return 0;
if (/^\d{10,13}$/.test(s)) return Number(s.length === 10 ? `${s}000` : s);
const d = dayjs(s);
return d.isValid() ? d.valueOf() : 0;
}
function formatAnyDate(v, fmt = 'YYYY-MM-DD') {
const ms = parseAnyTimeMs(v);
if (!ms) return '';
const d = dayjs(ms);
return d.isValid() ? d.format(fmt) : '';
}
const visitDate = computed(() => {
const t = templateType.value;
if (t === 'outpatient') return record.value?.visitTime || '';
if (t === 'inhospital') return record.value?.inhosDate || '';
if (t === 'preConsultation') return record.value?.consultDate || '';
if (t === 'physicalExaminationTemplate') return record.value?.inspectDate || '';
return record.value?.dateStr || '';
const timeTitle = temp.value?.service?.timeTitle || getDefaultTimeTitle(t);
const raw = timeTitle ? record.value?.[timeTitle] : (record.value?.dateStr ?? record.value?.sortTime ?? '');
return formatAnyDate(raw) || normalizeText(raw) || '';
});
const visitDateLabel = computed(() => {
const t = templateType.value;
return String(temp.value?.service?.timeName || getDefaultTimeName(t) || '日期');
});
const showDiagnosisRow = computed(() => {
const list = Array.isArray(temp.value?.templateList)
? temp.value.templateList
: Array.isArray(getVisitRecordTemplate(templateType.value)?.templateList)
? getVisitRecordTemplate(templateType.value).templateList
: [];
return list.some((i) => i && (i.title === 'diagnosis' || i.title === 'diagnosisName'));
});
const diagnosisText = computed(() => {
const t = templateType.value;
if (t === 'preConsultation') return normalizeText(record.value?.chiefComplaint) || normalizeText(record.value?.summary) || '--';
if (t === 'physicalExaminationTemplate') return formatPositiveFind(record.value?.positiveFind) || normalizeText(record.value?.summary) || '--';
if (!showDiagnosisRow.value) return '--';
if (t === 'outpatient' || t === 'inhospital') return normalizeText(record.value?.diagnosisName || record.value?.diagnosis) || normalizeText(record.value?.summary) || '--';
return normalizeText(record.value?.diagnosisName || record.value?.diagnosis || record.value?.summary) || '--';
});
const showFilesSection = computed(() => {
if (files.value.length) return true;
const list = Array.isArray(temp.value?.templateList)
? temp.value.templateList
: Array.isArray(getVisitRecordTemplate(templateType.value)?.templateList)
? getVisitRecordTemplate(templateType.value).templateList
: [];
return list.some((i) => i && (i.type === 'files' || i.title === 'files'));
});
const sections = computed(() => {
const t = templateType.value;
const push = (title, value) => {
const v = value === 0 ? '0' : value ? String(value) : '';
if (!v.trim()) return;
return { title, value: v };
};
const hiddenKeys = new Set(t === 'outpatient'
? ['corp', 'deptName', 'corpName', 'doctor']
: t === 'inhospital'
? ['corp', 'corpName']
: []);
const list = [];
if (t === 'outpatient') {
const corp = push('就诊机构', record.value?.corpName);
const dept = push('科室', record.value?.deptName);
const doctor = push('医生', record.value?.doctor);
const treatment = push('治疗方案', record.value?.treatmentPlan);
const dispose = push('处置计划', record.value?.disposePlan);
const summary = push('备注/摘要', record.value?.summary);
[corp, dept, doctor, treatment, dispose, summary].forEach((i) => i && list.push(i));
return list;
}
if (t === 'inhospital') {
const corp = push('住院机构', record.value?.corpName);
const summary = push('摘要', record.value?.summary);
[corp, summary].forEach((i) => i && list.push(i));
return list;
}
if (t === 'preConsultation') {
const illness = push('现病史', record.value?.presentIllness);
const past = push('既往史', record.value?.pastHistory);
const allergy = push('过敏史', record.value?.allergyHistory);
const summary = push('摘要', record.value?.summary);
[illness, past, allergy, summary].forEach((i) => i && list.push(i));
return list;
}
if (t === 'physicalExaminationTemplate') {
const corp = push('体检机构', record.value?.corpName);
const pkg = push('体检套餐', record.value?.inspectPakageName);
const positive = push('阳性发现及处理意见', formatPositiveFind(record.value?.positiveFind, { withOpinion: true }));
const summary = push('摘要', record.value?.summary);
[corp, pkg, positive, summary].forEach((i) => i && list.push(i));
return list;
}
const summary = push('摘要', record.value?.summary);
if (summary) list.push(summary);
const pushedNames = new Set();
const pushRow = (name, value) => {
const v = normalizeText(value);
if (!v.trim()) return;
if (pushedNames.has(name)) return;
pushedNames.add(name);
list.push({ title: name, value: v });
};
const resolveOptionLabel = (item, candidate) => {
const range = Array.isArray(item?.range) ? item.range : [];
if (!range.length) return normalizeText(candidate);
const isObjectRange = range[0] && typeof range[0] === 'object';
const toLabel = (v) => {
const s = normalizeText(v);
if (!s) return '';
if (!isObjectRange) return s;
const found = range.find((opt) => opt && typeof opt === 'object' && String(opt.value) === String(s));
return found ? String(found.label ?? found.value ?? s) : s;
};
if (Array.isArray(candidate)) return candidate.map(toLabel).filter((i) => String(i).trim()).join('');
return toLabel(candidate);
};
const templateList = Array.isArray(temp.value?.templateList)
? temp.value.templateList
: Array.isArray(getVisitRecordTemplate(t)?.templateList)
? getVisitRecordTemplate(t).templateList
: [];
const timeTitle = temp.value?.service?.timeTitle || getDefaultTimeTitle(t);
templateList.forEach((item) => {
const key = item?.title ? String(item.title) : '';
if (!key) return;
if (key === 'files') return;
if (key === 'diagnosis' || key === 'diagnosisName') return;
if (timeTitle && key === timeTitle) return;
if (hiddenKeys.has(key)) return;
const raw = record.value?.[key];
const display = key === 'positiveFind'
? formatPositiveFind(raw, { withOpinion: true })
: item?.type === 'date'
? (formatAnyDate(raw) || normalizeText(raw))
: resolveOptionLabel(item, raw);
pushRow(String(item?.name || key), display);
});
return list;
});
async function loadTemplate(t) {
const corpId = getCorpId();
if (!corpId || !t) return null;
try {
const res = await api('getCurrentTemplate', { corpId, templateType: t });
if (!res?.success) return null;
const raw = unwrapTemplateResponse(res);
return normalizeTemplate(raw);
} catch (e) {
return null;
}
}
const topText = computed(() => {
const time = record.value?.createTime ? dayjs(record.value.createTime).format('YYYY-MM-DD HH:mm') : '';
const rawName = record.value?.creatorName ? String(record.value.creatorName) : '';
@ -206,13 +323,11 @@ onLoad(async (opt) => {
setTimeout(() => uni.navigateBack(), 300);
return;
}
// wxapp 使 diagnosis diagnosisName
if ((r.medicalType === 'outpatient' || r.medicalType === 'inhospital') && !r.diagnosis && r.diagnosisName) {
r.diagnosis = r.diagnosisName;
}
record.value = 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 || '病历详情') });
} catch (error) {
hideLoading();

View File

@ -30,13 +30,8 @@
<view class="tabs-area">
<scroll-view scroll-x class="tabs-scroll" :show-scrollbar="false">
<view class="tabs-container">
<view
v-for="tab in tabs"
:key="tab.key"
class="tab-item"
:class="{ active: currentTabKey === tab.key }"
@click="onTabClick(tab)"
>
<view v-for="tab in tabs" :key="tab.key" class="tab-item" :class="{ active: currentTabKey === tab.key }"
@click="onTabClick(tab)">
{{ tab.label }}
</view>
</view>
@ -47,32 +42,24 @@
<!-- Main Content -->
<view class="content-body">
<!-- Patient List -->
<scroll-view
scroll-y
class="patient-list"
:scroll-into-view="scrollIntoId"
:scroll-with-animation="true"
lower-threshold="80"
@scrolltolower="loadMore"
>
<scroll-view scroll-y class="patient-list" :scroll-into-view="scrollIntoId" :scroll-with-animation="true"
lower-threshold="80" @scrolltolower="loadMore">
<view v-for="group in patientList" :key="group.letter" :id="letterToDomId(group.letter)">
<view class="group-title">{{ group.letter }}</view>
<view v-for="(patient, pIndex) in group.data" :key="pIndex" class="patient-card" @click="handlePatientClick(patient)">
<view v-for="(patient, pIndex) in group.data" :key="pIndex" class="patient-card"
@click="handlePatientClick(patient)">
<!-- Checkbox for Batch Mode -->
<view v-if="isBatchMode" class="checkbox-area">
<uni-icons
:type="selectedItems.includes(getSelectId(patient)) ? 'checkbox-filled' : 'checkbox'"
size="24"
:color="selectedItems.includes(getSelectId(patient)) ? '#007aff' : '#ccc'"
></uni-icons>
<uni-icons :type="selectedItems.includes(getSelectId(patient)) ? 'checkbox-filled' : 'checkbox'" size="24"
:color="selectedItems.includes(getSelectId(patient)) ? '#007aff' : '#ccc'"></uni-icons>
</view>
<view class="card-content">
<!-- Row 1 -->
<view class="card-row-top">
<view class="patient-info">
<text class="patient-name">{{ patient.name }}</text>
<text class="patient-meta">{{ patient.gender }}/{{ patient.age }}</text>
<text class="patient-meta">{{ patient.gender }}{{ patient.age ? '/' + patient.age + '岁' : '' }}</text>
</view>
<view class="patient-tags">
<view v-for="(tag, tIndex) in resolveGroupTags(patient)" :key="tIndex" class="tag">
@ -81,11 +68,19 @@
</view>
</view>
<!-- Row 2 / 3 -->
<!-- Row 2 -->
<view v-if="currentTabKey === 'new'" class="card-row-middle">
<text v-if="patient.record" class="record-text record-ellipsis">
{{ patient.record.type }} / {{ patient.record.date }} / {{ patient.record.diagnosis }}
</text>
<text v-else class="no-record">暂无病历记录</text>
</view>
<!-- Row 3 -->
<view class="card-row-bottom">
<template v-if="currentTabKey === 'new'"> <!-- New Patient Tab -->
<text class="record-text">
{{ patient.createTime || '-' }} / {{ resolveCreatorName(patient) || '-' }}
{{ resolveRecentAddTime(patient) }} {{ resolveRecentAddMeta(patient) }}
</text>
</template>
<template v-else>
@ -104,12 +99,7 @@
<!-- Sidebar Index -->
<view v-if="!isBatchMode" class="sidebar-index">
<view
v-for="letter in indexList"
:key="letter"
class="index-item"
@click="scrollToLetter(letter)"
>
<view v-for="letter in indexList" :key="letter" class="index-item" @click="scrollToLetter(letter)">
{{ letter }}
</view>
</view>
@ -120,9 +110,7 @@
<view class="left-action" @click="handleSelectAll">
<uni-icons
:type="selectedItems.length > 0 && selectedItems.length === patientList.flatMap(g => g.data).length ? 'checkbox-filled' : 'checkbox'"
size="24"
color="#666"
></uni-icons>
size="24" color="#666"></uni-icons>
<text class="footer-text">全选 ({{ selectedItems.length }})</text>
</view>
<view class="right-actions">
@ -142,7 +130,7 @@ import dayjs from 'dayjs';
import api from '@/utils/api';
import useAccountStore from '@/store/account';
import { toast } from '@/utils/widget';
import { confirm as uniConfirm, hideLoading, loading as showLoading, toast } from '@/utils/widget';
// State
const teams = ref([]);
@ -202,7 +190,7 @@ const accountStore = useAccountStore();
const { account, doctorInfo } = storeToRefs(accountStore);
const { getDoctorInfo } = accountStore;
const teamDisplay = computed(() => `${currentTeam.value?.name || ''}(${managedArchiveCountAllTeams.value})`);
const teamDisplay = computed(() => `${currentTeam.value?.name || ''}`);
function asArray(value) {
return Array.isArray(value) ? value : [];
@ -234,6 +222,19 @@ function getTeamId() {
return String(currentTeam.value?.teamId || '') || '';
}
function hasCompleteUserInfo() {
const userId = getUserId();
const corpId = String(account.value?.corpId || doctorInfo.value?.corpId || '') || '';
const anotherName = String(doctorInfo.value?.anotherName || '').trim();
return Boolean(corpId && userId && anotherName);
}
function ensureUserInfoForFeature() {
if (hasCompleteUserInfo()) return true;
toast('请先完善个人信息再使用该功能');
return false;
}
async function loadTeamMembers() {
const corpId = getCorpId();
const teamId = getTeamId();
@ -262,6 +263,32 @@ function resolveCreatorName(patient) {
return userNameMap.value[val] || val;
}
function resolveRecentAddTime(patient) {
return patient?.recentAddTime || patient?.createTime || '-';
}
function resolveRecentAddOperatorName(patient) {
const uid = patient?.recentAddOperatorUserId || patient?.creator || '';
if (!uid) return '';
return userNameMap.value[uid] || uid;
}
function resolveRecentAddAction(patient) {
const t = String(patient?.recentAddType || '').trim();
if (!t || t === 'create') return '创建';
if (t === 'share') return '共享';
if (t.startsWith('transfer')) return '转移';
return '创建';
}
function resolveRecentAddMeta(patient) {
const name = resolveRecentAddOperatorName(patient);
const action = resolveRecentAddAction(patient);
if (name) return `${name}${action}`;
if (action === '创建') return '患者创建';
return '-';
}
function applyVerifyStatus(status, reason) {
verifyStatus.value = status || '';
@ -380,6 +407,14 @@ function formatPatient(raw) {
const createTimeStr = createTime ? createTime.format('YYYY-MM-DD HH:mm') : '';
const createTimeTs = createTime ? createTime.valueOf() : 0;
// //退 createTime
const recentAddTimeRaw = raw?.recentAddTime ?? raw?.recentAddAt ?? raw?.recentTime;
const recentAddTime = parseCreateTime(recentAddTimeRaw) || createTime;
const recentAddTimeStr = recentAddTime ? recentAddTime.format('YYYY-MM-DD HH:mm') : '';
const recentAddTimeTs = recentAddTime ? recentAddTime.valueOf() : 0;
const recentAddType = String(raw?.recentAddType || (recentAddTimeRaw ? '' : 'create') || '');
const recentAddOperatorUserId = String(raw?.recentAddOperatorUserId || raw?.recentAddOperator || raw?.creator || '');
// 使 tagNames
const rawTagNames = asArray(raw?.tagNames).filter((i) => typeof i === 'string' && i.trim());
// 使 tags
@ -418,6 +453,10 @@ function formatPatient(raw) {
mobile,
createTime: createTimeStr,
createTimeTs,
recentAddTime: recentAddTimeStr,
recentAddTimeTs,
recentAddType,
recentAddOperatorUserId,
creator: raw?.creatorName || raw?.creator || '',
hospitalId: raw?.customerNumber || raw?.hospitalId || '',
record,
@ -508,8 +547,10 @@ async function reload(reset = true) {
} else if (currentTab.value.kind === 'new') {
const start = dayjs().subtract(7, 'day').startOf('day').valueOf();
const end = dayjs().endOf('day').valueOf();
query.startCreateTime = start;
query.endCreateTime = end;
// = 7 + /
query.startRecentTime = start;
query.endRecentTime = end;
query.includeRecentAddTime = true;
}
loading.value = true;
@ -576,10 +617,14 @@ const patientList = computed(() => {
if (currentTab.value.kind === 'new') {
const sevenDaysAgo = dayjs().subtract(7, 'day').startOf('day').valueOf();
const flatList = all
.filter((p) => Number(p?.createTimeTs || 0) >= sevenDaysAgo)
.filter((p) => Number(p?.recentAddTimeTs || p?.createTimeTs || 0) >= sevenDaysAgo)
.slice()
.sort((a, b) => Number(b?.createTimeTs || 0) - Number(a?.createTimeTs || 0));
return [{ letter: '最近新增', data: flatList }];
.sort(
(a, b) =>
Number(b?.recentAddTimeTs || b?.createTimeTs || 0) -
Number(a?.recentAddTimeTs || a?.createTimeTs || 0)
);
return [{ letter: '最近7天新增', data: flatList }];
}
return groupByLetter(all);
@ -587,12 +632,14 @@ const patientList = computed(() => {
const indexList = computed(() => {
if (currentTab.value.kind === 'new') return []; // No index bar for new patient
return 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('').filter(l => patientList.value.some(g => g.letter === l));
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ#'.split('').filter(l => patientList.value.some(g => g.letter === l));
return letters;
});
const totalPatients = computed(() => {
let count = 0;
patientList.value.forEach(g => count += g.data.length);
if (currentTab.value.kind === 'new') return count;
return totalFromApi.value || count;
});
@ -638,6 +685,7 @@ const goToSearch = () => {
const goToGroupManage = () => {
if (checkBatchMode()) return;
if (!ensureUserInfoForFeature()) return;
uni.navigateTo({
url: '/pages/case/group-manage'
});
@ -657,6 +705,28 @@ const toggleBatchMode = () => {
const handleCreate = () => {
if (checkBatchMode()) return;
const rawMax = doctorInfo.value?.maxCustomerArchive;
const hasMaxField = rawMax !== undefined && rawMax !== null && String(rawMax).trim() !== '';
const maxCustomerArchive = hasMaxField ? Number(rawMax) : NaN;
// maxCustomerArchive
// -1 = 沿10/100
if (hasMaxField && Number.isFinite(maxCustomerArchive)) {
if (maxCustomerArchive !== -1 && managedArchiveCountAllTeams.value >= maxCustomerArchive) {
uni.showModal({
title: '提示',
content: `当前管理档案数已达上限 ${maxCustomerArchive} 个,无法继续新增。如需提升档案管理数,请联系客服处理。`,
cancelText: '知道了',
confirmText: '添加客服',
success: (res) => {
if (res.confirm) {
openAddCustomerServiceEntry();
}
}
});
return;
}
} else {
// 100 ->
if (managedArchiveCountAllTeams.value >= 100) {
uni.showModal({
@ -692,6 +762,7 @@ const handleCreate = () => {
});
return;
}
}
//
uni.showActionSheet({
@ -777,14 +848,149 @@ const cancelBatch = () => {
selectedItems.value = [];
};
const handleTransfer = () => {
function showActionSheet(itemList = [], title = '') {
return new Promise((resolve, reject) => {
if (!Array.isArray(itemList) || itemList.length === 0) {
reject(new Error('empty'));
return;
}
uni.showActionSheet({
title,
itemList,
success: ({ tapIndex }) => resolve(tapIndex),
fail: () => reject(new Error('cancel')),
});
});
}
async function fetchTeamMembersByTeamId(teamId) {
const corpId = getCorpId();
if (!corpId || !teamId) return [];
const res = await api('getTeamData', { corpId, teamId });
if (!res?.success) return [];
const t = res?.data && typeof res.data === 'object' ? res.data : {};
return Array.isArray(t.memberList) ? t.memberList : [];
}
async function transferToCustomerPool(customerIds) {
try {
await uniConfirm('客户将与本团队解除服务关系,本团队成员将没有权限查询到客户档案。');
} catch (e) {
return;
}
const corpId = getCorpId();
const currentTeamId = getTeamId();
const creatorUserId = getUserId();
if (!corpId || !currentTeamId || !creatorUserId) return toast('缺少用户/团队信息');
showLoading('保存中...');
try {
const res = await api('transferCustomers', {
corpId,
customerIds,
currentTeamId,
operationType: 'transferToCustomerPool',
creatorUserId,
});
if (!res?.success) {
toast(res?.message || '操作失败');
return;
}
toast('操作成功');
cancelBatch();
await reload(true);
} catch (e) {
toast('操作失败');
} finally {
hideLoading();
}
}
async function transferToOtherTeam(customerIds) {
const corpId = getCorpId();
const currentTeamId = getTeamId();
const creatorUserId = getUserId();
if (!corpId || !currentTeamId || !creatorUserId) return toast('缺少用户/团队信息');
if (!teams.value.length) await loadTeams();
const candidates = teams.value.filter((t) => String(t?.teamId || '') !== String(currentTeamId));
if (!candidates.length) return toast('暂无可选团队');
let teamIndex;
try {
teamIndex = await showActionSheet(candidates.map((t) => t.name || ''), '选择新负责团队');
} catch (e) {
return;
}
const pickedTeam = candidates[teamIndex];
if (!pickedTeam?.teamId) return toast('团队信息异常');
let members = [];
try {
members = await fetchTeamMembersByTeamId(pickedTeam.teamId);
} catch (e) {
members = [];
}
if (!members.length) return toast('当前团队暂无可选成员');
const labels = members.map((m) => String(m?.anotherName || m?.name || m?.userid || ''));
let userIndex;
try {
userIndex = await showActionSheet(labels, '选择责任人');
} catch (e) {
return;
}
const pickedUser = members[userIndex] || null;
const targetUserId = String(pickedUser?.userid || '') || '';
if (!targetUserId) return toast('责任人信息异常');
showLoading('保存中...');
try {
const res = await api('transferCustomers', {
corpId,
customerIds,
currentTeamId,
targetTeamId: String(pickedTeam.teamId),
targetUserId,
operationType: 'transferToOtherTeam',
creatorUserId,
});
if (!res?.success) {
toast(res?.message || '操作失败');
return;
}
toast('操作成功');
cancelBatch();
await reload(true);
} catch (e) {
toast('操作失败');
} finally {
hideLoading();
}
}
const handleTransfer = async () => {
if (selectedItems.value.length === 0) {
uni.showToast({ title: '请选择患者', icon: 'none' });
return;
}
uni.setStorageSync(BATCH_CUSTOMER_IDS_KEY, selectedItems.value.slice());
// Navigate to Transfer Page
uni.navigateTo({ url: '/pages/case/batch-transfer' });
let tapIndex;
try {
tapIndex = await showActionSheet(['转移给其他团队', '转移至客户公共池']);
} catch (e) {
return;
}
const customerIds = selectedItems.value.slice().map(String).filter(Boolean);
if (!customerIds.length) return toast('请选择患者');
if (tapIndex === 0) {
await transferToOtherTeam(customerIds);
} else if (tapIndex === 1) {
await transferToCustomerPool(customerIds);
}
};
const handleShare = () => {
@ -817,6 +1023,8 @@ function onTabClick(tab) {
if (checkBatchMode()) return;
if (!tab || !tab.key) return;
if (currentTabKey.value === tab.key) return;
if (tab.kind === 'group' && !ensureUserInfoForFeature()) return;
currentTabKey.value = tab.key;
}
@ -953,7 +1161,7 @@ onShow(async () => {
color: #666;
white-space: nowrap;
flex-shrink: 0;
min-width: 100rpx;
min-width: 70rpx;
text-align: right;
}
}
@ -1035,6 +1243,27 @@ onShow(async () => {
}
}
.card-row-middle {
font-size: 28rpx;
margin-bottom: 12rpx;
.record-text {
color: #666;
}
.record-ellipsis {
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
.no-record {
color: #bdc3c7;
}
}
.card-row-bottom {
font-size: 28rpx;
@ -1067,12 +1296,13 @@ onShow(async () => {
align-items: center;
justify-content: space-between;
padding: 0 30rpx;
box-shadow: 0 -4rpx 20rpx rgba(0,0,0,0.05);
box-shadow: 0 -4rpx 20rpx rgba(0, 0, 0, 0.05);
z-index: 99;
.left-action {
display: flex;
align-items: center;
.footer-text {
margin-left: 10rpx;
font-size: 28rpx;

View File

@ -1,18 +1,33 @@
<template>
<view class="message-page">
<!-- 头部组件 -->
<message-header v-model:activeTab="activeTab" @team-change="handleTeamChange" @add-patient="handleAddPatient" />
<message-header
v-model:activeTab="activeTab"
@team-change="handleTeamChange"
@add-patient="handleAddPatient"
/>
<!-- 消息列表 -->
<scroll-view class="message-list" scroll-y="true" refresher-enabled :refresher-triggered="refreshing"
@refresherrefresh="handleRefresh" @scrolltolower="handleLoadMore">
<scroll-view
class="message-list"
scroll-y="true"
refresher-enabled
:refresher-triggered="refreshing"
@refresherrefresh="handleRefresh"
@scrolltolower="handleLoadMore"
>
<!-- 消息列表项 -->
<view v-for="conversation in filteredConversationList"
:key="conversation.groupID || conversation.conversationID" class="message-item"
@click="handleClickConversation(conversation)">
<view
v-for="conversation in filteredConversationList"
:key="conversation.groupID || conversation.conversationID"
class="message-item"
@click="handleClickConversation(conversation)"
>
<view class="avatar-container">
<image class="avatar" :src="conversation.avatar || '/static/default-avatar.png'"
mode="aspectFill" />
<image
class="avatar"
:src="conversation.avatar || '/static/default-patient-avatar.png'"
mode="aspectFill"
/>
<view v-if="conversation.unreadCount > 0" class="unread-badge">
<text class="unread-text">{{
conversation.unreadCount > 99 ? "99+" : conversation.unreadCount
@ -24,7 +39,10 @@
<view class="header">
<view class="name-info">
<text class="name">{{ formatPatientName(conversation) }}</text>
<text v-if="conversation.patientSex || conversation.patientAge" class="patient-info">
<text
v-if="conversation.patientSex || conversation.patientAge"
class="patient-info"
>
{{ formatPatientInfo(conversation) }}
</text>
</view>
@ -34,14 +52,24 @@
</view>
<view class="message-preview">
<text class="preview-text">{{
conversation.lastMessage || "暂无消息"
cleanMessageText(conversation.lastMessage) || "暂无消息"
}}</text>
</view>
</view>
</view>
<!-- 空状态 -->
<view v-if="!loading && filteredConversationList.length === 0" class="empty-container">
<view
v-if="!loading && conversationList.length === 0"
class="empty-container"
>
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
<text class="empty-text">暂无会话</text>
</view>
<view
v-else-if="!loading && filteredConversationList.length === 0"
class="empty-container"
>
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
<text class="empty-text">{{
activeTab === "processing" ? "暂无处理中的会话" : "暂无已结束的会话"
@ -49,7 +77,10 @@
</view>
<!-- 加载更多 -->
<view v-if="hasMore && filteredConversationList.length > 0" class="load-more">
<view
v-if="hasMore && filteredConversationList.length > 0"
class="load-more"
>
<text class="load-more-text">{{
loadingMore ? "加载中..." : "上拉加载更多"
}}</text>
@ -59,63 +90,40 @@
</template>
<script setup>
import {
ref,
computed
} from "vue";
import {
onLoad,
onShow,
onHide
} from "@dcloudio/uni-app";
import {
storeToRefs
} from "pinia";
import useAccountStore from "@/store/account.js";
import useTeamStore from "@/store/team.js";
import useInfoCheck from "@/hooks/useInfoCheck.js";
import {
globalTimChatManager
} from "@/utils/tim-chat.js";
import {
mergeConversationWithGroupDetails
} from "@/utils/conversation-merger.js";
import MessageHeader from "./components/message-header.vue";
import { ref, computed } from "vue";
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
import { storeToRefs } from "pinia";
import useAccountStore from "@/store/account.js";
import useTeamStore from "@/store/team.js";
import useInfoCheck from "@/hooks/useInfoCheck.js";
import { globalTimChatManager } from "@/utils/tim-chat.js";
import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.js";
import MessageHeader from "../home/components/message-header.vue";
//
const {
account,
openid,
isIMInitialized
} = storeToRefs(useAccountStore());
const {
initIMAfterLogin
} = useAccountStore();
//
const { account, openid, isIMInitialized } = storeToRefs(useAccountStore());
const { initIMAfterLogin } = useAccountStore();
//
const teamStore = useTeamStore();
const {
getTeams
} = teamStore;
//
const teamStore = useTeamStore();
const { getTeams } = teamStore;
//
const {
withInfo
} = useInfoCheck();
//
const { withInfo } = useInfoCheck();
//
const currentTeamId = ref(""); // ""
//
const currentTeamId = ref(""); // ""
//
const conversationList = ref([]);
const loading = ref(false);
const loadingMore = ref(false);
const hasMore = ref(false);
const refreshing = ref(false);
const activeTab = ref("processing");
//
const conversationList = ref([]);
const loading = ref(false);
const loadingMore = ref(false);
const hasMore = ref(false);
const refreshing = ref(false);
const activeTab = ref("processing");
// orderStatus
const filteredConversationList = computed(() => {
// orderStatus
const filteredConversationList = computed(() => {
let filtered = [];
if (activeTab.value === "processing") {
@ -139,61 +147,206 @@
filtered = filtered.filter((conv) => conv.teamId === currentTeamId.value);
}
return filtered;
});
});
//
const handleTeamChange = (teamId) => {
//
const handleTeamChange = (teamId) => {
currentTeamId.value = teamId;
console.log("切换到团队ID:", teamId);
};
};
// - 使 withInfo 使
const handleAddPatient = withInfo(() => {
// - 使 withInfo 使
const handleAddPatient = withInfo(() => {
uni.navigateTo({
url: "/pages/work/team/invite/invite-patient",
});
});
});
// IM
const initIM = async () => {
if (!isIMInitialized.value) {
//
const updateUnreadBadgeImmediately = async () => {
try {
if (!globalTimChatManager || !globalTimChatManager.tim) {
console.warn("TIM实例不存在无法更新徽章");
return;
}
const response = await globalTimChatManager.tim.getConversationList();
if (!response || !response.data || !response.data.conversationList) {
console.warn("获取会话列表返回数据异常");
return;
}
//
const totalUnreadCount = response.data.conversationList
.filter(
(conv) => conv.conversationID && conv.conversationID.startsWith("GROUP")
)
.reduce((sum, conv) => sum + (conv.unreadCount || 0), 0);
// tabBar - TabBar
try {
if (totalUnreadCount > 0) {
uni.setTabBarBadge({
index: 1,
text: totalUnreadCount > 99 ? "99+" : String(totalUnreadCount),
});
console.log("已更新 tabBar 徽章:", totalUnreadCount);
} else {
uni.removeTabBarBadge({
index: 1,
});
console.log("已移除 tabBar 徽章");
}
} catch (badgeError) {
// TabBar
if (badgeError.errMsg && badgeError.errMsg.includes("not TabBar page")) {
console.log("当前不是TabBar页面跳过徽章更新");
} else {
console.error("更新TabBar徽章失败:", badgeError);
}
}
} catch (error) {
console.error("更新未读徽章失败:", error);
}
};
// IM
const initIM = async () => {
// isIMInitialized
const needsInit =
!isIMInitialized.value ||
!globalTimChatManager ||
!globalTimChatManager.isLoggedIn;
if (needsInit) {
uni.showLoading({
title: "连接中...",
});
//
if (
isIMInitialized.value &&
globalTimChatManager &&
!globalTimChatManager.isLoggedIn
) {
console.log("IM已初始化但连接已断开清理旧实例后重新初始化");
await globalTimChatManager.cleanupOldInstance();
}
const success = await initIMAfterLogin();
uni.hideLoading();
if (!success) {
uni.showToast({
title: "IM连接失败请重试",
icon: "none",
});
return false;
}
} else if (globalTimChatManager && !globalTimChatManager.isLoggedIn) {
uni.showLoading({
title: "重连中...",
});
const reconnected = await globalTimChatManager.ensureIMConnection();
uni.hideLoading();
if (!reconnected) {
return false;
handleReloginIM();
// //
// uni.showModal({
// title: "IM",
// content:
// "IMIM",
// confirmText: "",
// cancelText: "",
// success: (res) => {
// if (res.confirm) {
// //
// handleReloginIM();
// }
// },
// });
// return false;
}
}
return true;
};
};
//
const loadConversationList = async () => {
// IM
const handleReloginIM = async () => {
try {
uni.showLoading({
title: "重新登陆中...",
});
// IM
if (globalTimChatManager) {
await globalTimChatManager.cleanupOldInstance();
}
// IM
const { initIMAfterLogin } = useAccountStore();
const success = await initIMAfterLogin();
uni.hideLoading();
if (success) {
// uni.showToast({
// title: "IM",
// icon: "success",
// });
//
await loadConversationList();
setupConversationListener();
} else {
// uni.showToast({
// title: "IM",
// icon: "none",
// });
}
} catch (error) {
uni.hideLoading();
console.error("重新登陆IM失败:", error);
// uni.showToast({
// title: "",
// icon: "none",
// });
}
};
//
const loadConversationList = async () => {
if (loading.value) return;
loading.value = true;
try {
console.log("开始加载群聊列表");
if (!globalTimChatManager || !globalTimChatManager.getGroupList) {
// IM
if (!globalTimChatManager) {
throw new Error("IM管理器未初始化");
}
const result = await globalTimChatManager.getGroupList();
// TIM
if (!globalTimChatManager.tim) {
console.warn("TIM实例不存在尝试重新初始化IM");
const reinitialized = await initIMAfterLogin();
if (!reinitialized) {
throw new Error("IM重新初始化失败");
}
}
// -
if (!globalTimChatManager.isLoggedIn) {
console.warn("IM未登录尝试重新连接");
const reconnected = await globalTimChatManager.ensureIMConnection();
if (!reconnected) {
throw new Error("IM重新连接失败");
}
}
if (!globalTimChatManager.getGroupList) {
throw new Error("IM管理器方法不可用");
}
//
const timeoutPromise = new Promise((_, reject) => {
setTimeout(
() => reject(new Error("加载会话列表超时,请检查网络连接")),
35000
);
});
const result = await Promise.race([
globalTimChatManager.getGroupList(),
timeoutPromise,
]);
if (result && result.success && result.groupList) {
//
conversationList.value = await mergeConversationWithGroupDetails(
@ -216,27 +369,36 @@
);
} else {
console.error("加载群聊列表失败:", result);
uni.showToast({
title: "加载失败,请重试",
icon: "none",
});
throw new Error(result?.message || "加载失败,请重试");
}
} catch (error) {
console.error("加载会话列表失败:", error);
//
if (
error.message &&
(error.message.includes("超时") || error.message.includes("连接"))
) {
uni.showToast({
title: "网络连接不稳定,请重试",
icon: "none",
});
} else {
uni.showToast({
title: error.message || "加载失败,请重试",
icon: "none",
});
}
} finally {
loading.value = false;
}
};
};
//
let updateTimer = null;
//
let updateTimer = null;
//
const setupConversationListener = () => {
//
const setupConversationListener = () => {
if (!globalTimChatManager) return;
//
@ -307,8 +469,7 @@
const existing = conversationList.value[existingIndex];
if (
existing.lastMessage !== conversationData.lastMessage ||
existing.lastMessageTime !== conversationData
.lastMessageTime ||
existing.lastMessageTime !== conversationData.lastMessageTime ||
existing.unreadCount !== conversationData.unreadCount ||
existing.patientName !== conversationData.patientName ||
existing.patientSex !== conversationData.patientSex ||
@ -386,15 +547,21 @@
);
}
});
};
};
//
const formatPatientName = (conversation) => {
//
const cleanMessageText = (text) => {
if (!text) return "";
return text.replace(/[\r\n]+/g, " ").trim();
};
//
const formatPatientName = (conversation) => {
return conversation.patientName || "未知患者";
};
};
// +
const formatPatientInfo = (conversation) => {
// +
const formatPatientInfo = (conversation) => {
const parts = [];
//
@ -410,10 +577,10 @@
}
return parts.join(" ");
};
};
//
const formatMessageTime = (timestamp) => {
//
const formatMessageTime = (timestamp) => {
if (!timestamp) return "";
const now = Date.now();
@ -452,10 +619,10 @@
//
return `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`;
};
};
//
const handleClickConversation = (conversation) => {
//
const handleClickConversation = (conversation) => {
console.log("点击会话:", conversation);
//
@ -469,12 +636,12 @@
//
uni.navigateTo({
url: `/pages/message/index?conversationID=${conversation.conversationID}&groupID=${conversation.groupID}`,
url: `/pages/message/index?conversationID=${encodeURIComponent(conversation.conversationID)}&groupID=${encodeURIComponent(conversation.groupID)}`,
});
};
};
//
const handleLoadMore = () => {
//
const handleLoadMore = () => {
if (loadingMore.value || !hasMore.value) return;
loadingMore.value = true;
@ -482,30 +649,30 @@
setTimeout(() => {
loadingMore.value = false;
}, 1000);
};
};
//
const handleRefresh = async () => {
//
const handleRefresh = async () => {
refreshing.value = true;
try {
await loadConversationList();
} finally {
refreshing.value = false;
}
};
};
//
onLoad(() => {
//
onLoad(() => {
console.log("消息列表页面加载");
});
});
//
onShow(async () => {
//
onShow(async () => {
try {
//
await getTeams();
// IM
// IM - IM
const imReady = await initIM();
if (!imReady) {
console.error("IM初始化失败");
@ -524,10 +691,10 @@
icon: "none",
});
}
});
});
//
onHide(() => {
//
onHide(() => {
//
if (updateTimer) {
clearTimeout(updateTimer);
@ -539,49 +706,49 @@
globalTimChatManager.setCallback("onConversationListUpdated", null);
globalTimChatManager.setCallback("onMessageReceived", null);
}
});
});
</script>
<style scoped lang="scss">
.message-page {
.message-page {
width: 100%;
height: 100vh;
background-color: #f5f5f5;
display: flex;
flex-direction: column;
}
}
.message-list {
.message-list {
width: 100%;
flex: 1;
}
}
.loading-container,
.empty-container {
.loading-container,
.empty-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
}
.loading-text {
.loading-text {
font-size: 28rpx;
color: #999;
}
}
.empty-image {
.empty-image {
width: 200rpx;
height: 200rpx;
margin-bottom: 20rpx;
}
}
.empty-text {
.empty-text {
font-size: 28rpx;
color: #999;
}
}
.message-item {
.message-item {
display: flex;
align-items: center;
padding: 24rpx 32rpx;
@ -591,21 +758,21 @@
&:active {
background-color: #f5f5f5;
}
}
}
.avatar-container {
.avatar-container {
position: relative;
margin-right: 24rpx;
flex-shrink: 0;
}
}
.avatar {
.avatar {
width: 96rpx;
height: 96rpx;
border-radius: 8rpx;
}
}
.unread-badge {
.unread-badge {
position: absolute;
top: -8rpx;
right: -8rpx;
@ -617,37 +784,37 @@
display: flex;
align-items: center;
justify-content: center;
}
}
.unread-text {
.unread-text {
font-size: 20rpx;
color: #fff;
line-height: 1;
}
}
.content {
.content {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
min-width: 0;
}
}
.header {
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8rpx;
}
}
.name-info {
.name-info {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
}
}
.name {
.name {
font-size: 30rpx;
font-weight: 500;
color: #333;
@ -655,42 +822,45 @@
text-overflow: ellipsis;
white-space: nowrap;
flex-shrink: 1;
}
}
.patient-info {
.patient-info {
font-size: 26rpx;
padding-left: 12rpx;
color: #999;
flex-shrink: 0;
}
}
.time {
.time {
font-size: 24rpx;
color: #999;
margin-left: 16rpx;
flex-shrink: 0;
}
}
.message-preview {
.message-preview {
display: flex;
align-items: center;
}
}
.preview-text {
.preview-text {
font-size: 26rpx;
color: #999;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
word-break: break-all;
}
.load-more {
.load-more {
padding: 20rpx 0;
text-align: center;
}
}
.load-more-text {
.load-more-text {
font-size: 24rpx;
color: #999;
}
}
</style>

View File

@ -9,7 +9,7 @@
<view class="label">{{ item.label }}</view>
<uni-icons :type="selectedMap[item.label] ? 'checkmarkempty' : ''" size="22" color="#007aff" />
</view>
<view v-if="showList.length === 0" class="empty">暂无诊断数据</view>
<view v-if="showList.length === 0" class="empty">{{ keyword.trim() ? '暂无诊断数据' : '请输入关键词搜索' }}</view>
<view style="height: 240rpx;"></view>
</scroll-view>
@ -31,6 +31,7 @@ const list = ref([]);
const selections = ref([]);
const mult = ref(false);
const eventName = ref('change-diagnosis');
let lastQueryId = 0;
const selectedMap = computed(() => selections.value.reduce((m, i) => ((m[i] = true), m), {}));
@ -38,22 +39,8 @@ function normalizeText(v) {
return v ? String(v) : '';
}
const fullMatched = computed(() => {
const value = String(keyword.value || '').trim();
if (!value) return null;
return { label: value, value, key: `full_${value}` };
});
const showList = computed(() => {
const base = Array.isArray(list.value) ? list.value : [];
const arr = [];
if (fullMatched.value) arr.push(fullMatched.value);
base.forEach((i) => {
if (!i || !i.label) return;
if (fullMatched.value && i.label === fullMatched.value.label) return;
arr.push(i);
});
return arr;
return Array.isArray(list.value) ? list.value : [];
});
let timer = null;
@ -89,11 +76,25 @@ onLoad((opt) => {
async function query() {
if (!ready.value) return;
const value = String(keyword.value || '').trim();
if (!value) {
list.value = [];
return;
}
const queryId = ++lastQueryId;
uni.showLoading({ title: '加载中...' });
try {
uni.showLoading({ title: '加载中...' });
const res = await api('getDisease', { diseaseName: value });
const arr = Array.isArray(res?.data?.data) ? res.data.data : [];
if (queryId !== lastQueryId) return;
const arr =
Array.isArray(res?.data?.data) ? res.data.data
: Array.isArray(res?.data?.list) ? res.data.list
: Array.isArray(res?.data?.data?.data) ? res.data.data.data
: Array.isArray(res?.data) ? res.data
: Array.isArray(res?.list) ? res.list
: Array.isArray(res?.data?.data?.list) ? res.data.data.list
: [];
list.value = arr
.map((i) => {
const label = normalizeText(i?.diseaseName);
@ -103,9 +104,9 @@ async function query() {
})
.filter(Boolean);
} catch (e) {
list.value = [];
if (queryId === lastQueryId) list.value = [];
} finally {
uni.hideLoading();
if (queryId === lastQueryId) uni.hideLoading();
}
}

View File

@ -5,7 +5,13 @@
<view class="mt-12 text-base text-dark">全周期健康管理伙伴</view>
</view>
<view class="login-btn-wrap">
<button v-if="checked" class="login-btn" type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
<button
v-if="checked"
class="login-btn"
type="primary"
open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber"
>
手机号快捷登录
</button>
<!-- <button v-if="checked" class="login-btn" type="primary" @click="getPhoneNumber()">
@ -15,7 +21,10 @@
手机号快捷登录
</button>
</view>
<view class="flex items-center justify-center mt-12 px-15" @click="checked = !checked">
<view
class="flex items-center justify-center mt-12 px-15"
@click="checked = !checked"
>
<checkbox :checked="checked" style="transform: scale(0.7)" />
<view class="text-sm text-gray">我已阅读并同意</view>
<view class="text-sm text-primary">用户协议</view>
@ -76,8 +85,8 @@ async function getPhoneNumber(e) {
await attempToPage(redirectUrl.value);
} else if (res && !(doctorInfo.value && doctorInfo.value.anotherName)) {
uni.redirectTo({
url: '/pages/work/profile'
})
url: "/pages/work/profile",
});
} else if (res) {
toHome();
}

View File

@ -1,6 +1,6 @@
// SCSS 变量定义
$font-size-text: 28rpx;
$font-size-tip: 24rpx;
$font-size-text: 30rpx;
$font-size-tip: 28rpx;
$font-size-title: 32rpx;
$text-color-sub: #999;
$primary-color: #0877F1;
@ -11,16 +11,23 @@ $primary-color: #0877F1;
height: 100vh;
background-color: #f5f5f5;
overflow: hidden;
position: relative;
width: 100%;
}
/* 患者信息栏样式 */
/* 患者信息栏样式 - 固定在顶部 */
.patient-info-bar {
position: relative;
position: fixed;
top: 0;
left: 0;
right: 0;
background: #fff;
border-bottom: 1rpx solid #f0f0f0;
padding: 20rpx 32rpx;
z-index: 10;
z-index: 100;
flex-shrink: 0; /* 防止被压缩 */
width: 100%;
box-sizing: border-box;
}
.patient-info-content {
@ -87,7 +94,12 @@ $primary-color: #0877F1;
flex: 1;
box-sizing: border-box;
overflow-x: hidden;
overflow-y: auto;
min-height: 0;
margin-top: 120rpx;
margin-bottom: 0;
position: relative;
z-index: 1;
}
.chat-content-compressed {
@ -331,7 +343,7 @@ $primary-color: #0877F1;
}
.message-text {
font-size: $font-size-text;
font-size: 30rpx;
line-height: 1.4;
word-wrap: break-word;
word-break: break-all;

View File

@ -348,7 +348,7 @@ const handleNextFromProgress = (data) => {
//
uni.navigateTo({
url: `/pages/case/medical-case-form?caseType=${data.caseType}&patientId=${
url: `/pages/case/ai-medical-case-form?caseType=${data.caseType}&patientId=${
props.patientId
}&groupId=${props.groupId}&formData=${encodeURIComponent(
JSON.stringify(extractedData)

View File

@ -93,6 +93,7 @@ const FIELD_LABELS = {
inspectSummary: "体检小结",
positiveFind: "阳性发现及处理意见",
//
consultationDate: "问诊日期",
presentIllnessHistory: "现病史",
pastMedicalHistory: "既往史",
};

View File

@ -369,16 +369,28 @@ function getBubbleClass(message) {
//
onLoad((options) => {
groupId.value = options.groupID || "";
const decodeQueryValue = (v) => {
const s = typeof v === "string" ? v : String(v || "");
if (!s) return "";
try {
return decodeURIComponent(s);
} catch (e) {
return s;
}
};
const rawGroupId = decodeQueryValue(options.groupID || "");
groupId.value = rawGroupId.startsWith("GROUP") ? rawGroupId.replace(/^GROUP/, "") : rawGroupId;
messageList.value = [];
isLoading.value = false;
if (options.conversationID) {
chatInfo.value.conversationID = options.conversationID;
timChatManager.setConversationID(options.conversationID);
console.log("设置当前会话ID:", options.conversationID);
const cid = decodeQueryValue(options.conversationID);
chatInfo.value.conversationID = cid;
timChatManager.setConversationID(cid);
console.log("设置当前会话ID:", cid);
}
if (options.userID) {
chatInfo.value.userID = options.userID;
chatInfo.value.userID = decodeQueryValue(options.userID);
}
checkLoginAndInitTIM();
@ -393,13 +405,13 @@ const checkLoginAndInitTIM = async () => {
});
const success = await initIMAfterLogin();
uni.hideLoading();
if (!success) {
uni.showToast({
title: "IM连接失败请重试",
icon: "none",
});
return;
}
// if (!success) {
// uni.showToast({
// title: "IM",
// icon: "none",
// });
// return;
// }
} else if (!timChatManager.isLoggedIn) {
uni.showLoading({
title: "重连中...",
@ -769,12 +781,29 @@ onShow(() => {
checkLoginAndInitTIM();
} else if (timChatManager.tim && !timChatManager.isLoggedIn) {
timChatManager.ensureIMConnection();
} else if (timChatManager.tim && timChatManager.isLoggedIn && chatInfo.value.conversationID) {
//
console.log("页面从后台返回,重新加载消息列表");
messageList.value = [];
isCompleted.value = false;
lastFirstMessageId.value = "";
loadMessageList();
}
startIMMonitoring(30000);
// 访
uni.$on("send-followup-message", handleSendFollowUpMessage);
//
uni.onKeyboardHeightChange((res) => {
if (res.height > 0) {
//
setTimeout(() => {
scrollToBottom(true);
}, 100);
}
});
});
// 访

View File

@ -1,18 +1,33 @@
<template>
<view class="message-page">
<!-- 头部组件 -->
<message-header v-model:activeTab="activeTab" @team-change="handleTeamChange" @add-patient="handleAddPatient" />
<message-header
v-model:activeTab="activeTab"
@team-change="handleTeamChange"
@add-patient="handleAddPatient"
/>
<!-- 消息列表 -->
<scroll-view class="message-list" scroll-y="true" refresher-enabled :refresher-triggered="refreshing"
@refresherrefresh="handleRefresh" @scrolltolower="handleLoadMore">
<scroll-view
class="message-list"
scroll-y="true"
refresher-enabled
:refresher-triggered="refreshing"
@refresherrefresh="handleRefresh"
@scrolltolower="handleLoadMore"
>
<!-- 消息列表项 -->
<view v-for="conversation in filteredConversationList"
:key="conversation.groupID || conversation.conversationID" class="message-item"
@click="handleClickConversation(conversation)">
<view
v-for="conversation in filteredConversationList"
:key="conversation.groupID || conversation.conversationID"
class="message-item"
@click="handleClickConversation(conversation)"
>
<view class="avatar-container">
<image class="avatar" :src="conversation.avatar || '/static/default-patient-avatar.png'"
mode="aspectFill" />
<image
class="avatar"
:src="conversation.avatar || '/static/default-patient-avatar.png'"
mode="aspectFill"
/>
<view v-if="conversation.unreadCount > 0" class="unread-badge">
<text class="unread-text">{{
conversation.unreadCount > 99 ? "99+" : conversation.unreadCount
@ -24,7 +39,10 @@
<view class="header">
<view class="name-info">
<text class="name">{{ formatPatientName(conversation) }}</text>
<text v-if="conversation.patientSex || conversation.patientAge" class="patient-info">
<text
v-if="conversation.patientSex || conversation.patientAge"
class="patient-info"
>
{{ formatPatientInfo(conversation) }}
</text>
</view>
@ -41,7 +59,20 @@
</view>
<!-- 空状态 -->
<view v-if="!loading && filteredConversationList.length === 0" class="empty-container">
<view
v-if="!loading && conversationList.length === 0"
class="empty-container"
>
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
<text class="empty-text">医生信息未获取请稍后重试</text>
</view>
<view
v-else-if="
!loading &&
filteredConversationList.length === 0
"
class="empty-container"
>
<image class="empty-image" src="/static/empty.svg" mode="aspectFit" />
<text class="empty-text">{{
activeTab === "processing" ? "暂无处理中的会话" : "暂无已结束的会话"
@ -49,7 +80,10 @@
</view>
<!-- 加载更多 -->
<view v-if="hasMore && filteredConversationList.length > 0" class="load-more">
<view
v-if="hasMore && filteredConversationList.length > 0"
class="load-more"
>
<text class="load-more-text">{{
loadingMore ? "加载中..." : "上拉加载更多"
}}</text>
@ -59,63 +93,40 @@
</template>
<script setup>
import {
ref,
computed
} from "vue";
import {
onLoad,
onShow,
onHide
} from "@dcloudio/uni-app";
import {
storeToRefs
} from "pinia";
import useAccountStore from "@/store/account.js";
import useTeamStore from "@/store/team.js";
import useInfoCheck from "@/hooks/useInfoCheck.js";
import {
globalTimChatManager
} from "@/utils/tim-chat.js";
import {
mergeConversationWithGroupDetails
} from "@/utils/conversation-merger.js";
import MessageHeader from "../home/components/message-header.vue";
import { ref, computed } from "vue";
import { onLoad, onShow, onHide } from "@dcloudio/uni-app";
import { storeToRefs } from "pinia";
import useAccountStore from "@/store/account.js";
import useTeamStore from "@/store/team.js";
import useInfoCheck from "@/hooks/useInfoCheck.js";
import { globalTimChatManager } from "@/utils/tim-chat.js";
import { mergeConversationWithGroupDetails } from "@/utils/conversation-merger.js";
import MessageHeader from "../home/components/message-header.vue";
//
const {
account,
openid,
isIMInitialized
} = storeToRefs(useAccountStore());
const {
initIMAfterLogin
} = useAccountStore();
//
const { account, openid, isIMInitialized } = storeToRefs(useAccountStore());
const { initIMAfterLogin } = useAccountStore();
//
const teamStore = useTeamStore();
const {
getTeams
} = teamStore;
//
const teamStore = useTeamStore();
const { getTeams } = teamStore;
//
const {
withInfo
} = useInfoCheck();
//
const { withInfo } = useInfoCheck();
//
const currentTeamId = ref(""); // ""
//
const currentTeamId = ref(""); // ""
//
const conversationList = ref([]);
const loading = ref(false);
const loadingMore = ref(false);
const hasMore = ref(false);
const refreshing = ref(false);
const activeTab = ref("processing");
//
const conversationList = ref([]);
const loading = ref(false);
const loadingMore = ref(false);
const hasMore = ref(false);
const refreshing = ref(false);
const activeTab = ref("processing");
// orderStatus
const filteredConversationList = computed(() => {
// orderStatus
const filteredConversationList = computed(() => {
let filtered = [];
if (activeTab.value === "processing") {
@ -139,23 +150,23 @@
filtered = filtered.filter((conv) => conv.teamId === currentTeamId.value);
}
return filtered;
});
});
//
const handleTeamChange = (teamId) => {
//
const handleTeamChange = (teamId) => {
currentTeamId.value = teamId;
console.log("切换到团队ID:", teamId);
};
};
// - 使 withInfo 使
const handleAddPatient = withInfo(() => {
// - 使 withInfo 使
const handleAddPatient = withInfo(() => {
uni.navigateTo({
url: "/pages/work/team/invite/invite-patient",
});
});
});
// IM
const initIM = async () => {
// IM
const initIM = async () => {
if (!isIMInitialized.value) {
uni.showLoading({
title: "连接中...",
@ -167,7 +178,8 @@
//
uni.showModal({
title: "IM连接失败",
content: "连接失败请检查网络后重试。如果IM连接失败请重新登陆IM再连接",
content:
"连接失败请检查网络后重试。如果IM连接失败请重新登陆IM再连接",
confirmText: "重新登陆",
cancelText: "取消",
success: (res) => {
@ -175,7 +187,7 @@
//
handleReloginIM();
}
}
},
});
return false;
}
@ -190,7 +202,8 @@
//
uni.showModal({
title: "IM连接失败",
content: "连接失败请检查网络后重试。如果IM连接失败请重新登陆IM再连接",
content:
"连接失败请检查网络后重试。如果IM连接失败请重新登陆IM再连接",
confirmText: "重新登陆",
cancelText: "取消",
success: (res) => {
@ -198,16 +211,16 @@
//
handleReloginIM();
}
}
},
});
return false;
}
}
return true;
};
};
// IM
const handleReloginIM = async () => {
// IM
const handleReloginIM = async () => {
try {
uni.showLoading({
title: "重新登陆中...",
@ -245,10 +258,10 @@
icon: "none",
});
}
};
};
//
const loadConversationList = async () => {
//
const loadConversationList = async () => {
if (loading.value) return;
loading.value = true;
try {
@ -318,13 +331,13 @@
} finally {
loading.value = false;
}
};
};
//
let updateTimer = null;
//
let updateTimer = null;
//
const setupConversationListener = () => {
//
const setupConversationListener = () => {
if (!globalTimChatManager) return;
//
@ -395,8 +408,7 @@
const existing = conversationList.value[existingIndex];
if (
existing.lastMessage !== conversationData.lastMessage ||
existing.lastMessageTime !== conversationData
.lastMessageTime ||
existing.lastMessageTime !== conversationData.lastMessageTime ||
existing.unreadCount !== conversationData.unreadCount ||
existing.patientName !== conversationData.patientName ||
existing.patientSex !== conversationData.patientSex ||
@ -474,15 +486,15 @@
);
}
});
};
};
//
const formatPatientName = (conversation) => {
//
const formatPatientName = (conversation) => {
return conversation.patientName || "未知患者";
};
};
// +
const formatPatientInfo = (conversation) => {
// +
const formatPatientInfo = (conversation) => {
const parts = [];
//
@ -498,10 +510,10 @@
}
return parts.join(" ");
};
};
//
const formatMessageTime = (timestamp) => {
//
const formatMessageTime = (timestamp) => {
if (!timestamp) return "";
const now = Date.now();
@ -540,10 +552,10 @@
//
return `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`;
};
};
//
const handleClickConversation = (conversation) => {
//
const handleClickConversation = (conversation) => {
console.log("点击会话:", conversation);
//
@ -557,12 +569,12 @@
//
uni.navigateTo({
url: `/pages/message/index?conversationID=${conversation.conversationID}&groupID=${conversation.groupID}`,
url: `/pages/message/index?conversationID=${encodeURIComponent(conversation.conversationID)}&groupID=${encodeURIComponent(conversation.groupID)}`,
});
};
};
//
const handleLoadMore = () => {
//
const handleLoadMore = () => {
if (loadingMore.value || !hasMore.value) return;
loadingMore.value = true;
@ -570,25 +582,25 @@
setTimeout(() => {
loadingMore.value = false;
}, 1000);
};
};
//
const handleRefresh = async () => {
//
const handleRefresh = async () => {
refreshing.value = true;
try {
await loadConversationList();
} finally {
refreshing.value = false;
}
};
};
//
onLoad(() => {
//
onLoad(() => {
console.log("消息列表页面加载");
});
});
//
onShow(async () => {
//
onShow(async () => {
try {
//
await getTeams();
@ -612,10 +624,10 @@
icon: "none",
});
}
});
});
//
onHide(() => {
//
onHide(() => {
//
if (updateTimer) {
clearTimeout(updateTimer);
@ -627,49 +639,49 @@
globalTimChatManager.setCallback("onConversationListUpdated", null);
globalTimChatManager.setCallback("onMessageReceived", null);
}
});
});
</script>
<style scoped lang="scss">
.message-page {
.message-page {
width: 100%;
height: 100vh;
background-color: #f5f5f5;
display: flex;
flex-direction: column;
}
}
.message-list {
.message-list {
width: 100%;
flex: 1;
}
}
.loading-container,
.empty-container {
.loading-container,
.empty-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
}
.loading-text {
.loading-text {
font-size: 28rpx;
color: #999;
}
}
.empty-image {
.empty-image {
width: 200rpx;
height: 200rpx;
margin-bottom: 20rpx;
}
}
.empty-text {
.empty-text {
font-size: 28rpx;
color: #999;
}
}
.message-item {
.message-item {
display: flex;
align-items: center;
padding: 24rpx 32rpx;
@ -679,21 +691,21 @@
&:active {
background-color: #f5f5f5;
}
}
}
.avatar-container {
.avatar-container {
position: relative;
margin-right: 24rpx;
flex-shrink: 0;
}
}
.avatar {
.avatar {
width: 96rpx;
height: 96rpx;
border-radius: 8rpx;
}
}
.unread-badge {
.unread-badge {
position: absolute;
top: -8rpx;
right: -8rpx;
@ -705,37 +717,37 @@
display: flex;
align-items: center;
justify-content: center;
}
}
.unread-text {
.unread-text {
font-size: 20rpx;
color: #fff;
line-height: 1;
}
}
.content {
.content {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
min-width: 0;
}
}
.header {
.header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8rpx;
}
}
.name-info {
.name-info {
display: flex;
align-items: center;
flex: 1;
min-width: 0;
}
}
.name {
.name {
font-size: 30rpx;
font-weight: 500;
color: #333;
@ -743,42 +755,42 @@
text-overflow: ellipsis;
white-space: nowrap;
flex-shrink: 1;
}
}
.patient-info {
.patient-info {
font-size: 26rpx;
padding-left: 12rpx;
color: #999;
flex-shrink: 0;
}
}
.time {
.time {
font-size: 24rpx;
color: #999;
margin-left: 16rpx;
flex-shrink: 0;
}
}
.message-preview {
.message-preview {
display: flex;
align-items: center;
}
}
.preview-text {
.preview-text {
font-size: 26rpx;
color: #999;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.load-more {
.load-more {
padding: 20rpx 0;
text-align: center;
}
}
.load-more-text {
.load-more-text {
font-size: 24rpx;
color: #999;
}
}
</style>

View File

@ -17,7 +17,8 @@
加入我的团队协同开展患者管理服务
</view>
<view class="mt-10 flex px-15 leading-normal text-center">
<button class="mr-10 border-auto rounded py-5 text-base text-primary flex-grow" @click="saveImage('save')">
<button class="mr-10 border-auto rounded py-5 text-base text-primary flex-grow"
@click="saveImage('save')">
保存图片
</button>
<button class="bg-primary rounded py-5 text-base text-white flex-grow" open-type="share">分享微信</button>
@ -29,39 +30,61 @@
</view>
</template>
<script setup>
import { computed, ref } from "vue";
import { storeToRefs } from "pinia";
import { onLoad, onShareAppMessage } from "@dcloudio/uni-app";
import useGuard from "@/hooks/useGuard.js";
import useAccountStore from "@/store/account.js";
import api from '@/utils/api';
import { toast } from "@/utils/widget";
import { getInviteMatePoster } from './base-poster-data';
import {
computed,
ref
} from "vue";
import {
storeToRefs
} from "pinia";
import {
onLoad,
onShareAppMessage
} from "@dcloudio/uni-app";
import useGuard from "@/hooks/useGuard.js";
import useAccountStore from "@/store/account.js";
import api from '@/utils/api';
import {
toast
} from "@/utils/widget";
import {
getInviteMatePoster
} from './base-poster-data';
const env = __VITE_ENV__;
const inviteQrcode = env.MP_INVITE_TEAMMATE_QRCODE;
const env = __VITE_ENV__;
const inviteQrcode = env.MP_INVITE_TEAMMATE_QRCODE;
const options = { margin: 10 };
const team = ref(null);
const teamId = ref('');
const painterRef = ref()
const poster = ref({})
const options = {
margin: 10
};
const team = ref(null);
const teamId = ref('');
const painterRef = ref()
const poster = ref({})
const { useLoad, useShow } = useGuard();
const { account } = storeToRefs(useAccountStore());
const {
useLoad,
useShow
} = useGuard();
const {
account
} = storeToRefs(useAccountStore());
const qrcode = computed(() => `${inviteQrcode}?type=inviteTeam&teamId=${teamId.value}`)
const qrcode = computed(() => `${inviteQrcode}?type=inviteTeam&teamId=${teamId.value}`)
async function getTeam() {
const res = await api('getTeamData', { teamId: teamId.value, corpId: account.value.corpId });
async function getTeam() {
const res = await api('getTeamData', {
teamId: teamId.value,
corpId: account.value.corpId
});
if (res && res.data) {
team.value = res.data;
} else {
toast(res?.message || '获取团队信息失败')
}
}
}
async function saveImage(action = 'save') {
async function saveImage(action = 'save') {
const data = getInviteMatePoster(team.value.name, qrcode.value)
try {
await painterRef.value.render(data);
@ -75,7 +98,7 @@ async function saveImage(action = 'save') {
if (action === 'save') {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function () {
success: function() {
console.log('save success');
}
});
@ -90,29 +113,29 @@ async function saveImage(action = 'save') {
} catch (e) {
toast(e?.message)
}
}
useLoad(options => {
}
useLoad(options => {
teamId.value = options.teamId;
})
})
useShow(() => {
useShow(() => {
getTeam()
});
});
onShareAppMessage(() => {
onShareAppMessage(() => {
return {
title: '邀请团队成员',
path: `pages/login/redirect-page?type=inviteTeam&teamId=${teamId.value}`
}
})
})
</script>
<style>
.canvas-box {
.canvas-box {
top: 10000rpx;
position: absolute;
z-index: -1;
width: 0;
height: 0;
overflow: hidden;
}
}
</style>

View File

@ -41,6 +41,7 @@ export default defineStore("accountStore", () => {
async function loginByCode(phoneCode = '') {
try {
const { code } = await uni.login({
appid,
provider: "weixin",
@ -61,13 +62,12 @@ export default defineStore("accountStore", () => {
}
account.value = res.data;
openid.value = res.data.openid;
// 持久化账户信息
cache.set(CACHE_KEYS.ACCOUNT, res.data);
cache.set(CACHE_KEYS.OPENID, res.data.openid);
// 登录成功后初始化腾讯IM
await getDoctorInfo(openid.value);
await getDoctorInfo({ openid: openid.value });
await initIMAfterLogin();
return res.data
}
@ -109,8 +109,7 @@ export default defineStore("accountStore", () => {
async function initIMAfterLogin() {
if (isIMInitialized.value) return true;
if (!doctorInfo.value) {
console.error('医生信息未获取无法初始化IM');
return false;
await getDoctorInfo();
}
try {
const userID = doctorInfo.value.userid;

View File

@ -10,6 +10,8 @@ const urlsConfig = {
getTeamData: 'getTeamData',
getTeamBymember: 'getTeamBymember',
getCurrentTemplate: 'getCurrentTemplate',
getTemplateGroup: 'getTemplateGroup',
getTemplateListByTemptype: 'getTemplateListByTemptype',
wxAppLogin: 'wxAppLogin',
getDeptList: 'getRealDeptList',
getHospitalList: 'getRealHospital',

View File

@ -1,10 +1,39 @@
const env = __VITE_ENV__;
function joinBaseAndPath(base, path) {
const b = String(base || '').replace(/\/+$/, '');
const p = String(path || '');
if (!p) return b;
if (/^https?:\/\//i.test(p)) return p;
return `${b}/${p.replace(/^\/+/, '')}`;
}
// 兼容历史数据:某些链接缺少域名后的 /
export function normalizeFileUrl(url) {
const u = String(url || '').trim();
if (!u) return '';
if (/^https?:\/\//i.test(u)) {
const afterProtocolIndex = u.indexOf('://') + 3;
const firstSlashIndex = u.indexOf('/', afterProtocolIndex);
if (firstSlashIndex > 0) {
const prefix = u.slice(0, afterProtocolIndex);
const host = u.slice(afterProtocolIndex, firstSlashIndex);
const path = u.slice(firstSlashIndex);
if (host.toLowerCase().endsWith('uploads') && !path.toLowerCase().startsWith('/uploads/')) {
const fixedHost = host.slice(0, -'uploads'.length);
const normalizedPath = `/uploads${path.startsWith('/') ? '' : '/'}${path.replace(/^\/+/, '')}`;
return `${prefix}${fixedHost}${normalizedPath}`;
}
}
}
return u.replace(/^(https?:\/\/[^/]+)(uploads\/)/i, '$1/$2');
}
export async function uploadFile(tempFilePath) {
try {
const res = await new Promise((resolve, reject) => {
uni.uploadFile({
url: `${env.MP_API_BASE_URL}/upload`,
url: joinBaseAndPath(env.MP_API_BASE_URL, 'upload'),
filePath: tempFilePath,
name: 'file',
success: (resp) => resolve(resp),
@ -14,7 +43,7 @@ export async function uploadFile(tempFilePath) {
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
if (data && data.success && data.filePath) {
return `${env.MP_API_BASE_URL}${data.filePath}`;
return normalizeFileUrl(joinBaseAndPath(env.MP_API_BASE_URL, data.filePath));
}
} catch (e) {
console.log('upload file error:', e);
@ -58,5 +87,3 @@ export async function chooseAndUploadImage(options = {}) {
return null;
}
}

View File

@ -283,7 +283,6 @@ function generateSendLink(survey, answerId, customerId, customerName, sendSurvey
const { corpId, userId } = context;
const isSystem = survey.createBy === 'system';
let url = '';
debugger
if (isSystem) {
// 系统问卷:使用 VITE_SURVEY_URL
url = `${env?.MP_SURVEY_URL}?corpId=${corpId}&surveryId=${survey.surveryId}&memberId=${customerId}&sendSurveyId=${sendSurveyId}&userId=${userId}`;
@ -359,6 +358,7 @@ export async function handleFollowUpMessages(messages, context = {}) {
corpId: context.corpId,
});
} else if (msg.type === 'questionnaire') {
success = await sendSurveyMessage(msg.content, {
userId: context.userId,
customerId: context.customerId,

View File

@ -1030,6 +1030,13 @@ class TimChatManager {
// 获取群聊列表
getGroupList() {
return new Promise((resolve, reject) => {
// 检查userId是否存在不存在则不需要初始化
if (!this.currentUserID) {
console.error('currentUserID不存在无法获取群聊列表')
reject(new Error('用户ID不存在'))
return
}
// 如果 TIM 实例不存在,等待初始化
if (!this.tim) {
console.log('TIM实例不存在等待初始化...')
@ -1071,12 +1078,13 @@ class TimChatManager {
if (timeoutHandle) clearTimeout(timeoutHandle)
this.getGroupListInternal().then(resolve).catch(reject)
} else if (waitTime >= maxWaitTime) {
console.error('等待SDK就绪超时')
console.error('等待SDK就绪超时当前isLoggedIn:', this.isLoggedIn)
if (timeoutHandle) clearTimeout(timeoutHandle)
// 超时时返回错误而不是继续等待
reject(new Error('SDK初始化超时请检查网络连接'))
} else {
waitTime += checkInterval
console.log(`等待SDK就绪... (${Math.floor(waitTime / 1000)}/${Math.floor(maxWaitTime / 1000)})`)
console.log(`等待SDK就绪... (${Math.floor(waitTime / 1000)}/${Math.floor(maxWaitTime / 1000)}, isLoggedIn: ${this.isLoggedIn})`)
timeoutHandle = setTimeout(checkSDKReady, checkInterval)
}
}
@ -2753,6 +2761,7 @@ class TimChatManager {
// 标记会话为已读
markConversationAsRead(conversationID) {
if (!this.tim || !this.isLoggedIn) {
console.log('⚠️ TIM未初始化或未登录无法标记会话已读');
return;
@ -2772,6 +2781,7 @@ class TimChatManager {
}
}
// 更新会话列表
updateConversationListOnNewMessage(message) {
try {