ykt-wxapp/components/archive-detail/service-info-tab.vue

644 lines
17 KiB
Vue
Raw Normal View History

2026-01-22 15:54:15 +08:00
<template>
<!-- Mobile 来源: ykt-management-mobile/src/pages/customer/customer-detail/service-info/service-info.vue -->
<view class="wrap">
<view class="filters">
2026-01-27 16:46:36 +08:00
<picker class="filter-item" mode="selector" :range="typeList" range-key="label" @change="pickType">
2026-01-22 15:54:15 +08:00
<view class="filter-pill">
<view class="pill-text" :class="{ muted: currentType.value === 'ALL' }">{{ currentType.value === 'ALL' ? '服务类型' : currentType.label }}</view>
<uni-icons type="arrowdown" size="12" color="#666" />
</view>
</picker>
2026-01-27 16:46:36 +08:00
<uni-datetime-picker class="filter-item wide-item" v-model="dateRange" type="daterange" rangeSeparator="-" @change="changeDates">
2026-01-22 15:54:15 +08:00
<view class="filter-pill wide">
<view class="pill-text" :class="{ muted: !dateRange.length }">
{{ dateRange.length ? dateRange.join('~') : '服务时间' }}
</view>
<view class="pill-icon" @click.stop="clearDates">
<uni-icons v-if="dateRange.length" type="closeempty" size="14" color="#666" />
<uni-icons v-else type="arrowdown" size="12" color="#666" />
</view>
</view>
</uni-datetime-picker>
2026-01-27 16:46:36 +08:00
<picker class="filter-item" mode="selector" :range="teamList" range-key="label" @change="pickTeam">
2026-01-22 15:54:15 +08:00
<view class="filter-pill">
<view class="pill-text">{{ currentTeam.label }}</view>
<uni-icons type="arrowdown" size="12" color="#666" />
</view>
</picker>
</view>
<view class="timeline">
<view v-for="(i, idx) in list" :key="i._id" class="cell" @click="toggleExpand(i)">
<view class="head">
<view class="dot"></view>
<view class="time">{{ i.timeStr }}</view>
<view v-if="i.hasFile" class="file-link" @click.stop="viewFile(i)">
{{ i.fileType === 'article' ? '查看文章' : '查看问卷' }}
</view>
</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>
<view class="body">
<view class="content" :class="{ clamp: !expandMap[i._id] }">
2026-01-27 17:38:40 +08:00
{{ displayTaskContent(i) || '暂无内容' }}
2026-01-22 15:54:15 +08:00
</view>
<image class="pen" src="/static/icons/icon-pen.svg" @click.stop="edit(i)" />
</view>
<view v-if="idx < list.length - 1" class="line"></view>
</view>
<view v-if="list.length === 0" class="empty">暂无数据</view>
<uni-load-more
v-if="list.length"
:status="moreStatus"
:contentText="loadMoreText"
@clickLoadMore="getMore"
/>
</view>
<view class="fab" :style="{ bottom: `${floatingBottom}px` }" @click="add">
<uni-icons type="plusempty" size="24" color="#fff" />
</view>
<uni-popup ref="filePopupRef" type="bottom" :mask-click="true">
<view class="popup">
<view class="popup-title">
<view class="popup-title-text">{{ fileTitle }}</view>
<view class="popup-close" @click="closeFilePopup">
<uni-icons type="closeempty" size="18" color="#666" />
</view>
</view>
<view class="popup-body2">
<view class="desc">{{ fileDesc }}</view>
<button class="btn primary" @click="copyFile">{{ fileAction }}</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script setup>
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
import dayjs from 'dayjs';
2026-01-26 16:47:35 +08:00
import { storeToRefs } from 'pinia';
import api from '@/utils/api';
import useAccountStore from '@/store/account';
import { toast } from '@/utils/widget';
import { getServiceTypeLabel, getServiceTypeOptions } from '@/utils/service-type-const';
2026-01-22 15:54:15 +08:00
const props = defineProps({
data: { type: Object, default: () => ({}) },
archiveId: { type: String, default: '' },
reachBottomTime: { type: [String, Number], default: '' },
floatingBottom: { type: Number, default: 16 },
});
2026-01-26 16:47:35 +08:00
const typeList = [{ label: '全部', value: 'ALL' }, ...getServiceTypeOptions({ excludeCustomerUpdate: true })];
const teamList = ref([{ label: '全部', value: 'ALL' }]);
2026-01-22 15:54:15 +08:00
const currentType = ref(typeList[0]);
2026-01-26 16:47:35 +08:00
const currentTeam = ref(teamList.value[0]);
2026-01-22 15:54:15 +08:00
const dateRange = ref([]);
const page = ref(1);
const pageSize = 10;
const pages = ref(1);
const loading = ref(false);
const list = ref([]);
const expandMap = ref({});
2026-01-26 16:47:35 +08:00
const userNameMap = ref({});
const accountStore = useAccountStore();
const { account, doctorInfo } = storeToRefs(accountStore);
const { getDoctorInfo } = accountStore;
async function ensureDoctor() {
if (doctorInfo.value) return;
if (!account.value?.openid) return;
try {
await getDoctorInfo();
} catch {
// ignore
}
}
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 t = uni.getStorageSync('ykt_case_current_team') || {};
const a = account.value || {};
const d = doctorInfo.value || {};
return String(t.corpId || a.corpId || d.corpId || '') || '';
}
function getCurrentTeamId() {
const t = uni.getStorageSync('ykt_case_current_team') || {};
return String(t.teamId || '') || '';
}
function resolveUserName(userId) {
const id = String(userId || '');
if (!id) return '';
const map = userNameMap.value || {};
return String(map[id] || '') || id;
}
2026-01-27 17:38:40 +08:00
function escapeRegExp(str) {
return String(str).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function replaceKnownUserIds(text) {
const map = userNameMap.value || {};
const ids = Object.keys(map);
if (!ids.length) return text;
let out = text;
ids.forEach((id) => {
const name = String(map[id] || '');
if (!id || !name || name === id) return;
const re = new RegExp(`(^|[^0-9A-Za-z_])(${escapeRegExp(id)})(?=[^0-9A-Za-z_]|$)`, 'g');
out = out.replace(re, (_, p1) => `${p1}${name}`);
});
return out;
}
2026-01-26 16:47:35 +08:00
function formatTaskContent(text) {
if (typeof text !== 'string') return '';
2026-01-27 17:38:40 +08:00
const withPlaceholders = text.replace(/&&&([^&]+)&&&/g, (_, id) => resolveUserName(id));
return replaceKnownUserIds(withPlaceholders).trim();
}
function displayTaskContent(r) {
return formatTaskContent(String(r?.taskContent || ''));
2026-01-26 16:47:35 +08:00
}
async function loadTeamMembers(teamId) {
const tid = String(teamId || '') || '';
if (!tid) return;
await ensureDoctor();
const corpId = getCorpId();
if (!corpId) return;
const res = await api('getTeamData', { corpId, teamId: tid });
if (!res?.success) return;
const t = res?.data && typeof res.data === 'object' ? res.data : {};
const members = Array.isArray(t.memberList) ? t.memberList : [];
const map = members.reduce((acc, m) => {
const uid = String(m?.userid || '');
if (!uid) return acc;
acc[uid] = String(m?.anotherName || m?.name || m?.userid || '') || uid;
return acc;
}, {});
userNameMap.value = { ...(userNameMap.value || {}), ...map };
}
2026-01-22 15:54:15 +08:00
const moreStatus = computed(() => {
if (loading.value) return 'loading';
return page.value <= pages.value ? 'more' : 'no-more';
});
const loadMoreText = {
contentdown: '点击加载更多',
contentrefresh: '加载中...',
contentnomore: '没有更多了',
};
function mapRow(i) {
const hasFile = Boolean(i.pannedEventSendFile);
const fileType = i.pannedEventSendFile?.type === 'article' ? 'article' : i.pannedEventSendFile?.type === 'questionnaire' ? 'questionnaire' : '';
return {
...i,
2026-01-26 16:47:35 +08:00
_id: String(i?._id || i?.id || ''),
2026-01-22 15:54:15 +08:00
hasFile,
fileType,
timeStr: i.executionTime ? dayjs(i.executionTime).format('YYYY-MM-DD HH:mm') : '--',
2026-01-26 16:47:35 +08:00
typeStr: getServiceTypeLabel(i.eventType),
2026-01-22 15:54:15 +08:00
};
}
function reset() {
page.value = 1;
pages.value = 1;
list.value = [];
getMore();
}
2026-01-26 16:47:35 +08:00
function getEventTypeList() {
const v = currentType.value?.value || 'ALL';
if (v === 'ALL') return typeList.filter((i) => i.value !== 'ALL').map((i) => i.value);
return [v];
}
async function getMore() {
2026-01-22 15:54:15 +08:00
if (!props.archiveId) return;
if (loading.value) return;
if (page.value > pages.value) return;
loading.value = true;
try {
2026-01-26 16:47:35 +08:00
await ensureDoctor();
const corpId = getCorpId();
if (!corpId) {
toast('缺少 corpId请先完成登录/团队选择');
return;
}
const params = {
corpId,
customerId: String(props.archiveId),
eventTypeList: getEventTypeList(),
};
if (dateRange.value.length) params.executionTime = dateRange.value;
const teamId = currentTeam.value?.value && currentTeam.value.value !== 'ALL' ? currentTeam.value.value : '';
const res = await api('getServiceRecord', {
2026-01-22 15:54:15 +08:00
page: page.value,
pageSize,
2026-01-26 16:47:35 +08:00
params,
queryType: '',
teamId,
2026-01-22 15:54:15 +08:00
});
2026-01-26 16:47:35 +08:00
if (!res?.success) {
toast(res?.message || '获取服务记录失败');
return;
}
const payload = res?.data;
const arr = Array.isArray(payload?.data) ? payload.data : Array.isArray(payload) ? payload : [];
const p =
typeof payload?.pages === 'number'
? payload.pages
: typeof payload?.total === 'number'
? Math.ceil(payload.total / pageSize) || 0
: typeof res?.total === 'number'
? Math.ceil(res.total / pageSize) || 0
: arr.length < pageSize
? page.value
: page.value + 1;
2026-01-22 15:54:15 +08:00
pages.value = p;
2026-01-26 16:47:35 +08:00
const mapped = arr.map(mapRow).filter((i) => i && i._id);
2026-01-22 15:54:15 +08:00
list.value = page.value === 1 ? mapped : [...list.value, ...mapped];
page.value += 1;
} finally {
loading.value = false;
}
}
function toggleExpand(r) {
expandMap.value[r._id] = !expandMap.value[r._id];
}
function pickType(e) {
currentType.value = typeList[e.detail.value] || typeList[0];
reset();
}
function pickTeam(e) {
2026-01-26 16:47:35 +08:00
currentTeam.value = teamList.value[e.detail.value] || teamList.value[0];
const tid = currentTeam.value?.value && currentTeam.value.value !== 'ALL' ? currentTeam.value.value : getCurrentTeamId();
loadTeamMembers(tid);
2026-01-22 15:54:15 +08:00
reset();
}
function changeDates() {
reset();
}
function clearDates() {
if (!dateRange.value.length) return;
dateRange.value = [];
reset();
}
function add() {
2026-01-26 16:47:35 +08:00
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,
eventType: '',
});
2026-01-22 15:54:15 +08:00
uni.navigateTo({ url: `/pages/case/service-record-detail?archiveId=${encodeURIComponent(props.archiveId)}&mode=add` });
}
function edit(record) {
2026-01-26 16:47:35 +08:00
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,
});
2026-01-22 15:54:15 +08:00
uni.navigateTo({ url: `/pages/case/service-record-detail?archiveId=${encodeURIComponent(props.archiveId)}&mode=edit&id=${encodeURIComponent(record._id)}` });
}
const filePopupRef = ref(null);
const fileTitle = ref('');
const fileDesc = ref('');
const fileAction = ref('');
const fileCopyText = ref('');
function viewFile(record) {
if (!record.hasFile) return;
if (record.fileType === 'article') {
fileTitle.value = '查看文章';
fileDesc.value = record.pannedEventSendFile?.url || '';
fileAction.value = '复制链接';
fileCopyText.value = record.pannedEventSendFile?.url || '';
} else {
fileTitle.value = '查看问卷';
fileDesc.value = `问卷ID: ${record.pannedEventSendFile?.surveryId || '--'}`;
fileAction.value = '复制问卷ID';
fileCopyText.value = record.pannedEventSendFile?.surveryId || '';
}
filePopupRef.value?.open?.();
}
function closeFilePopup() {
filePopupRef.value?.close?.();
}
function copyFile() {
if (!fileCopyText.value) return;
uni.setClipboardData({
data: fileCopyText.value,
success: () => uni.showToast({ title: '已复制', icon: 'success' }),
});
closeFilePopup();
}
2026-01-26 16:47:35 +08:00
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 : [];
const normalized = 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 || !name) return null;
return { label: String(name), value: String(teamId) };
})
.filter(Boolean);
teamList.value = [{ label: '全部', value: 'ALL' }, ...normalized];
currentTeam.value = teamList.value.find((i) => i.value === currentTeam.value?.value) || teamList.value[0];
}
2026-01-22 15:54:15 +08:00
onMounted(() => {
2026-01-26 16:47:35 +08:00
loadTeams();
loadTeamMembers(getCurrentTeamId());
2026-01-22 15:54:15 +08:00
reset();
uni.$on('archive-detail:service-record-changed', reset);
});
onUnmounted(() => {
uni.$off('archive-detail:service-record-changed', reset);
});
watch(
() => props.reachBottomTime,
() => getMore()
);
</script>
<style scoped>
.wrap {
2026-01-26 16:47:35 +08:00
padding: 8px 0 96px;
2026-01-22 15:54:15 +08:00
}
.filters {
2026-01-27 16:46:36 +08:00
padding: 10px 14px;
background: #fff;
border-bottom: 1px solid #f0f0f0;
2026-01-22 15:54:15 +08:00
display: flex;
align-items: center;
2026-01-27 16:46:36 +08:00
gap: 12px;
2026-01-26 16:47:35 +08:00
}
2026-01-27 16:46:36 +08:00
.filter-item {
2026-01-26 16:47:35 +08:00
display: block;
flex: 1;
min-width: 0;
2026-01-22 15:54:15 +08:00
}
2026-01-27 16:46:36 +08:00
.filter-item.wide-item {
flex: 1.4;
}
/* Removed old deep selectors */
2026-01-22 15:54:15 +08:00
.filter-pill {
2026-01-27 16:46:36 +08:00
background: #f7f8fa;
border: 1px solid #e5e7eb;
border-radius: 6px;
padding: 10px 12px;
2026-01-22 15:54:15 +08:00
display: flex;
align-items: center;
2026-01-27 16:46:36 +08:00
gap: 8px;
2026-01-26 16:47:35 +08:00
width: 100%;
min-width: 0;
2026-01-27 16:46:36 +08:00
box-sizing: border-box; /* Ensure padding doesn't overflow width */
2026-01-22 15:54:15 +08:00
}
.pill-text {
font-size: 13px;
color: #333;
2026-01-26 16:47:35 +08:00
flex: 1;
min-width: 0;
2026-01-22 15:54:15 +08:00
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
2026-01-27 16:46:36 +08:00
font-weight: 500;
2026-01-26 16:47:35 +08:00
}
2026-01-22 15:54:15 +08:00
.pill-text.muted {
color: #999;
2026-01-27 16:46:36 +08:00
font-weight: 400;
2026-01-22 15:54:15 +08:00
}
.pill-icon {
2026-01-27 16:46:36 +08:00
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
}
.filter-pill :deep(uni-icons) {
flex-shrink: 0;
2026-01-22 15:54:15 +08:00
}
.timeline {
background: #fff;
2026-01-26 16:47:35 +08:00
margin-top: 6px;
padding: 10px 0 70px;
2026-01-22 15:54:15 +08:00
}
.cell {
padding: 0 14px;
position: relative;
}
.head {
position: relative;
display: flex;
align-items: center;
justify-content: space-between;
height: 44px;
padding-left: 18px;
}
.dot {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
width: 8px;
height: 8px;
border-radius: 50%;
background: #4f6ef7;
}
.time {
font-size: 14px;
font-weight: 600;
color: #1f1f1f;
}
.file-link {
font-size: 13px;
color: #4f6ef7;
}
.meta {
display: flex;
align-items: center;
gap: 10px;
padding-left: 18px;
margin-bottom: 6px;
}
.tag {
font-size: 12px;
color: #4f6ef7;
border: 1px solid #4f6ef7;
border-radius: 999px;
padding: 4px 8px;
}
.meta-text {
font-size: 13px;
color: #333;
}
.truncate {
max-width: 160px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.body {
display: flex;
align-items: flex-start;
justify-content: space-between;
padding-left: 18px;
padding-bottom: 12px;
}
.content {
flex: 1;
font-size: 13px;
color: #666;
line-height: 18px;
margin-right: 10px;
}
.content.clamp {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
.pen {
width: 18px;
height: 18px;
margin-top: 2px;
}
.line {
position: absolute;
left: 18px;
top: 34px;
bottom: 0;
width: 2px;
background: #4f6ef7;
opacity: 0.6;
}
.empty {
padding: 120px 0;
text-align: center;
color: #9aa0a6;
font-size: 13px;
}
.fab {
position: fixed;
right: 16px;
width: 52px;
height: 52px;
border-radius: 26px;
background: #4f6ef7;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 10px 18px rgba(79, 110, 247, 0.35);
z-index: 20;
}
.popup {
background: #fff;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
overflow: hidden;
}
.popup-title {
position: relative;
padding: 14px;
border-bottom: 1px solid #f0f0f0;
}
.popup-title-text {
text-align: center;
font-size: 16px;
font-weight: 600;
color: #333;
}
.popup-close {
position: absolute;
right: 12px;
top: 0;
height: 100%;
display: flex;
align-items: center;
}
.popup-body2 {
padding: 14px;
}
.desc {
font-size: 14px;
color: #333;
line-height: 20px;
word-break: break-all;
margin-bottom: 14px;
}
.btn {
width: 100%;
height: 44px;
line-height: 44px;
border-radius: 6px;
font-size: 15px;
}
.btn::after {
border: none;
}
.btn.primary {
background: #4f6ef7;
color: #fff;
}
</style>