ykt-wxapp/pages/case/service-record-detail.vue

465 lines
12 KiB
Vue
Raw Normal View History

2026-02-02 15:15:51 +08:00
<template>
2026-01-22 15:54:15 +08:00
<view class="page">
<!-- Mobile 来源: ykt-management-mobile/src/pages/customer/service-record-detail/service-record-detail.vue -->
2026-02-06 18:04:34 +08:00
<view v-if="!recordId" class="body">
2026-02-11 17:45:09 +08:00
<scroll-view scroll-y class="scroll" :style="{ height: scrollHeight + 'px' }">
2026-01-22 15:54:15 +08:00
<view class="card">
<view class="section-title">执行日期</view>
2026-01-26 16:47:35 +08:00
<picker mode="date" @change="pickDate" :disabled="true">
2026-01-22 15:54:15 +08:00
<view class="picker-box">
<uni-icons type="calendar" size="18" color="#666" class="mr" />
<view class="picker-text" :class="{ muted: !date }">{{ date || '请选择服务日期' }}</view>
</view>
</picker>
<view class="section-title">执行时间</view>
2026-01-26 16:47:35 +08:00
<picker mode="time" @change="pickTime" :disabled="Boolean(recordId)">
2026-01-22 15:54:15 +08:00
<view class="picker-box">
<uni-icons type="calendar" size="18" color="#666" class="mr" />
<view class="picker-text" :class="{ muted: !time }">{{ time || '请选择执行时间' }}</view>
</view>
</picker>
<view class="section-title">服务类型</view>
<picker mode="selector" :range="typeOptions" range-key="label" @change="pickType" :disabled="Boolean(recordId)">
<view class="picker-box between">
2026-01-26 16:47:35 +08:00
<view class="picker-text" :class="{ muted: !currentType?.value }">
{{ currentType?.value ? currentType.label : '请选择服务类型' }}
2026-01-22 15:54:15 +08:00
</view>
<uni-icons type="arrowright" size="16" color="#999" />
</view>
</picker>
<view class="section-title">所属团队</view>
2026-02-06 18:04:34 +08:00
<picker mode="selector" :range="teamOptions" range-key="label" :disabled="true">
<view class="picker-box">
2026-01-26 16:47:35 +08:00
<view class="picker-text" :class="{ muted: !currentTeam?.value }">
{{ currentTeam?.value ? currentTeam.label : '请选择所属团队' }}
2026-01-22 15:54:15 +08:00
</view>
</view>
</picker>
<view class="section-title">服务内容</view>
<view class="textarea-box">
<textarea v-model="form.taskContent" class="textarea tall" maxlength="1000" placeholder="请输入服务小结内容" />
<view class="counter">{{ (form.taskContent || '').length }}/1000</view>
</view>
</view>
<view style="height: 120px;"></view>
</scroll-view>
<view class="footer">
<button class="btn plain" @click="cancel">取消</button>
<button class="btn primary" @click="save">保存</button>
</view>
</view>
2026-02-06 18:04:34 +08:00
<!-- 编辑仅支持修改服务内容底部弹层 -->
<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>
2026-01-22 15:54:15 +08:00
</view>
</template>
<script setup>
2026-02-06 18:04:34 +08:00
import { nextTick, reactive, ref } from 'vue';
2026-01-22 15:54:15 +08:00
import { onLoad } from '@dcloudio/uni-app';
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 { getServiceTypeOptions } from '@/utils/service-type-const';
2026-01-22 15:54:15 +08:00
2026-02-11 17:45:09 +08:00
const scrollHeight = ref(0);
2026-01-22 15:54:15 +08:00
const archiveId = ref('');
const mode = ref('add');
const recordId = ref('');
2026-01-26 16:47:35 +08:00
const typeOptions = getServiceTypeOptions({ excludeCustomerUpdate: true });
const currentType = ref(null);
2026-01-22 15:54:15 +08:00
2026-01-26 16:47:35 +08:00
const teamOptions = ref([]);
const currentTeam = ref(null);
2026-01-22 15:54:15 +08:00
const date = ref('');
const time = ref('');
const form = reactive({
taskContent: '',
});
2026-01-26 16:47:35 +08:00
const customerId = ref('');
const customerName = ref('');
const customerUserId = 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 || {};
2026-02-06 18:04:34 +08:00
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 || '') || '';
2026-01-26 16:47:35 +08:00
}
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 getCurrentTeam() {
const t = uni.getStorageSync('ykt_case_current_team') || {};
const teamId = String(t.teamId || '') || '';
const name = String(t.name || t.teamName || '') || '';
return teamId ? { value: teamId, label: name || teamId } : null;
}
2026-01-22 15:54:15 +08:00
onLoad((options) => {
2026-02-11 17:45:09 +08:00
try {
const { windowHeight } = uni.getSystemInfoSync();
scrollHeight.value = windowHeight || 0;
} catch {
scrollHeight.value = 0;
}
2026-01-22 15:54:15 +08:00
archiveId.value = options?.archiveId ? String(options.archiveId) : '';
recordId.value = options?.id ? String(options.id) : '';
2026-01-26 16:47:35 +08:00
mode.value = options?.mode ? String(options.mode) : 'add';
const seed = uni.getStorageSync('service-record-detail') || null;
2026-01-22 15:54:15 +08:00
2026-01-26 16:47:35 +08:00
customerId.value = String(seed?.customerId || archiveId.value || '') || '';
customerName.value = String(seed?.customerName || '') || '';
customerUserId.value = String(seed?.customerUserId || '') || '';
const executionTime = seed?.executionTime && dayjs(seed.executionTime).isValid() ? dayjs(seed.executionTime) : null;
date.value = executionTime ? executionTime.format('YYYY-MM-DD') : dayjs().format('YYYY-MM-DD');
time.value = executionTime ? executionTime.format('HH:mm') : '';
form.taskContent = String(seed?.taskContent || '') || '';
const seedType = String(seed?.eventType || '') || '';
currentType.value = typeOptions.find((i) => i.value === seedType) || null;
2026-02-06 18:04:34 +08:00
// 新建:团队固定为当前团队,不支持切换
const cur = getCurrentTeam();
currentTeam.value = cur;
teamOptions.value = cur ? [cur] : [];
if (recordId.value) {
uni.setNavigationBarTitle({ title: '修改服务内容' });
nextTick(() => editPopupRef.value?.open?.());
} else {
uni.setNavigationBarTitle({ title: '新建服务记录' });
}
2026-01-22 15:54:15 +08:00
});
function pickType(e) {
2026-01-26 16:47:35 +08:00
currentType.value = typeOptions[e.detail.value] || null;
2026-01-22 15:54:15 +08:00
}
function pickDate(e) {
date.value = e.detail.value || '';
}
function pickTime(e) {
time.value = e.detail.value || '';
}
function cancel() {
uni.navigateBack();
}
function save() {
2026-01-26 16:47:35 +08:00
if (!customerId.value) return toast('缺少 customerId');
2026-01-22 15:54:15 +08:00
if (!date.value) return uni.showToast({ title: '请选择服务日期', icon: 'none' });
if (!time.value) return uni.showToast({ title: '请选择执行时间', icon: 'none' });
if (!currentType.value?.value) return uni.showToast({ title: '请选择服务类型', icon: 'none' });
if (!currentTeam.value?.value) return uni.showToast({ title: '请选择所属团队', icon: 'none' });
if (!String(form.taskContent || '').trim()) return uni.showToast({ title: '请输入服务内容', icon: 'none' });
const executionTime = dayjs(`${date.value} ${time.value}`).isValid() ? dayjs(`${date.value} ${time.value}`).valueOf() : Date.now();
2026-01-26 16:47:35 +08:00
submit(executionTime);
}
2026-02-06 18:04:34 +08:00
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);
}
2026-01-26 16:47:35 +08:00
async function submit(executionTime) {
await ensureDoctor();
const corpId = getCorpId();
const userId = getUserId();
if (!corpId || !userId) {
toast('缺少用户/团队信息');
return;
}
const params = {
taskContent: form.taskContent,
executionTime,
eventType: currentType.value.value,
executeTeamId: currentTeam.value.value,
executeTeamName: currentTeam.value.label,
};
let res;
if (recordId.value) {
res = await api('updateServiceRecord', {
corpId,
id: recordId.value,
params: {
...params,
updateUserId: userId,
},
});
} else {
res = await api('addServiceRecord', {
...params,
corpId,
creatorUserId: userId,
executorUserId: userId,
customerId: customerId.value,
customerName: customerName.value,
customerUserId: customerUserId.value,
});
}
if (!res?.success) {
toast(res?.message || (recordId.value ? '修改失败' : '新增失败'));
return;
}
2026-01-22 15:54:15 +08:00
uni.$emit('archive-detail:service-record-changed');
uni.showToast({ title: '保存成功', icon: 'success' });
setTimeout(() => uni.navigateBack(), 300);
}
</script>
<style scoped>
.page {
2026-02-11 17:45:09 +08:00
height: 100vh;
overflow: hidden;
2026-01-22 15:54:15 +08:00
background: #f5f6f8;
2026-02-11 17:45:09 +08:00
padding-bottom: 0;
2026-01-22 15:54:15 +08:00
}
.body {
height: 100vh;
display: flex;
flex-direction: column;
}
.scroll {
2026-02-11 17:45:09 +08:00
width: 100%;
2026-01-22 15:54:15 +08:00
}
.card {
background: #fff;
padding: 14px;
margin: 10px 14px 0;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}
.section-title {
font-size: 16px;
font-weight: 600;
color: #333;
margin: 12px 0 10px;
}
.section-title:first-child {
margin-top: 0;
}
.picker-box {
display: flex;
align-items: center;
padding: 12px 12px;
border: 1px solid #e6e6e6;
border-radius: 6px;
background: #fff;
}
.picker-box.between {
justify-content: space-between;
}
.mr {
margin-right: 10px;
}
.picker-text {
font-size: 14px;
color: #333;
}
.picker-text.muted {
color: #999;
}
.textarea-box {
border: 1px solid #e6e6e6;
border-radius: 8px;
padding: 10px;
}
.textarea {
width: 100%;
height: 90px;
font-size: 14px;
box-sizing: border-box;
}
.textarea.tall {
height: 120px;
}
.counter {
margin-top: 6px;
text-align: right;
font-size: 12px;
color: #999;
}
.footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
background: #fff;
padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
display: flex;
gap: 12px;
box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.06);
}
.btn {
flex: 1;
height: 44px;
line-height: 44px;
border-radius: 6px;
font-size: 15px;
}
.btn::after {
border: none;
}
.btn.plain {
background: #fff;
2026-02-02 15:15:51 +08:00
color: #0877F1;
border: 1px 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;
}
2026-02-06 18:04:34 +08:00
.sheet {
2026-01-22 15:54:15 +08:00
background: #fff;
2026-02-06 18:04:34 +08:00
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;
2026-01-22 15:54:15 +08:00
display: flex;
align-items: center;
justify-content: center;
2026-02-06 18:04:34 +08:00
}
.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;
2026-01-22 15:54:15 +08:00
}
</style>