Browse Source

增加收获扦样任务单页-基本信息数据验证逻辑;

maqiang 10 months ago
parent
commit
b13782d136

+ 39 - 0
lib/page/sample_task/reap_sample_detail/reap_sample_basic_detail_page.dart

@@ -18,16 +18,19 @@ import '../../../network/my_api.dart';
18 18
 import '../../../service/user_service.dart';
19 19
 import '../../../utils/file_utils.dart';
20 20
 import '../../../widget/card_item.dart';
21
+import 'reap_sample_task_page.dart';
21 22
 
22 23
 /// 收获扦样-基础信息
23 24
 class ReapSampleBasicDetailPage extends StatefulWidget {
24 25
   final SampleTaskItem? data;
25 26
   final bool detail;
27
+  final ReapSampleTaskController ctrl;
26 28
 
27 29
   const ReapSampleBasicDetailPage(
28 30
     this.data, {
29 31
     super.key,
30 32
     this.detail = true,
33
+    required this.ctrl,
31 34
   });
32 35
 
33 36
   @override
@@ -388,6 +391,41 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
388 391
     }
389 392
   }
390 393
 
394
+  /// 校验数据
395
+  bool verifyData() {
396
+    // 扦样/陪同人员
397
+    if ((data?.dgryName ?? '').isNotEmpty) {
398
+      MyNavigator.showToast('扦样/陪同人员不能为空');
399
+      return false;
400
+    }
401
+    // 乡镇
402
+    if ((data?.xiangXzqhName ?? '').isNotEmpty) {
403
+      MyNavigator.showToast('乡镇不能为空');
404
+      return false;
405
+    }
406
+    // 村
407
+    if ((data?.cunXzqhName ?? '').isNotEmpty) {
408
+      MyNavigator.showToast('村不能为空');
409
+      return false;
410
+    }
411
+    // 扦样地点经纬度
412
+    if ((data?.qyddjwd ?? '').isNotEmpty) {
413
+      MyNavigator.showToast('扦样地点经纬度不能为空');
414
+      return false;
415
+    }
416
+    // 种植面积(亩地)
417
+    if (data?.zzmj == null) {
418
+      MyNavigator.showToast('种植面积不能为空');
419
+      return false;
420
+    }
421
+    // 土壤地理类型
422
+    if (data?.trdllx == null) {
423
+      MyNavigator.showToast('土壤地理类型不能为空');
424
+      return false;
425
+    }
426
+    return true;
427
+  }
428
+
391 429
   @override
392 430
   bool get wantKeepAlive => true;
393 431
 
