// ignore_for_file: must_be_immutable import 'dart:convert'; import 'package:fis_jsonrpc/rpc.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vitalapp/architecture/utils/prompt_box.dart'; import 'package:vitalapp/components/alert_dialog.dart'; import 'package:vitalapp/components/no_data_view.dart'; import 'package:vitalapp/managers/interfaces/prescription.dart'; import 'package:vitalapp/pages/check/prescription/prescription_form.dart'; import 'package:vitalapp/pages/check/prescription/prescription_form_keys.dart'; import 'package:vitalapp/pages/form/form_info.dart'; import 'package:vitalapp/store/store.dart'; class ExaminationPrescription extends StatefulWidget { ExaminationPrescription({ super.key, required this.physicalExamNumber, required this.patientCode, required this.prescription, required this.prescriptionTitle, this.isEdit, }); final String? physicalExamNumber; final String? patientCode; final bool? isEdit; String prescription = ''; String prescriptionTitle = ''; @override State createState() => _ExaminationPrescriptionState(); } class _ExaminationPrescriptionState extends State { final _prescriptionManager = Get.find(); List? prescriptionList; String prescriptionCode = ""; @override Widget build(BuildContext context) { return _buildExaminationPrescriptionDialog(); } @override void initState() { _initPrescription(); super.initState(); } Future _initPrescription() async { // 获取处方列表 if (widget.prescriptionTitle.isEmpty) { return; } prescriptionList = await _prescriptionManager.getPrescriptionPage( patientCode: widget.patientCode!, physicalExamNumber: widget.physicalExamNumber!, ); String? prescriptionData = prescriptionList ?.firstWhereOrNull( (element) => element.prescriptionTemplateKey == widget.prescription) ?.prescriptionData; prescriptionCode = prescriptionList ?.firstWhereOrNull((element) => element.prescriptionTemplateKey == widget.prescription) ?.code ?? ""; if (prescriptionData != null) { FormInfo.instance.formValue = jsonDecode(prescriptionData); } setState(() {}); } Widget _buildExaminationPrescriptionDialog() { const designWidth = 1280.0; // 设计尺寸宽度:1280 final width = Get.width; final scale = width / designWidth; // 计算缩放比例 return VAlertDialog( // title: "新增处方", width: width * 0.8 / scale, content: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ if (widget.prescriptionTitle.isEmpty) Container( //height: Get.height, child: ListView( shrinkWrap: true, children: [ Wrap( children: PrescriptionFormKeys.AllFormKeys.entries.map( (e) { return Container( margin: EdgeInsets.symmetric( vertical: 6, horizontal: 10, ), decoration: BoxDecoration( border: Border.all( color: widget.prescription == e.key ? Colors.blue : Colors.black26, ), borderRadius: const BorderRadius.all( Radius.circular(50), ), color: widget.prescription == e.key ? Colors.blue : Colors.transparent, ), child: InkWell( onTap: () => selectRaidoChange(e), borderRadius: BorderRadius.circular(50), child: FittedBox( child: Container( padding: const EdgeInsets.all(12), alignment: Alignment.center, child: Text( e.value, style: TextStyle( fontSize: 20, color: widget.prescription == e.key ? Colors.white : Colors.black54, ), ), ), ), ), ); }, ).toList(), ), ], ), ), if (widget.prescriptionTitle.isNotEmpty) // 构建处方信息 Expanded( key: UniqueKey(), child: Container( color: Colors.white, child: _buildPrescription( widget.prescription, widget.prescriptionTitle, ), ), ), ], ), onCanceled: () { FormInfo.instance.formValue.clear(); }, onConfirm: () async { if (widget.isEdit ?? false) { bool? result = await _prescriptionManager.updatePrescription( patientCode: widget.patientCode!, physicalExamNumber: widget.physicalExamNumber, prescriptionCode: prescriptionCode, prescriptionKey: widget.prescription, prescriptionData: jsonEncode(FormInfo.instance.formValue), ); if (result ?? false) { Get.back(); FormInfo.instance.formValue.clear(); } else { PromptBox.toast("更新失败"); } } else if (FormInfo.instance.formValue.isNotEmpty) { String? prescriptionCode = await _prescriptionManager.createPrescription( patientCode: widget.patientCode!, physicalExamNumber: widget.physicalExamNumber, prescriptionKey: widget.prescription, prescriptionData: jsonEncode(FormInfo.instance.formValue), ); Get.back(result: { "prescriptionCode": prescriptionCode, "prescription": widget.prescription, }); FormInfo.instance.formValue.clear(); } else { Get.back(); } }, ); } void selectRaidoChange(MapEntry e) { Store.app.setBusy("加载中"); widget.prescription = e.key; widget.prescriptionTitle = e.value; setState(() {}); Store.app.cancelBusy(); } Widget _buildPrescription(String prescription, String prescriptionTitle) { switch (prescription) { case '': return VNoDataView(); default: return Column( children: [ Container( margin: const EdgeInsets.all(10), child: Text( prescriptionTitle, style: const TextStyle( fontSize: 30, fontWeight: FontWeight.bold, ), ), ), Expanded( child: PrescriptionForm( prescription, ), ), ], ); } // 构建处方信息 } }