feat(health+miniprogram): 预约/报告/随访/资讯/家庭管理 — Chunk 4-6
后端: - 添加 articles 表迁移 + Entity + Service + Handler - 健康数据趋势 API (get_mini_trend) 注册路由 - article CRUD (list/get) + DTO 前端 (11个新页面 + 5个服务): - 预约挂号: 列表/创建向导/详情页 - 报告管理: 列表/详情页 - 随访管理: 任务列表/记录详情页 - 资讯文章: 文章详情页 - 个人中心: 就诊人管理/新增/我的报告/我的随访/用药提醒/设置 - 更新 app.config.ts 注册全部路由 - 更新 profile/article 页面为真实功能
This commit is contained in:
268
apps/miniprogram/src/pages/appointment/create/index.tsx
Normal file
268
apps/miniprogram/src/pages/appointment/create/index.tsx
Normal file
@@ -0,0 +1,268 @@
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import { View, Text, Picker, Input } from '@tarojs/components';
|
||||
import Taro from '@tarojs/taro';
|
||||
import { listDoctors, createAppointment } from '../../../services/appointment';
|
||||
import { useAuthStore } from '../../../stores/auth';
|
||||
import './index.scss';
|
||||
|
||||
const DEPARTMENTS = ['内科', '外科', '妇科', '儿科', '体检中心'];
|
||||
|
||||
interface DoctorItem {
|
||||
id: string;
|
||||
name: string;
|
||||
title?: string;
|
||||
department?: string;
|
||||
specialty?: string;
|
||||
}
|
||||
|
||||
export default function AppointmentCreate() {
|
||||
const [currentStep, setCurrentStep] = useState(0);
|
||||
const [department, setDepartment] = useState('');
|
||||
const [deptPickerIndex, setDeptPickerIndex] = useState(0);
|
||||
const [doctors, setDoctors] = useState<DoctorItem[]>([]);
|
||||
const [selectedDoctor, setSelectedDoctor] = useState<DoctorItem | null>(null);
|
||||
const [appointmentDate, setAppointmentDate] = useState('');
|
||||
const [timeSlot, setTimeSlot] = useState('');
|
||||
const [reason, setReason] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const currentPatient = useAuthStore((s) => s.currentPatient);
|
||||
|
||||
// Step 1: 选择科室后加载医生列表
|
||||
const onDepartmentChange = useCallback(async (e: any) => {
|
||||
const idx = e.detail.value;
|
||||
const dept = DEPARTMENTS[idx];
|
||||
setDeptPickerIndex(idx);
|
||||
setDepartment(dept);
|
||||
setSelectedDoctor(null);
|
||||
|
||||
try {
|
||||
const res = await listDoctors(dept);
|
||||
setDoctors(res.data || []);
|
||||
} catch {
|
||||
Taro.showToast({ title: '加载医生失败', icon: 'none' });
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Step 2: 选择医生
|
||||
const onSelectDoctor = useCallback((doctor: DoctorItem) => {
|
||||
setSelectedDoctor(doctor);
|
||||
}, []);
|
||||
|
||||
// Step 3: 日期变更
|
||||
const onDateChange = useCallback((e: any) => {
|
||||
setAppointmentDate(e.detail.value);
|
||||
}, []);
|
||||
|
||||
// Step 3: 时段变更
|
||||
const onTimeSlotChange = useCallback((e: any) => {
|
||||
setTimeSlot(e.detail.value);
|
||||
}, []);
|
||||
|
||||
// Step 3: 备注变更
|
||||
const onReasonChange = useCallback((e: any) => {
|
||||
setReason(e.detail.value);
|
||||
}, []);
|
||||
|
||||
// 提交预约
|
||||
const handleSubmit = useCallback(async () => {
|
||||
if (!selectedDoctor) {
|
||||
Taro.showToast({ title: '请选择医生', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!appointmentDate) {
|
||||
Taro.showToast({ title: '请选择日期', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!timeSlot.trim()) {
|
||||
Taro.showToast({ title: '请输入时段', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (!currentPatient) {
|
||||
Taro.showToast({ title: '请先选择就诊人', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
await createAppointment({
|
||||
patient_id: currentPatient.id,
|
||||
doctor_id: selectedDoctor.id,
|
||||
schedule_id: '',
|
||||
appointment_date: appointmentDate,
|
||||
time_slot: timeSlot.trim(),
|
||||
reason: reason.trim() || undefined,
|
||||
});
|
||||
Taro.showToast({ title: '预约成功', icon: 'success' });
|
||||
setTimeout(() => {
|
||||
Taro.navigateBack();
|
||||
}, 1500);
|
||||
} catch {
|
||||
Taro.showToast({ title: '预约失败', icon: 'none' });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [selectedDoctor, appointmentDate, timeSlot, reason, currentPatient]);
|
||||
|
||||
// 步骤切换
|
||||
const goNext = () => {
|
||||
if (currentStep === 0 && !department) {
|
||||
Taro.showToast({ title: '请先选择科室', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
if (currentStep === 1 && !selectedDoctor) {
|
||||
Taro.showToast({ title: '请选择医生', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
setCurrentStep(Math.min(currentStep + 1, 2));
|
||||
};
|
||||
|
||||
const goPrev = () => {
|
||||
setCurrentStep(Math.max(currentStep - 1, 0));
|
||||
};
|
||||
|
||||
const stepLabels = ['选择科室', '选择医生', '选择日期与时段'];
|
||||
|
||||
return (
|
||||
<View className='create-page'>
|
||||
{/* 步骤指示器 */}
|
||||
<View className='step-bar'>
|
||||
{stepLabels.map((label, idx) => (
|
||||
<View
|
||||
className={`step-item ${idx <= currentStep ? 'step-active' : ''} ${idx < currentStep ? 'step-done' : ''}`}
|
||||
key={label}
|
||||
>
|
||||
<View className='step-dot'>
|
||||
{idx < currentStep ? (
|
||||
<Text className='step-check'>✓</Text>
|
||||
) : (
|
||||
<Text className='step-num'>{idx + 1}</Text>
|
||||
)}
|
||||
</View>
|
||||
<Text className='step-label'>{label}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
||||
{/* 步骤连接线 */}
|
||||
<View className='step-line-wrapper'>
|
||||
<View className='step-line'>
|
||||
<View className='step-line-fill' style={{ width: `${(currentStep / 2) * 100}%` }} />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Step 1: 选择科室 */}
|
||||
{currentStep === 0 && (
|
||||
<View className='step-content'>
|
||||
<Text className='step-title'>请选择就诊科室</Text>
|
||||
<Picker mode='selector' range={DEPARTMENTS} value={deptPickerIndex} onChange={onDepartmentChange}>
|
||||
<View className='picker-card'>
|
||||
<Text className={`picker-value ${department ? '' : 'placeholder'}`}>
|
||||
{department || '点击选择科室'}
|
||||
</Text>
|
||||
<Text className='picker-arrow'>▾</Text>
|
||||
</View>
|
||||
</Picker>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* Step 2: 选择医生 */}
|
||||
{currentStep === 1 && (
|
||||
<View className='step-content'>
|
||||
<Text className='step-title'>{department} - 请选择医生</Text>
|
||||
{doctors.length === 0 ? (
|
||||
<View className='empty-state'>
|
||||
<Text className='empty-text'>暂无可选医生</Text>
|
||||
</View>
|
||||
) : (
|
||||
<View className='doctor-list'>
|
||||
{doctors.map((doc) => (
|
||||
<View
|
||||
className={`doctor-card ${selectedDoctor?.id === doc.id ? 'doctor-selected' : ''}`}
|
||||
key={doc.id}
|
||||
onClick={() => onSelectDoctor(doc)}
|
||||
>
|
||||
<View className='doctor-avatar'>
|
||||
<Text className='doctor-avatar-text'>{doc.name.charAt(0)}</Text>
|
||||
</View>
|
||||
<View className='doctor-detail'>
|
||||
<Text className='doctor-name'>{doc.name}</Text>
|
||||
<Text className='doctor-title'>{doc.title || '医生'}</Text>
|
||||
{doc.specialty && <Text className='doctor-specialty'>{doc.specialty}</Text>}
|
||||
</View>
|
||||
{selectedDoctor?.id === doc.id && (
|
||||
<Text className='doctor-check'>✓</Text>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* Step 3: 选择日期和时段 */}
|
||||
{currentStep === 2 && (
|
||||
<View className='step-content'>
|
||||
<Text className='step-title'>选择就诊时间</Text>
|
||||
|
||||
<View className='form-group'>
|
||||
<Text className='form-label'>医生</Text>
|
||||
<View className='form-static'>
|
||||
<Text className='form-static-text'>{selectedDoctor?.name} - {department}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className='form-group'>
|
||||
<Text className='form-label'>就诊日期</Text>
|
||||
<Picker mode='date' value={appointmentDate} onChange={onDateChange}>
|
||||
<View className='picker-card'>
|
||||
<Text className={`picker-value ${appointmentDate ? '' : 'placeholder'}`}>
|
||||
{appointmentDate || '点击选择日期'}
|
||||
</Text>
|
||||
<Text className='picker-arrow'>▾</Text>
|
||||
</View>
|
||||
</Picker>
|
||||
</View>
|
||||
|
||||
<View className='form-group'>
|
||||
<Text className='form-label'>就诊时段</Text>
|
||||
<Input
|
||||
className='form-input'
|
||||
placeholder='例如: 09:00-10:00'
|
||||
value={timeSlot}
|
||||
onInput={onTimeSlotChange}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View className='form-group'>
|
||||
<Text className='form-label'>备注(选填)</Text>
|
||||
<Input
|
||||
className='form-input'
|
||||
placeholder='请简要描述症状或就诊目的'
|
||||
value={reason}
|
||||
onInput={onReasonChange}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
|
||||
{/* 底部操作栏 */}
|
||||
<View className='bottom-bar'>
|
||||
{currentStep > 0 && (
|
||||
<View className='btn btn-prev' onClick={goPrev}>
|
||||
<Text className='btn-text'>上一步</Text>
|
||||
</View>
|
||||
)}
|
||||
{currentStep < 2 ? (
|
||||
<View className='btn btn-next' onClick={goNext}>
|
||||
<Text className='btn-text btn-text-white'>下一步</Text>
|
||||
</View>
|
||||
) : (
|
||||
<View className={`btn btn-submit ${loading ? 'btn-disabled' : ''}`} onClick={loading ? undefined : handleSubmit}>
|
||||
<Text className='btn-text btn-text-white'>{loading ? '提交中...' : '确认预约'}</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user