feat(appointment): 预约创建页重写 — 宫格科室+周视图日历+时段卡片

This commit is contained in:
iven
2026-04-24 12:42:46 +08:00
parent 487432b4e9
commit 38e53efaec
2 changed files with 193 additions and 220 deletions

View File

@@ -6,95 +6,85 @@
padding-bottom: 140px; padding-bottom: 140px;
} }
/* 步骤指示器 */
.step-bar {
display: flex;
justify-content: space-around;
padding: 32px 24px 0;
}
.step-item {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
opacity: 0.4;
transition: opacity 0.3s;
}
.step-item.step-active {
opacity: 1;
}
.step-item.step-done {
opacity: 0.8;
}
.step-dot {
width: 56px;
height: 56px;
border-radius: 50%;
background: $bd;
display: flex;
align-items: center;
justify-content: center;
transition: background 0.3s;
}
.step-active .step-dot {
background: $pri;
}
.step-done .step-dot {
background: $acc;
}
.step-num {
font-size: 28px;
color: white;
font-weight: bold;
}
.step-check {
font-size: 28px;
color: white;
font-weight: bold;
}
.step-label {
font-size: 22px;
color: $tx2;
}
.step-active .step-label {
color: $pri;
font-weight: 500;
}
/* 步骤连接线 */
.step-line-wrapper {
padding: 12px 80px 0;
}
.step-line {
height: 4px;
background: $bd;
border-radius: 2px;
overflow: hidden;
}
.step-line-fill {
height: 100%;
background: linear-gradient(90deg, $acc, $pri);
border-radius: 2px;
transition: width 0.3s ease;
}
/* 步骤内容 */ /* 步骤内容 */
.step-content { .step-content {
padding: 32px 24px; padding: 32px 24px;
} }
/* 科室宫格 */
.dept-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}
.dept-card {
background: $card;
border-radius: $r;
padding: 24px 12px;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
border: 2px solid transparent;
transition: border-color 0.2s;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.dept-card.dept-selected {
border-color: $pri;
background: $pri-surface;
}
.dept-icon {
font-size: 40px;
}
.dept-label {
font-size: 26px;
color: $tx;
}
/* 时段卡片 */
.slot-section {
margin-top: 24px;
}
.slot-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 12px;
}
.slot-card {
background: $card;
border-radius: $r-sm;
padding: 16px 20px;
border: 2px solid transparent;
transition: all 0.2s;
&.slot-few { border-color: $wrn; }
&.slot-full { opacity: 0.5; background: $bd-l; }
&.slot-selected { border-color: $pri; background: $pri-surface; }
}
.slot-time {
font-size: 28px;
font-weight: bold;
color: $tx;
display: block;
}
.slot-count {
font-size: 22px;
color: $tx3;
display: block;
margin-top: 4px;
}
.slot-few .slot-count { color: $wrn; }
.slot-full .slot-count { color: $dan; }
.step-title { .step-title {
font-size: 32px; font-size: 32px;
font-weight: bold; font-weight: bold;

View File

@@ -1,11 +1,20 @@
import React, { useState, useCallback } from 'react'; import React, { useState, useCallback, useMemo } from 'react';
import { View, Text, Picker, Input } from '@tarojs/components'; import { View, Text, Input } from '@tarojs/components';
import Taro from '@tarojs/taro'; import Taro from '@tarojs/taro';
import { listDoctors, createAppointment } from '../../../services/appointment'; import { listDoctors, createAppointment, calendarView } from '../../../services/appointment';
import { useAuthStore } from '../../../stores/auth'; import { useAuthStore } from '../../../stores/auth';
import StepIndicator from '../../../components/StepIndicator';
import WeekCalendar from '../../../components/WeekCalendar';
import './index.scss'; import './index.scss';
const DEPARTMENTS = ['内科', '外科', '妇科', '儿科', '体检中心']; const DEPARTMENTS = [
{ label: '内科', icon: '🫀' },
{ label: '外科', icon: '🔪' },
{ label: '妇科', icon: '👩‍⚕️' },
{ label: '儿科', icon: '👶' },
{ label: '体检中心', icon: '🏥' },
{ label: '中医科', icon: '🌿' },
];
interface DoctorItem { interface DoctorItem {
id: string; id: string;
@@ -15,27 +24,33 @@ interface DoctorItem {
specialty?: string; specialty?: string;
} }
interface TimeSlot {
time_slot: string;
available_count: number;
}
export default function AppointmentCreate() { export default function AppointmentCreate() {
const [currentStep, setCurrentStep] = useState(0); const [currentStep, setCurrentStep] = useState(0);
const [department, setDepartment] = useState(''); const [department, setDepartment] = useState('');
const [deptPickerIndex, setDeptPickerIndex] = useState(0);
const [doctors, setDoctors] = useState<DoctorItem[]>([]); const [doctors, setDoctors] = useState<DoctorItem[]>([]);
const [selectedDoctor, setSelectedDoctor] = useState<DoctorItem | null>(null); const [selectedDoctor, setSelectedDoctor] = useState<DoctorItem | null>(null);
const [appointmentDate, setAppointmentDate] = useState(''); const [appointmentDate, setAppointmentDate] = useState('');
const [timeSlot, setTimeSlot] = useState(''); const [timeSlot, setTimeSlot] = useState('');
const [reason, setReason] = useState(''); const [reason, setReason] = useState('');
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [schedules, setSchedules] = useState<any[]>([]);
const [timeSlots, setTimeSlots] = useState<TimeSlot[]>([]);
const currentPatient = useAuthStore((s) => s.currentPatient); const currentPatient = useAuthStore((s) => s.currentPatient);
// Step 1: 选择科室后加载医生列表 const scheduledDates = useMemo(() => {
const onDepartmentChange = useCallback(async (e: { detail: { value: number } }) => { if (!schedules) return new Set<string>();
const idx = e.detail.value; return new Set(schedules.map((s: any) => s.date || s.appointment_date));
const dept = DEPARTMENTS[idx]; }, [schedules]);
setDeptPickerIndex(idx);
const onSelectDept = useCallback(async (dept: string) => {
setDepartment(dept); setDepartment(dept);
setSelectedDoctor(null); setSelectedDoctor(null);
try { try {
const res = await listDoctors(dept); const res = await listDoctors(dept);
setDoctors(res.data || []); setDoctors(res.data || []);
@@ -44,44 +59,47 @@ export default function AppointmentCreate() {
} }
}, []); }, []);
// Step 2: 选择医生 const onSelectDoctor = useCallback(async (doctor: DoctorItem) => {
const onSelectDoctor = useCallback((doctor: DoctorItem) => {
setSelectedDoctor(doctor); setSelectedDoctor(doctor);
setLoading(true);
try {
const today = new Date();
const endDate = new Date(today);
endDate.setDate(today.getDate() + 30);
const fmt = (d: Date) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
const res = await calendarView(fmt(today), fmt(endDate), doctor.id);
setSchedules(res || []);
} catch {
// 日历加载失败不阻塞
} finally {
setLoading(false);
}
}, []); }, []);
// Step 3: 日期变更 const onSelectDate = useCallback((date: string) => {
const onDateChange = useCallback((e: { detail: { value: string } }) => { setAppointmentDate(date);
setAppointmentDate(e.detail.value); setTimeSlot('');
}, []); // 从排班数据中提取时段
const daySlots = schedules
.filter((s: any) => (s.date || s.appointment_date) === date)
.map((s: any) => ({
time_slot: s.time_slot || `${s.start_time || ''}-${s.end_time || ''}`,
available_count: s.available_count ?? (s.max_patients ?? 10),
}));
setTimeSlots(daySlots);
}, [schedules]);
// Step 3: 时段变更 const getSlotStyle = (available: number) => {
const onTimeSlotChange = useCallback((e: { detail: { value: string } }) => { if (available === 0) return 'slot-full';
setTimeSlot(e.detail.value); if (available <= 3) return 'slot-few';
}, []); return 'slot-available';
};
// Step 3: 备注变更
const onReasonChange = useCallback((e: { detail: { value: string } }) => {
setReason(e.detail.value);
}, []);
// 提交预约
const handleSubmit = useCallback(async () => { const handleSubmit = useCallback(async () => {
if (!selectedDoctor) { if (!selectedDoctor) { Taro.showToast({ title: '请选择医生', icon: 'none' }); return; }
Taro.showToast({ title: '请选择医生', icon: 'none' }); if (!appointmentDate) { Taro.showToast({ title: '请选择日期', icon: 'none' }); return; }
return; if (!timeSlot) { Taro.showToast({ title: '请选择时段', icon: 'none' }); return; }
} if (!currentPatient) { 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); setLoading(true);
try { try {
@@ -89,13 +107,11 @@ export default function AppointmentCreate() {
patient_id: currentPatient.id, patient_id: currentPatient.id,
doctor_id: selectedDoctor.id, doctor_id: selectedDoctor.id,
appointment_date: appointmentDate, appointment_date: appointmentDate,
time_slot: timeSlot.trim(), time_slot: timeSlot,
reason: reason.trim() || undefined, reason: reason.trim() || undefined,
}); });
Taro.showToast({ title: '预约成功', icon: 'success' }); Taro.showToast({ title: '预约成功', icon: 'success' });
setTimeout(() => { setTimeout(() => Taro.navigateBack(), 1500);
Taro.navigateBack();
}, 1500);
} catch { } catch {
Taro.showToast({ title: '预约失败', icon: 'none' }); Taro.showToast({ title: '预约失败', icon: 'none' });
} finally { } finally {
@@ -103,76 +119,53 @@ export default function AppointmentCreate() {
} }
}, [selectedDoctor, appointmentDate, timeSlot, reason, currentPatient]); }, [selectedDoctor, appointmentDate, timeSlot, reason, currentPatient]);
// 步骤切换
const goNext = () => { const goNext = () => {
if (currentStep === 0 && !department) { if (currentStep === 0 && !department) { Taro.showToast({ title: '请先选择科室', icon: 'none' }); return; }
Taro.showToast({ title: '请选择科室', icon: 'none' }); if (currentStep === 1 && !selectedDoctor) { Taro.showToast({ title: '请选择医生', icon: 'none' }); return; }
return;
}
if (currentStep === 1 && !selectedDoctor) {
Taro.showToast({ title: '请选择医生', icon: 'none' });
return;
}
setCurrentStep(Math.min(currentStep + 1, 2)); setCurrentStep(Math.min(currentStep + 1, 2));
}; };
const goPrev = () => { const handleStepChange = (idx: number) => {
setCurrentStep(Math.max(currentStep - 1, 0)); if (idx < currentStep) {
if (idx <= 1) setSelectedDoctor(null);
if (idx <= 2) { setAppointmentDate(''); setTimeSlot(''); }
setCurrentStep(idx);
}
}; };
const stepLabels = ['选择科室', '选择医生', '选择日期与时段'];
return ( return (
<View className='create-page'> <View className='create-page'>
{/* 步骤指示器 */} <StepIndicator
<View className='step-bar'> steps={[{ label: '选科室' }, { label: '选医生' }, { label: '选时段' }]}
{stepLabels.map((label, idx) => ( current={currentStep}
<View onChange={handleStepChange}
className={`step-item ${idx <= currentStep ? 'step-active' : ''} ${idx < currentStep ? 'step-done' : ''}`} />
key={label}
>
<View className='step-dot'>
{idx < currentStep ? (
<Text className='step-check'>&#10003;</Text>
) : (
<Text className='step-num'>{idx + 1}</Text>
)}
</View>
<Text className='step-label'>{label}</Text>
</View>
))}
</View>
{/* 步骤连接线 */} {/* Step 1: 科室宫格 */}
<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 && ( {currentStep === 0 && (
<View className='step-content'> <View className='step-content'>
<Text className='step-title'></Text> <Text className='step-title'></Text>
<Picker mode='selector' range={DEPARTMENTS} value={deptPickerIndex} onChange={onDepartmentChange}> <View className='dept-grid'>
<View className='picker-card'> {DEPARTMENTS.map((dept) => (
<Text className={`picker-value ${department ? '' : 'placeholder'}`}> <View
{department || '点击选择科室'} className={`dept-card ${department === dept.label ? 'dept-selected' : ''}`}
</Text> key={dept.label}
<Text className='picker-arrow'>&#9662;</Text> onClick={() => onSelectDept(dept.label)}
</View> >
</Picker> <Text className='dept-icon'>{dept.icon}</Text>
<Text className='dept-label'>{dept.label}</Text>
</View>
))}
</View>
</View> </View>
)} )}
{/* Step 2: 选择医生 */} {/* Step 2: 医生列表 */}
{currentStep === 1 && ( {currentStep === 1 && (
<View className='step-content'> <View className='step-content'>
<Text className='step-title'>{department} - </Text> <Text className='step-title'>{department} - </Text>
{doctors.length === 0 ? ( {doctors.length === 0 ? (
<View className='empty-state'> <View className='empty-hint'><Text className='empty-text'></Text></View>
<Text className='empty-text'></Text>
</View>
) : ( ) : (
<View className='doctor-list'> <View className='doctor-list'>
{doctors.map((doc) => ( {doctors.map((doc) => (
@@ -181,17 +174,13 @@ export default function AppointmentCreate() {
key={doc.id} key={doc.id}
onClick={() => onSelectDoctor(doc)} onClick={() => onSelectDoctor(doc)}
> >
<View className='doctor-avatar'> <View className='doctor-avatar'><Text className='doctor-avatar-text'>{doc.name.charAt(0)}</Text></View>
<Text className='doctor-avatar-text'>{doc.name.charAt(0)}</Text>
</View>
<View className='doctor-detail'> <View className='doctor-detail'>
<Text className='doctor-name'>{doc.name}</Text> <Text className='doctor-name'>{doc.name}</Text>
<Text className='doctor-title'>{doc.title || '医生'}</Text> <Text className='doctor-title'>{doc.title || '医生'}</Text>
{doc.specialty && <Text className='doctor-specialty'>{doc.specialty}</Text>} {doc.specialty && <Text className='doctor-specialty'>{doc.specialty}</Text>}
</View> </View>
{selectedDoctor?.id === doc.id && ( {selectedDoctor?.id === doc.id && <Text className='doctor-check'>&#10003;</Text>}
<Text className='doctor-check'>&#10003;</Text>
)}
</View> </View>
))} ))}
</View> </View>
@@ -199,48 +188,42 @@ export default function AppointmentCreate() {
</View> </View>
)} )}
{/* Step 3: 选择日期和时段 */} {/* Step 3: 日历 + 时段 */}
{currentStep === 2 && ( {currentStep === 2 && (
<View className='step-content'> <View className='step-content'>
<Text className='step-title'></Text> <Text className='step-title'></Text>
<View className='form-group'> <View className='form-group'>
<Text className='form-label'></Text> <Text className='form-label'></Text>
<View className='form-static'> <View className='form-static'><Text className='form-static-text'>{selectedDoctor?.name} - {department}</Text></View>
<Text className='form-static-text'>{selectedDoctor?.name} - {department}</Text>
</View>
</View> </View>
<View className='form-group'> <WeekCalendar
<Text className='form-label'></Text> scheduledDates={scheduledDates}
<Picker mode='date' value={appointmentDate} onChange={onDateChange}> selectedDate={appointmentDate}
<View className='picker-card'> onSelectDate={onSelectDate}
<Text className={`picker-value ${appointmentDate ? '' : 'placeholder'}`}> />
{appointmentDate || '点击选择日期'}
</Text> {appointmentDate && timeSlots.length > 0 && (
<Text className='picker-arrow'>&#9662;</Text> <View className='slot-section'>
<Text className='form-label'></Text>
<View className='slot-grid'>
{timeSlots.map((slot) => (
<View
className={`slot-card ${getSlotStyle(slot.available_count)} ${timeSlot === slot.time_slot ? 'slot-selected' : ''}`}
key={slot.time_slot}
onClick={slot.available_count > 0 ? () => setTimeSlot(slot.time_slot) : undefined}
>
<Text className='slot-time'>{slot.time_slot}</Text>
<Text className='slot-count'>{slot.available_count > 0 ? `剩余 ${slot.available_count}` : '已满'}</Text>
</View>
))}
</View> </View>
</Picker> </View>
</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'> <View className='form-group'>
<Text className='form-label'></Text> <Text className='form-label'></Text>
<Input <Input className='form-input' placeholder='请简要描述症状' value={reason} onInput={(e) => setReason(e.detail.value)} />
className='form-input'
placeholder='请简要描述症状或就诊目的'
value={reason}
onInput={onReasonChange}
/>
</View> </View>
</View> </View>
)} )}
@@ -248,7 +231,7 @@ export default function AppointmentCreate() {
{/* 底部操作栏 */} {/* 底部操作栏 */}
<View className='bottom-bar'> <View className='bottom-bar'>
{currentStep > 0 && ( {currentStep > 0 && (
<View className='btn btn-prev' onClick={goPrev}> <View className='btn btn-prev' onClick={() => handleStepChange(currentStep - 1)}>
<Text className='btn-text'></Text> <Text className='btn-text'></Text>
</View> </View>
)} )}