From f75bc191e674409b7ece84cc75df50ddf8aed28b Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 24 Apr 2026 12:24:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(miniprogram):=20=E9=A2=84=E7=BA=A6=E8=AF=A6?= =?UTF-8?q?=E6=83=85/=E9=9A=8F=E8=AE=BF=E8=AF=A6=E6=83=85=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=20API=20=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=20Storage=20=E7=BC=93=E5=AD=98=E4=BC=A0?= =?UTF-8?q?=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/appointment/detail/index.tsx | 72 ++++++++++--------- .../src/pages/followup/detail/index.tsx | 28 ++++---- apps/miniprogram/src/services/appointment.ts | 4 ++ apps/miniprogram/src/services/followup.ts | 4 ++ 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/apps/miniprogram/src/pages/appointment/detail/index.tsx b/apps/miniprogram/src/pages/appointment/detail/index.tsx index ba12997..ede4b59 100644 --- a/apps/miniprogram/src/pages/appointment/detail/index.tsx +++ b/apps/miniprogram/src/pages/appointment/detail/index.tsx @@ -1,8 +1,10 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { View, Text } from '@tarojs/components'; import Taro, { useRouter } from '@tarojs/taro'; -import { cancelAppointment } from '../../../services/appointment'; +import { getAppointment, cancelAppointment } from '../../../services/appointment'; import type { Appointment } from '../../../services/appointment'; +import Loading from '../../../components/Loading'; +import ErrorState from '../../../components/ErrorState'; import './index.scss'; const STATUS_MAP: Record = { @@ -15,13 +17,27 @@ const STATUS_MAP: Record = { export default function AppointmentDetail() { const router = useRouter(); const id = router.params.id || ''; + + const [appointment, setAppointment] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(false); const [cancelling, setCancelling] = useState(false); - // 从缓存获取预约数据 - const cached = Taro.getStorageSync('appointment_detail_cache'); - const appointment: Appointment | null = (cached && cached.id === id) ? cached : null; + useEffect(() => { + if (!id) return; + setLoading(true); + getAppointment(id) + .then((data) => setAppointment(data)) + .catch((err) => { + console.error('[AppointmentDetail]', err); + setError(true); + }) + .finally(() => setLoading(false)); + }, [id]); - const status = appointment ? (STATUS_MAP[appointment.status] || { label: appointment.status, className: 'tag-pending' }) : { label: '未知', className: 'tag-pending' }; + const status = appointment + ? (STATUS_MAP[appointment.status] || { label: appointment.status, className: 'tag-pending' }) + : { label: '未知', className: 'tag-pending' }; const canCancel = appointment && (appointment.status === 'pending' || appointment.status === 'confirmed'); const handleCancel = async () => { @@ -37,9 +53,7 @@ export default function AppointmentDetail() { try { await cancelAppointment(appointment.id, appointment.version); Taro.showToast({ title: '已取消预约', icon: 'success' }); - setTimeout(() => { - Taro.navigateBack(); - }, 1500); + setTimeout(() => Taro.navigateBack(), 1500); } catch { Taro.showToast({ title: '取消失败', icon: 'none' }); } finally { @@ -47,41 +61,42 @@ export default function AppointmentDetail() { } }; - const goBack = () => { - Taro.navigateBack(); - }; + const goBack = () => Taro.navigateBack(); - if (!appointment) { + if (loading) { return ( - - 返回 - + 返回 预约详情 - - 📋 - 未找到预约信息 - 请从预约列表进入 + + + ); + } + + if (error || !appointment) { + return ( + + + 返回 + 预约详情 + + ); } return ( - {/* 顶部导航 */} - - 返回 - + 返回 预约详情 - {/* 状态卡片 */} {status.label} @@ -90,32 +105,26 @@ export default function AppointmentDetail() { {appointment.department} - {/* 详情信息 */} 预约信息 - 就诊人 {appointment.patient_name} - 就诊日期 {appointment.appointment_date} - 就诊时段 {appointment.time_slot} - 预约单号 {appointment.id} - {/* 温馨提示 */} {(appointment.status === 'pending' || appointment.status === 'confirmed') && ( 温馨提示 @@ -123,7 +132,6 @@ export default function AppointmentDetail() { )} - {/* 底部操作 */} {canCancel && ( { if (!id) return; setLoading(true); - listTasks() - .then((res) => { - const found = (res.data || []).find((t) => t.id === id); - setTask(found || null); + getTaskDetail(id) + .then((data) => setTask(data)) + .catch((err) => { + console.error('[FollowUpDetail]', err); + setError(true); }) - .catch(() => Taro.showToast({ title: '加载失败', icon: 'none' })) .finally(() => setLoading(false)); }, [id]); @@ -54,19 +58,15 @@ export default function FollowUpDetail() { if (loading) { return ( - - 加载中... - + ); } - if (!task) { + if (error || !task) { return ( - - 任务不存在 - + ); } @@ -75,7 +75,6 @@ export default function FollowUpDetail() { return ( - {/* 任务详情 */} {task.task_type} @@ -93,7 +92,6 @@ export default function FollowUpDetail() { )} - {/* 提交表单 */} {!isCompleted && ( 填写随访记录 diff --git a/apps/miniprogram/src/services/appointment.ts b/apps/miniprogram/src/services/appointment.ts index dd020b7..4bcb281 100644 --- a/apps/miniprogram/src/services/appointment.ts +++ b/apps/miniprogram/src/services/appointment.ts @@ -30,6 +30,10 @@ export async function listAppointments(page = 1) { return api.get<{ data: Appointment[]; total: number }>(`/health/appointments?page=${page}&page_size=20`); } +export async function getAppointment(id: string) { + return api.get(`/health/appointments/${id}`); +} + export async function createAppointment(data: { patient_id: string; doctor_id: string; diff --git a/apps/miniprogram/src/services/followup.ts b/apps/miniprogram/src/services/followup.ts index ea2fd20..00b0185 100644 --- a/apps/miniprogram/src/services/followup.ts +++ b/apps/miniprogram/src/services/followup.ts @@ -29,6 +29,10 @@ export async function listTasks(status?: string) { ); } +export async function getTaskDetail(id: string) { + return api.get(`/health/follow-up-tasks/${id}`); +} + export async function submitRecord(data: { task_id: string; content: FollowUpContent }) { return api.post('/health/follow-up-records', data); }