@@ -395,6 +433,7 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
395 433
   void onInit() {
396 434
     data = widget.data;
397 435
     isDetail = widget.detail;
436
+    widget.ctrl.verifyData = verifyData;
398 437
     // 土壤信息
399 438
     getTrxxList();
400 439
 

+ 14 - 7
lib/page/sample_task/reap_sample_detail/reap_sample_disaster_detail_page.dart

@@ -6,24 +6,26 @@ import 'package:lszlgl/widget/card_item.dart';
6 6
 import '../../../model/rsp/dict_rsp.dart';
7 7
 import '../../../model/rsp/sample_task_rsp.dart';
8 8
 import '../../../service/dict_service.dart';
9
+import 'reap_sample_task_page.dart';
9 10
 
10 11
 /// 收获扦样-灾害污染
11 12
 class ReapSampleDisasterDetailPage extends StatefulWidget {
12 13
   final SampleTaskItem? data;
13 14
   final bool detail;
15
+  final ReapSampleTaskController ctrl;
14 16
 
15 17
   const ReapSampleDisasterDetailPage(
16 18
     this.data, {
17 19
     super.key,
18 20
     this.detail = true,
21
+    required this.ctrl,
19 22
   });
20 23
 
21 24
   @override
22 25
   State<ReapSampleDisasterDetailPage> createState() => _ReapSampleDisasterDetailPageState();
23 26
 }
24 27
 
25
-class _ReapSampleDisasterDetailPageState extends BaseLifecycleState<ReapSampleDisasterDetailPage>
26
-    with AutomaticKeepAliveClientMixin {
28
+class _ReapSampleDisasterDetailPageState extends BaseLifecycleState<ReapSampleDisasterDetailPage> with AutomaticKeepAliveClientMixin {
27 29
   SampleTaskItem? data;
28 30
   late bool isDetail;
29 31
 
@@ -76,17 +78,25 @@ class _ReapSampleDisasterDetailPageState extends BaseLifecycleState<ReapSampleDi
76 78
     num? selValue,
77 79
   ) {
78 80
     // 菜单数据
79
-    notifier.value =
80
-        (DictService.getDictList(type) ?? []).map((e) => CardMenuData(e.label, num.parse(e.value ?? '0'))).toList();
81
+    notifier.value = (DictService.getDictList(type) ?? []).map((e) => CardMenuData(e.label, num.parse(e.value ?? '0'))).toList();
81 82
     // 选中项
82 83
     DictRsp? dict = DictService.getDict(type, value: selValue);
83 84
     if (dict != null) selNotifier.value = CardMenuData(dict.label, dict.value);
84 85
   }
85 86
 
87
+  /// 校验数据
88
+  bool verifyData() {
89
+    return true;
90
+  }
91
+
92
+  @override
93
+  bool get wantKeepAlive => true;
94
+
86 95
   @override
87 96
   void onInit() {
88 97
     data = widget.data;
89 98
     isDetail = widget.detail;
99
+    widget.ctrl.verifyData = verifyData;
90 100
 
91 101
     // 工厂排污
92 102
     setBoolMenuSelNotifier(zztdzwsfygcpw, data?.zztdzwsfygcpw);
@@ -115,9 +125,6 @@ class _ReapSampleDisasterDetailPageState extends BaseLifecycleState<ReapSampleDi
115 125
   }
116 126
 
117 127
   @override
118
-  bool get wantKeepAlive => true;
119
-
120
-  @override
121 128
   Widget build(BuildContext context) {
122 129
     super.build(context);
123 130
     return SingleChildScrollView(child: buildList());

+ 13 - 5
lib/page/sample_task/reap_sample_detail/reap_sample_medicine_detail_page.dart

@@ -6,24 +6,26 @@ import '../../../model/rsp/sample_task_rsp.dart';
6 6
 import '../../../utils/date_time_utils.dart';
7 7
 import '../../../utils/input_formatter.dart';
8 8
 import '../../../widget/button.dart';
9
+import 'reap_sample_task_page.dart';
9 10
 
10 11
 /// 收获扦样-用药情况
11 12
 class ReapSampleMedicineDetailPage extends StatefulWidget {
12 13
   final SampleTaskItem? data;
13 14
   final bool detail;
15
+  final ReapSampleTaskController ctrl;
14 16
 
15 17
   const ReapSampleMedicineDetailPage(
16 18
     this.data, {
17 19
     super.key,
18 20
     this.detail = true,
21
+    required this.ctrl,
19 22
   });
20 23
 
21 24
   @override
22 25
   State<ReapSampleMedicineDetailPage> createState() => _ReapSampleMedicineDetailPageState();
23 26
 }
24 27
 
25
-class _ReapSampleMedicineDetailPageState extends BaseLifecycleState<ReapSampleMedicineDetailPage>
26
-    with AutomaticKeepAliveClientMixin {
28
+class _ReapSampleMedicineDetailPageState extends BaseLifecycleState<ReapSampleMedicineDetailPage> with AutomaticKeepAliveClientMixin {
27 29
   SampleTaskItem? data;
28 30
   late bool isDetail;
29 31
 
@@ -74,16 +76,22 @@ class _ReapSampleMedicineDetailPageState extends BaseLifecycleState<ReapSampleMe
74 76
     }
75 77
   }
76 78
 
79
+  /// 校验数据
80
+  bool verifyData() {
81
+    return true;
82
+  }
83
+
84
+  @override
85
+  bool get wantKeepAlive => true;
86
+
77 87
   @override
78 88
   void onInit() {
79 89
     data = widget.data;
80 90
     isDetail = widget.detail;
91
+    widget.ctrl.verifyData = verifyData;
81 92
   }
82 93
 
83 94
   @override
84
-  bool get wantKeepAlive => true;
85
-
86
-  @override
87 95
   Widget build(BuildContext context) {
88 96
     super.build(context);
89 97
     return SingleChildScrollView(child: buildList());

+ 16 - 7
lib/page/sample_task/reap_sample_detail/reap_sample_org_detail_page.dart

@@ -3,17 +3,20 @@ import 'package:lszlgl/base/base_lifecycle_state.dart';
3 3
 import 'package:lszlgl/widget/card_item.dart';
4 4
 
5 5
 import '../../../model/rsp/sample_task_rsp.dart';
6
+import 'reap_sample_task_page.dart';
6 7
 
7 8
 /// 收获扦样-检验机构
8 9
 class ReapSampleOrgDetailPage extends StatefulWidget {
9 10
   final SampleTaskItem? data;
10 11
   final bool detail;
12
+  final ReapSampleTaskController ctrl;
11 13
 
12 14
   const ReapSampleOrgDetailPage(
13
-      this.data, {
14
-        super.key,
15
-        this.detail = true,
16
-      });
15
+    this.data, {
16
+    super.key,
17
+    this.detail = true,
18
+    required this.ctrl,
19
+  });
17 20
 
18 21
   @override
19 22
   State<ReapSampleOrgDetailPage> createState() => _ReapSampleOrgDetailPageState();
@@ -27,9 +30,18 @@ class _ReapSampleOrgDetailPageState extends BaseLifecycleState<ReapSampleOrgDeta
27 30
   String? aqjg;
28 31
   String? aqdz;
29 32
 
33
+  /// 校验数据
34
+  bool verifyData() {
35
+    return true;
36
+  }
37
+
38
+  @override
39
+  bool get wantKeepAlive => true;
40
+
30 41
   @override
31 42
   void onInit() {
32 43
     data = widget.data;
44
+    widget.ctrl.verifyData = verifyData;
33 45
     var list = data?.jyjgxxRespVOList;
34 46
     if (list != null && list.isNotEmpty) {
35 47
       for (JyjgxxItem item in list) {
@@ -45,9 +57,6 @@ class _ReapSampleOrgDetailPageState extends BaseLifecycleState<ReapSampleOrgDeta
45 57
   }
46 58
 
47 59
   @override
48
-  bool get wantKeepAlive => true;
49
-
50
-  @override
51 60
   Widget build(BuildContext context) {
52 61
     super.build(context);
53 62
     return SingleChildScrollView(child: buildList());

+ 18 - 5
lib/page/sample_task/reap_sample_detail/reap_sample_task_page.dart

@@ -37,6 +37,10 @@ class ReapSampleTaskPageArgs {
37 37
   }
38 38
 }
39 39
 
40
+class ReapSampleTaskController {
41
+  bool Function()? verifyData;
42
+}
43
+
40 44
 /// 收获扦样任务
41 45
 class ReapSampleTaskPage extends StatefulWidget {
42 46
   final ReapSampleTaskPageArgs args;
@@ -60,6 +64,7 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
60 64
   late PageController pageCtrl;
61 65
 
62 66
   late List<String> tabTextList;
67
+  late List<ReapSampleTaskController> ctrlList;
63 68
   late List<Widget> pageList;
64 69
 
65 70
   ValueNotifier<int> tabIndex = ValueNotifier(0);
@@ -83,6 +88,13 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
83 88
   }
84 89
 
85 90
   void submit() async {
91
+    // 空值判断
92
+    for (int i = 0; i < ctrlList.length; i++) {
93
+      if (!(ctrlList[i].verifyData?.call() ?? true)) {
94
+        pageCtrl.jumpToPage(i);
95
+        return;
96
+      }
97
+    }
86 98
     SampleTaskItem req = (pageStatus.value.data ?? SampleTaskItem());
87 99
     // 去签名
88 100
     var args = SignaturePageArgs(count: req.dgryName?.split(',').length ?? 0);
@@ -135,11 +147,11 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
135 147
 
136 148
   void cratePageList(SampleTaskItem data) {
137 149
     pageList = [
138
-      ReapSampleBasicDetailPage(data, detail: args.detail),
139
-      ReapSampleVarietyDetailPage(data, detail: args.detail),
140
-      ReapSampleDisasterDetailPage(data, detail: args.detail),
141
-      ReapSampleMedicineDetailPage(data, detail: args.detail),
142
-      ReapSampleOrgDetailPage(data, detail: args.detail),
150
+      ReapSampleBasicDetailPage(data, detail: args.detail, ctrl: ctrlList[0]),
151
+      ReapSampleVarietyDetailPage(data, detail: args.detail, ctrl: ctrlList[1]),
152
+      ReapSampleDisasterDetailPage(data, detail: args.detail, ctrl: ctrlList[2]),
153
+      ReapSampleMedicineDetailPage(data, detail: args.detail, ctrl: ctrlList[3]),
154
+      ReapSampleOrgDetailPage(data, detail: args.detail, ctrl: ctrlList[4]),
143 155
     ];
144 156
   }
145 157
 
@@ -222,6 +234,7 @@ class _ReapSampleTaskPageState extends BaseLifecycleState<ReapSampleTaskPage> wi
222 234
     super.initState();
223 235
     args = widget.args;
224 236
     tabTextList = ['基础信息', '品种信息', '灾害污染', '用药情况', '检验机构'];
237
+    ctrlList = tabTextList.map((e) => ReapSampleTaskController()).toList();
225 238
     pageCtrl = PageController();
226 239
   }
227 240
 

+ 13 - 5
lib/page/sample_task/reap_sample_detail/reap_sample_variety_detail_page.dart

@@ -10,24 +10,26 @@ import '../../../network/my_api.dart';
10 10
 import '../../../utils/date_time_utils.dart';
11 11
 import '../../../utils/input_formatter.dart';
12 12
 import '../../../widget/button.dart';
13
+import 'reap_sample_task_page.dart';
13 14
 
14 15
 /// 收获扦样-品种信息
15 16
 class ReapSampleVarietyDetailPage extends StatefulWidget {
16 17
   final SampleTaskItem? data;
17 18
   final bool detail;
19
+  final ReapSampleTaskController ctrl;
18 20
 
19 21
   const ReapSampleVarietyDetailPage(
20 22
     this.data, {
21 23
     super.key,
22 24
     this.detail = true,
25
+    required this.ctrl,
23 26
   });
24 27
 
25 28
   @override
26 29
   State<ReapSampleVarietyDetailPage> createState() => _ReapSampleVarietyDetailPageState();
27 30
 }
28 31
 
29
-class _ReapSampleVarietyDetailPageState extends BaseLifecycleState<ReapSampleVarietyDetailPage>
30
-    with AutomaticKeepAliveClientMixin {
32
+class _ReapSampleVarietyDetailPageState extends BaseLifecycleState<ReapSampleVarietyDetailPage> with AutomaticKeepAliveClientMixin {
31 33
   SampleTaskItem? data;
32 34
   late bool isDetail;
33 35
   late Widget arrowDown;
@@ -134,10 +136,19 @@ class _ReapSampleVarietyDetailPageState extends BaseLifecycleState<ReapSampleVar
134 136
     }
135 137
   }
136 138
 
139
+  /// 校验数据
140
+  bool verifyData() {
141
+    return true;
142
+  }
143
+
144
+  @override
145
+  bool get wantKeepAlive => true;
146
+
137 147
   @override
138 148
   void onInit() {
139 149
     data = widget.data;
140 150
     isDetail = widget.detail;
151
+    widget.ctrl.verifyData = verifyData;
141 152
     arrowDown = Image.asset(imgItemArrowDown, width: 20, color: const Color(0xFF01B2C8));
142 153
 
143 154
     // 粮食品类菜单数据
@@ -169,9 +180,6 @@ class _ReapSampleVarietyDetailPageState extends BaseLifecycleState<ReapSampleVar
169 180
   }
170 181
 
171 182
   @override
172
-  bool get wantKeepAlive => true;
173
-
174
-  @override
175 183
   Widget build(BuildContext context) {
176 184
     super.build(context);
177 185
     return SingleChildScrollView(child: buildList());