Parcourir la source

0018411: 【严重精神病障碍】【随访表】行为及治疗下,用药情况和指导下,新增“用药情况”和“用药指导”后,无法编辑记录

finlay il y a 11 mois
Parent
commit
d63aeffc7b

+ 5 - 0
lib/components/dialog_medication.dart

@@ -17,6 +17,7 @@ class VDialogMedication extends StatefulWidget {
   final double? inputHeight;
   final bool Function(String)? onConfirmVerification;
   final bool showCancel;
+  final MedicationModel? medicationModel;
 
   const VDialogMedication({
     Key? key,
@@ -27,6 +28,7 @@ class VDialogMedication extends StatefulWidget {
     this.inputHeight = 56,
     this.onConfirmVerification,
     this.showCancel = false,
+    this.medicationModel,
   }) : super(key: key);
   Future<MedicationModel?> show<MedicationModel>() =>
       VAlertDialog.showDialog<MedicationModel>(this);
@@ -40,6 +42,9 @@ class _VDialogMedicationState extends State<VDialogMedication> {
   @override
   void initState() {
     super.initState();
+    if (widget.medicationModel != null) {
+      medicationModel = widget.medicationModel!;
+    }
   }
 
   @override

+ 23 - 0
lib/pages/check/widgets/configurable_card.dart

@@ -859,6 +859,12 @@ class _ConfigurableFormState extends State<ConfigurableCard> {
           if (currentSelectedCheckBox.contains(disabledValue)) {
             // PromptBox.toast('选项冲突');
           } else {
+            // 最大可选处理
+            if (currentFormObject.maxItems != null &&
+                currentSelectedCheckBox.length >= currentFormObject.maxItems!) {
+              PromptBox.toast('最多选择${currentFormObject.maxItems}项');
+              return;
+            }
             currentSelectedCheckBox.add(e.value ?? '');
           }
         }
@@ -1172,11 +1178,28 @@ class _ConfigurableFormState extends State<ConfigurableCard> {
       setState(() {});
     }
 
+    Future<void> editVeterinaryDrug(int index) async {
+      MedicationModel medicationModel =
+          MedicationModel.fromJson(currentValue[index]);
+
+      MedicationModel? result = await VDialogMedication(
+        title: currentFormObject.label,
+        medicationModel: medicationModel,
+      ).show();
+      if (result != null) {
+        currentValue[index] = result.toJson();
+        formValue[currentFormObject.key!] = null;
+        formValue[currentFormObject.key!] = currentValue;
+        setState(() {});
+      }
+    }
+
     return ExamMedication(
       currentFormObject: currentFormObject,
       currentValues: currentValue,
       addVeterinaryDrug: addVeterinaryDrug,
       deleteVeterinaryDrug: deleteVeterinaryDrug,
+      editVeterinaryDrug: editVeterinaryDrug,
     );
   }
 

+ 8 - 0
lib/pages/check/widgets/exam_configurable/exam_medication.dart

@@ -8,6 +8,7 @@ class ExamMedication extends StatelessWidget {
   final Function? addVeterinaryDrug;
   final FormObject currentFormObject;
   final Function? deleteVeterinaryDrug;
+  final Function? editVeterinaryDrug;
 
   const ExamMedication({
     super.key,
@@ -15,6 +16,7 @@ class ExamMedication extends StatelessWidget {
     this.addVeterinaryDrug,
     required this.currentFormObject,
     this.deleteVeterinaryDrug,
+    this.editVeterinaryDrug,
   });
 
   @override
@@ -45,6 +47,12 @@ class ExamMedication extends StatelessWidget {
                         textAlign: TextAlign.left,
                       ),
                     ),
+                    IconButton(
+                      onPressed: () {
+                        editVeterinaryDrug!(entry.key);
+                      },
+                      icon: Icon(Icons.edit),
+                    ),
                     IconButton(
                       onPressed: () {
                         deleteVeterinaryDrug!(entry.key);