ykt-wxapp/pages/case/components/archive-detail/customer-profile-tab.vue

558 lines
16 KiB
Vue
Raw Normal View History

2026-01-22 15:54:15 +08:00
<template>
<!-- Mobile 来源: ykt-management-mobile/src/pages/customer/customer-detail/customer-profile.vue -->
<view class="wrap">
<view class="card">
<view id="anchor-base" class="section-title" @click="startEdit">
<text>基本信息</text>
<image class="pen" src="/static/icons/icon-pen.svg" />
</view>
<view class="rows">
<form-template
v-if="editing && effectiveBaseItems.length"
ref="baseFormRef"
:items="effectiveBaseItems"
:form="forms"
@change="onChange"
/>
<template v-else>
<view
v-for="item in effectiveBaseItems"
:key="item.title"
class="row"
>
<view class="label">{{ item.name || item.title }}</view>
<view
v-if="item.title === 'mobile' && displayValue(item) !== '-'"
class="val link"
@click="call(rawValue(item))"
>
{{ displayValue(item) }}
</view>
<view v-else class="val" :class="displayValue(item) === '-' ? 'muted' : ''">{{ displayValue(item) }}</view>
</view>
</template>
2026-01-22 15:54:15 +08:00
</view>
</view>
<view class="card">
<view id="anchor-internal" class="section-title" @click="startEdit">
<text>内部信息</text>
<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 || '点击查看' }}
2026-02-02 15:15:51 +08:00
<uni-icons type="arrowright" size="14" color="#0877F1" />
2026-01-22 15:54:15 +08:00
</view>
</view>
<form-template
v-if="editing && effectiveInternalItems.length"
ref="internalFormRef"
:items="effectiveInternalItems"
:form="forms"
:filterRule="filterRule"
@change="onChange"
/>
<template v-else>
<view
v-for="item in effectiveInternalItems"
:key="item.title"
class="row"
>
<view class="label">{{ item.name || item.title }}</view>
<view class="val" :class="displayValue(item) === '-' ? 'muted' : ''">{{ displayValue(item) }}</view>
</view>
</template>
2026-01-22 15:54:15 +08:00
</view>
</view>
<view v-if="editing" class="bottom-bar" :style="{ bottom: `${floatingBottom}px` }">
<button class="btn plain" @click="cancel">取消</button>
<button class="btn primary" @click="save">保存</button>
</view>
<uni-popup ref="transferPopupRef" type="bottom" :mask-click="true">
<view class="popup">
<view class="popup-title">
<view class="popup-title-text">院内流转记录</view>
2026-01-22 15:54:15 +08:00
<view class="popup-close" @click="closeTransferRecord">
<uni-icons type="closeempty" size="18" color="#666" />
</view>
</view>
<scroll-view scroll-y class="popup-body">
<view v-if="transferRecords.length" class="timeline">
2026-01-22 15:54:15 +08:00
<view class="line"></view>
<view v-for="r in transferRecords" :key="r._id" class="item">
<view class="dot"></view>
<view class="content">
<view class="time">{{ r.createTime }}</view>
2026-01-22 15:54:15 +08:00
<view class="card2">
<view v-if="r.executeTeamName" class="trow"><text class="tlabel">转入团队:</text>{{ r.executeTeamName }}</view>
<view v-if="r.eventTypeName" class="trow"><text class="tlabel">转入方式:</text>{{ r.eventTypeName }}</view>
2026-01-30 10:45:36 +08:00
<view v-if="r.creatorUserName" class="trow">
<text class="tlabel">操作人:</text>
2026-01-30 10:45:36 +08:00
<text>{{ r.creatorUserName }}</text>
</view>
2026-01-22 15:54:15 +08:00
</view>
</view>
</view>
</view>
<view v-else class="empty-state">
<text class="empty-text">暂无流转记录</text>
</view>
2026-01-22 15:54:15 +08:00
</scroll-view>
</view>
</uni-popup>
</view>
</template>
<script setup>
import { computed, reactive, ref, watch, onMounted } from 'vue';
import { storeToRefs } from 'pinia';
2026-01-22 15:54:15 +08:00
import dayjs from 'dayjs';
import FormTemplate from '@/components/form-template/index.vue';
import api from '@/utils/api';
import useAccountStore from '@/store/account';
import useTeamStore from '@/store/team';
2026-01-22 15:54:15 +08:00
const props = defineProps({
data: { type: Object, default: () => ({}) },
baseItems: { type: Array, default: () => ([]) },
internalItems: { type: Array, default: () => ([]) },
2026-01-22 15:54:15 +08:00
floatingBottom: { type: Number, default: 16 },
});
const emit = defineEmits(['save']);
const accountStore = useAccountStore();
const teamStore = useTeamStore();
const { account, doctorInfo } = storeToRefs(accountStore);
const { teams } = storeToRefs(teamStore);
2026-01-22 15:54:15 +08:00
const editing = ref(false);
const baseFormRef = ref(null);
const internalFormRef = ref(null);
const patch = reactive({});
const forms = computed(() => ({ ...(props.data || {}), ...patch }));
const fallbackBaseItems = [
{ title: 'name', name: '姓名', type: 'input', operateType: 'formCell', required: true, wordLimit: 20 },
{ title: 'sex', name: '性别', type: 'select', operateType: 'formCell', required: false, range: ['男', '女'] },
{ title: 'age', name: '年龄', type: 'input', inputType: 'number', operateType: 'formCell', required: false, wordLimit: 3 },
{ title: 'mobile', name: '联系电话', type: 'input', inputType: 'number', operateType: 'formCell', required: false, wordLimit: 11 },
];
const fallbackInternalItems = [
{ title: 'notes', name: '备注', type: 'textarea', operateType: 'formCell', required: false, wordLimit: 200 },
];
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));
const filterRule = {
reference(formModel) {
const customerSource = Array.isArray(formModel.customerSource)
? formModel.customerSource
: typeof formModel.customerSource === 'string'
? [formModel.customerSource]
: [];
return ['同事推荐', '客户推荐'].includes(customerSource[0]) && customerSource.length === 1;
},
};
2026-01-22 15:54:15 +08:00
watch(
() => props.data,
() => {
if (!editing.value) Object.keys(patch).forEach((k) => delete patch[k]);
2026-01-22 15:54:15 +08:00
},
{ deep: true }
);
function normalizeChangeValue(value) {
if (value && typeof value === 'object' && 'value' in value) return value.value;
return value;
2026-01-22 15:54:15 +08:00
}
function startEdit() {
if (editing.value) return;
editing.value = true;
}
function cancel() {
editing.value = false;
Object.keys(patch).forEach((k) => delete patch[k]);
2026-01-22 15:54:15 +08:00
}
function save() {
if (baseFormRef.value?.verify && !baseFormRef.value.verify()) return;
if (internalFormRef.value?.verify && !internalFormRef.value.verify()) return;
const out = { ...patch };
emit('save', out);
2026-01-22 15:54:15 +08:00
editing.value = false;
Object.keys(patch).forEach((k) => delete patch[k]);
2026-01-22 15:54:15 +08:00
}
function onChange({ title, value }) {
patch[title] = normalizeChangeValue(value);
2026-01-22 15:54:15 +08:00
}
function call(mobile) {
if (!mobile) return;
uni.makePhoneCall({ phoneNumber: String(mobile) });
}
function rawValue(item) {
const title = item?.title;
if (!title) return '';
const v = forms.value?.[title];
return v === undefined || v === null ? '' : v;
}
function displayValue(item) {
const title = item?.title;
const type = item?.type;
if (!title) return '-';
const v = forms.value?.[title];
if (v === undefined || v === null || v === '') return '-';
if (type === 'files') {
const list = Array.isArray(v) ? v : typeof v === 'string' && v ? [v] : [];
return list.length ? `已上传${list.length}` : '-';
}
if (Array.isArray(v)) {
// 对于数组类型如标签查找range中的label
if (type === 'select' || type === 'radio' || type === 'selectAndImage' || type === 'tagPicker' || item.__originType === 'tag') {
const range = Array.isArray(item?.range) ? item.range : [];
if (range.length && typeof range[0] === 'object') {
const labels = v.map((val) => {
const found = range.find((i) => String(i?.value) === String(val));
return found ? String(found.label || found.value || val) : String(val);
}).filter(Boolean);
return labels.length ? labels.join('、') : '-';
}
}
return v.filter(Boolean).join('、') || '-';
}
if (typeof v === 'object') {
if ('label' in v) return String(v.label || '-');
if ('name' in v) return String(v.name || '-');
if ('value' in v) return String(v.value || '-');
return '-';
}
if (type === 'select' || type === 'radio' || type === 'selectAndImage') {
const range = Array.isArray(item?.range) ? item.range : [];
if (range.length && typeof range[0] === 'object') {
const found = range.find((i) => String(i?.value) === String(v));
if (found) return String(found.label || found.value || '-');
}
}
return String(v);
}
2026-01-22 15:54:15 +08:00
function scrollToAnchor(key) {
activeAnchor.value = key;
const selector = `#anchor-${key}`;
const query = uni.createSelectorQuery();
query.select(selector).boundingClientRect();
query.selectViewport().scrollOffset();
query.exec((res) => {
const rect = res[0];
const scroll = res[1];
if (!rect || !scroll) return;
uni.pageScrollTo({ scrollTop: rect.top + scroll.scrollTop - 60, duration: 200 });
});
}
const transferPopupRef = ref(null);
const transferRecords = ref([]);
const latestTransferRecord = computed(() => transferRecords.value[0]);
2026-01-30 10:45:36 +08:00
const userNameMap = ref({});
const CURRENT_TEAM_STORAGE_KEY = 'ykt_case_current_team';
function getCorpId() {
const d = doctorInfo.value || {};
const a = account.value || {};
const team = uni.getStorageSync(CURRENT_TEAM_STORAGE_KEY) || {};
return String(d.corpId || a.corpId || team.corpId || '') || '';
}
2026-01-22 15:54:15 +08:00
2026-01-30 10:45:36 +08:00
async function loadTeamMembers() {
const corpId = getCorpId();
const team = uni.getStorageSync(CURRENT_TEAM_STORAGE_KEY) || {};
const teamId = team?.teamId ? String(team.teamId) : '';
if (!corpId || !teamId) return;
if (Object.keys(userNameMap.value || {}).length > 0) return;
try {
const res = await api('getTeamData', { corpId, teamId });
if (!res?.success) return;
const t = res?.data && typeof res.data === 'object' ? res.data : {};
const members = Array.isArray(t.memberList) ? t.memberList : [];
userNameMap.value = 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;
}, {});
} catch (e) {
console.error('获取团队成员失败', e);
}
}
function resolveUserName(userId) {
const id = String(userId || '');
if (!id) return '';
const map = userNameMap.value || {};
return String(map[id] || id) || id;
}
const ServiceType = {
remindFiling: '自主开拓',
adminTransferTeams: '团队流转',
adminRemoveTeams: '移出团队',
systemAutoDistribute: '系统分配',
bindWechatCustomer: '绑定企业微信',
2026-01-30 10:45:36 +08:00
share: '共享',
transfer: '转移',
importCustomer: '导入客户',
addCustomer: '新增客户',
};
async function fetchTransferRecords() {
const customerId = props.data?._id;
if (!customerId) return;
2026-01-30 10:45:36 +08:00
// 先加载团队成员信息
await loadTeamMembers();
try {
const res = await api('customerTransferRecord', { customerId });
if (res?.success && res.list) {
const allTeams = Array.isArray(teams.value) ? teams.value : [];
transferRecords.value = res.list.map((item) => {
const record = { ...item };
record.createTime = dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss');
record.executeTeamName = allTeams.find((team) => team.teamId === item.executeTeamId)?.name || item.executeTeamName;
record.eventTypeName = ServiceType[item.eventType] || item.eventType;
2026-01-30 10:45:36 +08:00
record.creatorUserName = item.creatorUserId === 'system' ? '系统自动建档' : resolveUserName(item.creatorUserId);
if (item.transferToTeamIds && Array.isArray(item.transferToTeamIds)) {
record.teamName = item.transferToTeamIds.map((teamId) => allTeams.find((team) => team.teamId === teamId)?.name).join('、');
}
if (item.removeTeamIds && Array.isArray(item.removeTeamIds)) {
record.teamName = item.removeTeamIds.map((teamId) => allTeams.find((team) => team.teamId === teamId)?.name).join('、');
}
if (item.eventType === 'remindFiling') record.eventTypeName = '自主开拓';
return record;
});
}
} catch (e) {
console.error('获取流转记录失败', e);
}
}
async function openTransferRecord() {
await fetchTransferRecords();
2026-01-22 15:54:15 +08:00
transferPopupRef.value?.open?.();
}
function closeTransferRecord() {
transferPopupRef.value?.close?.();
}
onMounted(() => {
fetchTransferRecords();
});
watch(() => props.data?._id, () => {
if (props.data?._id) fetchTransferRecords();
});
2026-01-22 15:54:15 +08:00
</script>
<style scoped>
.wrap {
2026-01-30 10:45:36 +08:00
padding: 24rpx 0 192rpx;
2026-01-22 15:54:15 +08:00
}
.card {
background: #fff;
2026-01-30 10:45:36 +08:00
margin-top: 20rpx;
2026-01-22 15:54:15 +08:00
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
2026-01-30 10:45:36 +08:00
padding: 24rpx 28rpx;
font-size: 30rpx;
2026-01-22 15:54:15 +08:00
font-weight: 600;
color: #333;
2026-01-30 10:45:36 +08:00
border-bottom: 2rpx solid #f2f2f2;
2026-01-22 15:54:15 +08:00
}
.pen {
2026-01-30 10:45:36 +08:00
width: 36rpx;
height: 36rpx;
2026-01-22 15:54:15 +08:00
}
.rows {
2026-01-30 10:45:36 +08:00
padding: 4rpx 28rpx;
2026-01-22 15:54:15 +08:00
}
.row {
display: flex;
align-items: center;
2026-01-30 10:45:36 +08:00
padding: 24rpx 0;
border-bottom: 2rpx solid #f6f6f6;
2026-01-22 15:54:15 +08:00
}
.row:last-child {
border-bottom: none;
}
.label {
2026-01-30 10:45:36 +08:00
width: 180rpx;
font-size: 28rpx;
2026-01-22 15:54:15 +08:00
color: #666;
}
.val {
flex: 1;
text-align: right;
2026-01-30 10:45:36 +08:00
font-size: 28rpx;
2026-01-22 15:54:15 +08:00
color: #333;
}
.val.link {
2026-02-02 15:15:51 +08:00
color: #0877F1;
2026-01-22 15:54:15 +08:00
display: flex;
justify-content: flex-end;
align-items: center;
2026-01-30 10:45:36 +08:00
gap: 12rpx;
2026-01-22 15:54:15 +08:00
}
.input,
.picker {
flex: 1;
text-align: right;
2026-01-30 10:45:36 +08:00
font-size: 28rpx;
2026-01-22 15:54:15 +08:00
color: #333;
}
.bottom-bar {
position: fixed;
left: 0;
right: 0;
background: #fff;
2026-01-30 10:45:36 +08:00
padding: 24rpx 28rpx;
2026-01-22 15:54:15 +08:00
display: flex;
2026-01-30 10:45:36 +08:00
gap: 24rpx;
box-shadow: 0 -8rpx 24rpx rgba(0, 0, 0, 0.06);
2026-01-22 15:54:15 +08:00
z-index: 30;
}
.btn {
flex: 1;
2026-01-30 10:45:36 +08:00
height: 88rpx;
line-height: 88rpx;
border-radius: 12rpx;
font-size: 30rpx;
2026-01-22 15:54:15 +08:00
}
.btn::after {
border: none;
}
.btn.plain {
background: #fff;
2026-02-02 15:15:51 +08:00
color: #0877F1;
border: 2rpx solid #0877F1;
2026-01-22 15:54:15 +08:00
}
.btn.primary {
2026-02-02 15:15:51 +08:00
background: #0877F1;
2026-01-22 15:54:15 +08:00
color: #fff;
}
.popup {
background: #fff;
2026-01-30 10:45:36 +08:00
border-top-left-radius: 20rpx;
border-top-right-radius: 20rpx;
2026-01-22 15:54:15 +08:00
overflow: hidden;
}
.popup-title {
position: relative;
2026-01-30 10:45:36 +08:00
padding: 28rpx;
border-bottom: 2rpx solid #f0f0f0;
2026-01-22 15:54:15 +08:00
}
.popup-title-text {
text-align: center;
2026-01-30 10:45:36 +08:00
font-size: 32rpx;
2026-01-22 15:54:15 +08:00
font-weight: 600;
color: #333;
}
.popup-close {
position: absolute;
2026-01-30 10:45:36 +08:00
right: 24rpx;
2026-01-22 15:54:15 +08:00
top: 0;
height: 100%;
display: flex;
align-items: center;
}
.popup-body {
max-height: 70vh;
}
.timeline {
position: relative;
2026-01-30 10:45:36 +08:00
padding: 40rpx 28rpx 36rpx 28rpx;
2026-01-22 15:54:15 +08:00
}
.line {
position: absolute;
2026-01-30 10:45:36 +08:00
left: 48rpx;
top: 56rpx;
bottom: 36rpx;
width: 4rpx;
2026-02-02 15:15:51 +08:00
background: #0877F1;
2026-01-22 15:54:15 +08:00
}
.item {
position: relative;
2026-01-30 10:45:36 +08:00
padding-left: 80rpx;
margin-bottom: 40rpx;
}
.item:last-child {
margin-bottom: 0;
2026-01-22 15:54:15 +08:00
}
.dot {
position: absolute;
2026-01-30 10:45:36 +08:00
left: 6rpx;
top: 8rpx;
width: 24rpx;
height: 24rpx;
2026-01-22 15:54:15 +08:00
border-radius: 50%;
2026-02-02 15:15:51 +08:00
background: #0877F1;
2026-01-30 10:45:36 +08:00
border: 4rpx solid #fff;
2026-02-02 15:15:51 +08:00
box-shadow: 0 0 0 4rpx #0877F1;
2026-01-22 15:54:15 +08:00
}
.time {
2026-01-30 10:45:36 +08:00
font-size: 24rpx;
2026-01-22 15:54:15 +08:00
color: #999;
2026-01-30 10:45:36 +08:00
margin-bottom: 16rpx;
2026-01-22 15:54:15 +08:00
}
.card2 {
2026-01-30 10:45:36 +08:00
border: 2rpx solid #f0f0f0;
border-radius: 16rpx;
padding: 24rpx;
background: #fafafa;
2026-01-22 15:54:15 +08:00
}
.trow {
2026-01-30 10:45:36 +08:00
font-size: 28rpx;
2026-01-22 15:54:15 +08:00
color: #333;
2026-01-30 10:45:36 +08:00
line-height: 40rpx;
2026-01-22 15:54:15 +08:00
}
.tlabel {
color: #666;
2026-01-30 10:45:36 +08:00
margin-right: 12rpx;
2026-01-22 15:54:15 +08:00
}
.empty-state {
2026-01-30 10:45:36 +08:00
padding: 80rpx 40rpx;
text-align: center;
}
.empty-text {
2026-01-30 10:45:36 +08:00
font-size: 28rpx;
color: #999;
}
2026-01-22 15:54:15 +08:00
</style>