import { useState } from 'react'; import { View, Text, Input, Textarea, Picker, ScrollView } from '@tarojs/components'; import Taro, { useRouter } from '@tarojs/taro'; import * as doctorApi from '@/services/doctor'; import Loading from '@/components/Loading'; import './index.scss'; interface FormState { dialyzer_model: string; membrane_area: string; dialysate_potassium: string; dialysate_calcium: string; dialysate_bicarbonate: string; anticoagulation_type: string; anticoagulation_dose: string; target_ultrafiltration_ml: string; target_dry_weight: string; blood_flow_rate: string; dialysate_flow_rate: string; frequency_per_week: string; duration_minutes: string; vascular_access_type: string; vascular_access_location: string; effective_from: string; effective_to: string; notes: string; } const initialForm: FormState = { dialyzer_model: '', membrane_area: '', dialysate_potassium: '', dialysate_calcium: '', dialysate_bicarbonate: '', anticoagulation_type: '', anticoagulation_dose: '', target_ultrafiltration_ml: '', target_dry_weight: '', blood_flow_rate: '', dialysate_flow_rate: '', frequency_per_week: '', duration_minutes: '', vascular_access_type: '', vascular_access_location: '', effective_from: '', effective_to: '', notes: '', }; export default function PrescriptionCreate() { const router = useRouter(); const patientId = router.params.patientId || ''; const [form, setForm] = useState(initialForm); const [submitting, setSubmitting] = useState(false); const updateField = (key: keyof FormState, value: string) => { setForm((prev) => ({ ...prev, [key]: value })); }; const handleSubmit = async () => { if (!patientId) { Taro.showToast({ title: '缺少患者信息', icon: 'none' }); return; } setSubmitting(true); const num = (v: string) => v ? Number(v) : undefined; const payload = { patient_id: patientId, dialyzer_model: form.dialyzer_model || undefined, membrane_area: num(form.membrane_area), dialysate_potassium: num(form.dialysate_potassium), dialysate_calcium: num(form.dialysate_calcium), dialysate_bicarbonate: num(form.dialysate_bicarbonate), anticoagulation_type: form.anticoagulation_type || undefined, anticoagulation_dose: form.anticoagulation_dose || undefined, target_ultrafiltration_ml: num(form.target_ultrafiltration_ml), target_dry_weight: num(form.target_dry_weight), blood_flow_rate: num(form.blood_flow_rate), dialysate_flow_rate: num(form.dialysate_flow_rate), frequency_per_week: num(form.frequency_per_week), duration_minutes: num(form.duration_minutes), vascular_access_type: form.vascular_access_type || undefined, vascular_access_location: form.vascular_access_location || undefined, effective_from: form.effective_from || undefined, effective_to: form.effective_to || undefined, notes: form.notes || undefined, }; try { await doctorApi.createDialysisPrescription(payload); Taro.showToast({ title: '创建成功', icon: 'success' }); setTimeout(() => Taro.navigateBack(), 1000); } catch { Taro.showToast({ title: '创建失败', icon: 'none' }); } finally { setSubmitting(false); } }; const InputField = ({ label, field, placeholder, type = 'digit' }: { label: string; field: keyof FormState; placeholder: string; type?: string; }) => ( {label} updateField(field, e.detail.value)} /> ); return ( {/* 透析器 */} 透析器 {/* 透析液 */} 透析液配比 {/* 抗凝 */} 抗凝方案 {/* 参数 */} 参数设置 {/* 血管通路 */} 血管通路 {/* 生效日期 */} 生效日期 生效日期 updateField('effective_from', e.detail.value)}> {form.effective_from || '请选择'} 失效日期 updateField('effective_to', e.detail.value)}> {form.effective_to || '请选择'} {/* 备注 */} 备注