|
@@ -1,5 +1,9 @@
|
1
|
1
|
import 'package:flutter/material.dart';
|
|
2
|
+import 'package:flutter/services.dart';
|
|
3
|
+import 'package:lszlgl/config/colors.dart';
|
|
4
|
+import 'package:lszlgl/utils/input_formatter.dart';
|
2
|
5
|
import '../../../base/base_lifecycle_state.dart';
|
|
6
|
+import '../../../model/rsp/dict_rsp.dart';
|
3
|
7
|
import '../../../model/rsp/sample_task_rsp.dart';
|
4
|
8
|
import '../../../network/my_api.dart';
|
5
|
9
|
import '../../../service/dict_service.dart';
|
|
@@ -9,20 +13,19 @@ import '../../../widget/card_item.dart';
|
9
|
13
|
class ReapSampleBasicDetailPage extends StatefulWidget {
|
10
|
14
|
final SampleTaskItem? data;
|
11
|
15
|
final bool detail;
|
12
|
|
- final VoidCallback? nextCallback;
|
13
|
16
|
|
14
|
17
|
const ReapSampleBasicDetailPage(
|
15
|
18
|
this.data, {
|
16
|
19
|
super.key,
|
17
|
20
|
this.detail = true,
|
18
|
|
- this.nextCallback,
|
19
|
21
|
});
|
20
|
22
|
|
21
|
23
|
@override
|
22
|
24
|
State<ReapSampleBasicDetailPage> createState() => _ReapSampleBasicDetailPageState();
|
23
|
25
|
}
|
24
|
26
|
|
25
|
|
-class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasicDetailPage> with AutomaticKeepAliveClientMixin {
|
|
27
|
+class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasicDetailPage>
|
|
28
|
+ with AutomaticKeepAliveClientMixin {
|
26
|
29
|
SampleTaskItem? data;
|
27
|
30
|
late bool isDetail;
|
28
|
31
|
|
|
@@ -37,9 +40,11 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
37
|
40
|
final xian = null.notifier<CardMenuData?>();
|
38
|
41
|
final cun = null.notifier<CardMenuData?>();
|
39
|
42
|
|
40
|
|
- final dllx = null.notifier<CardMenuData?>();
|
|
43
|
+ final trxxList = <CardMenuData>[].notifier<List<CardMenuData>>();
|
|
44
|
+ final trxx = null.notifier<CardMenuData?>();
|
41
|
45
|
|
42
|
|
- Future<void> districtList(num level, {num? id}) async {
|
|
46
|
+ /// 获取行政区划列表
|
|
47
|
+ Future<void> getDistrictList(num level, {num? id}) async {
|
43
|
48
|
MyNavigator.showLoading();
|
44
|
49
|
try {
|
45
|
50
|
var rsp = await MyApi.get().districtList(level, id: id);
|
|
@@ -59,7 +64,32 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
59
|
64
|
MyNavigator.dismissLoading();
|
60
|
65
|
}
|
61
|
66
|
|
62
|
|
- void onSelect(ValueNotifier<CardMenuData?> selNotifier, CardMenuData selData) {
|
|
67
|
+ /// 获取土壤信息列表
|
|
68
|
+ Future<void> getTrxxList() async {
|
|
69
|
+ MyNavigator.showLoading();
|
|
70
|
+ try {
|
|
71
|
+ var rsp = await MyApi.get().trxxList();
|
|
72
|
+ List<CardMenuData> list = [];
|
|
73
|
+ if (rsp.data != null) {
|
|
74
|
+ for (TrxxRsp item in rsp.data!) {
|
|
75
|
+ var menuData = CardMenuData(item.tlmc, item.id);
|
|
76
|
+ list.add(menuData);
|
|
77
|
+ // 选中
|
|
78
|
+ if (item.id == data?.trdllx) trxx.value = menuData;
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+ trxxList.value = list;
|
|
82
|
+ } catch (e) {}
|
|
83
|
+ MyNavigator.dismissLoading();
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ /// 选中土壤信息
|
|
87
|
+ void onSelectTrxx(ValueNotifier<CardMenuData?> selNotifier, CardMenuData selData) {
|
|
88
|
+ data?.trdllx = selData.value;
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ /// 选中行政区划
|
|
92
|
+ void onSelectXzqh(ValueNotifier<CardMenuData?> selNotifier, CardMenuData selData) {
|
63
|
93
|
num level = 100;
|
64
|
94
|
if (selNotifier == sheng) {
|
65
|
95
|
level = 1;
|
|
@@ -124,7 +154,7 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
124
|
154
|
}
|
125
|
155
|
if (level < 5) {
|
126
|
156
|
// 获取下一个等级的菜单数据
|
127
|
|
- districtList(level + 1, id: selData.value ?? 0);
|
|
157
|
+ getDistrictList(level + 1, id: selData.value ?? 0);
|
128
|
158
|
}
|
129
|
159
|
}
|
130
|
160
|
|
|
@@ -137,22 +167,22 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
137
|
167
|
if (data?.cun != null) cun.value = CardMenuData(data?.cun, data?.cunXzqh);
|
138
|
168
|
|
139
|
169
|
// 省
|
140
|
|
- districtList(1);
|
|
170
|
+ getDistrictList(1);
|
141
|
171
|
// 市
|
142
|
172
|
if (data?.shengXzqh != null) {
|
143
|
|
- districtList(2, id: data?.shengXzqh);
|
|
173
|
+ getDistrictList(2, id: data?.shengXzqh);
|
144
|
174
|
}
|
145
|
175
|
// 区
|
146
|
176
|
if (data?.shiXzqh != null) {
|
147
|
|
- districtList(3, id: data?.shiXzqh);
|
|
177
|
+ getDistrictList(3, id: data?.shiXzqh);
|
148
|
178
|
}
|
149
|
179
|
// 县
|
150
|
180
|
if (data?.quXzqh != null) {
|
151
|
|
- districtList(4, id: data?.quXzqh);
|
|
181
|
+ getDistrictList(4, id: data?.quXzqh);
|
152
|
182
|
}
|
153
|
183
|
// 村
|
154
|
184
|
if (data?.xiangXzqh != null) {
|
155
|
|
- districtList(5, id: data?.xiangXzqh);
|
|
185
|
+ getDistrictList(5, id: data?.xiangXzqh);
|
156
|
186
|
}
|
157
|
187
|
}
|
158
|
188
|
|
|
@@ -163,6 +193,10 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
163
|
193
|
void onInit() {
|
164
|
194
|
data = widget.data;
|
165
|
195
|
isDetail = widget.detail;
|
|
196
|
+ // 土壤信息
|
|
197
|
+ getTrxxList();
|
|
198
|
+
|
|
199
|
+ // 编辑数据
|
166
|
200
|
if (!isDetail) {
|
167
|
201
|
getEditData();
|
168
|
202
|
}
|
|
@@ -199,19 +233,19 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
199
|
233
|
),
|
200
|
234
|
isDetail
|
201
|
235
|
? CardItemWidget('省份', rightText: data?.sheng, bottomLine: true)
|
202
|
|
- : CardItemMenuWidget('省份', shengList, sheng, onSelectTap: onSelect, bottomLine: true),
|
|
236
|
+ : CardItemMenuWidget('省份', shengList, sheng, onSelectTap: onSelectXzqh, bottomLine: true),
|
203
|
237
|
isDetail
|
204
|
238
|
? CardItemWidget('市区', rightText: data?.shi, bottomLine: true)
|
205
|
|
- : CardItemMenuWidget('市区', shiList, shi, onSelectTap: onSelect, bottomLine: true),
|
|
239
|
+ : CardItemMenuWidget('市区', shiList, shi, onSelectTap: onSelectXzqh, bottomLine: true),
|
206
|
240
|
isDetail
|
207
|
241
|
? CardItemWidget('区县', rightText: data?.qu, bottomLine: true)
|
208
|
|
- : CardItemMenuWidget('区县', quList, qu, onSelectTap: onSelect, bottomLine: true),
|
|
242
|
+ : CardItemMenuWidget('区县', quList, qu, onSelectTap: onSelectXzqh, bottomLine: true),
|
209
|
243
|
isDetail
|
210
|
244
|
? CardItemWidget('乡镇', rightText: data?.xian, bottomLine: true)
|
211
|
|
- : CardItemMenuWidget('乡镇', xianList, xian, onSelectTap: onSelect, bottomLine: true),
|
|
245
|
+ : CardItemMenuWidget('乡镇', xianList, xian, onSelectTap: onSelectXzqh, bottomLine: true),
|
212
|
246
|
isDetail
|
213
|
247
|
? CardItemWidget('村', rightText: data?.cun, bottomLine: true)
|
214
|
|
- : CardItemMenuWidget('村', cunList, cun, onSelectTap: onSelect, bottomLine: true),
|
|
248
|
+ : CardItemMenuWidget('村', cunList, cun, onSelectTap: onSelectXzqh, bottomLine: true),
|
215
|
249
|
CardItemWidget(
|
216
|
250
|
'扦样地点经纬度',
|
217
|
251
|
rightText: data?.qyddjwd,
|
|
@@ -219,25 +253,68 @@ class _ReapSampleBasicDetailPageState extends BaseLifecycleState<ReapSampleBasic
|
219
|
253
|
),
|
220
|
254
|
CardItemWidget(
|
221
|
255
|
'种植面积(亩地)',
|
222
|
|
- rightText: data?.zzmj?.toString(),
|
223
|
|
- bottomLine: true,
|
224
|
|
- ),
|
225
|
|
- CardItemWidget(
|
226
|
|
- '土壤地理类型',
|
227
|
|
- rightText: DictService.getLabel(DictType.jclb, value: data?.trdllx),
|
|
256
|
+ rightText: isDetail ? data?.zzmj?.toString() : null,
|
|
257
|
+ rightChild: isDetail
|
|
258
|
+ ? null
|
|
259
|
+ : buildField(
|
|
260
|
+ text: data?.zzmj?.toString(),
|
|
261
|
+ inputType: const TextInputType.numberWithOptions(decimal: true),
|
|
262
|
+ formatters: [XNumberTextInputFormatter()],
|
|
263
|
+ onChanged: (value) => data?.zzmj = value.isEmpty ? null : num.parse(value),
|
|
264
|
+ ),
|
228
|
265
|
bottomLine: true,
|
229
|
266
|
),
|
|
267
|
+ isDetail
|
|
268
|
+ ? trxx.builder((v) => CardItemWidget('土壤地理类型', rightText: v?.name ?? '', bottomLine: true))
|
|
269
|
+ : CardItemMenuWidget('土壤地理类型', trxxList, trxx, onSelectTap: onSelectTrxx, bottomLine: true),
|
230
|
270
|
CardItemWidget(
|
231
|
271
|
'被调查农户或合作社',
|
232
|
|
- rightText: data?.bdcnhhhzs,
|
|
272
|
+ rightText: isDetail ? data?.bdcnhhhzs : null,
|
|
273
|
+ rightChild: isDetail
|
|
274
|
+ ? null
|
|
275
|
+ : buildField(
|
|
276
|
+ text: data?.bdcnhhhzs,
|
|
277
|
+ onChanged: (value) => data?.bdcnhhhzs = value,
|
|
278
|
+ ),
|
233
|
279
|
bottomLine: true,
|
234
|
280
|
),
|
235
|
281
|
CardItemWidget(
|
236
|
282
|
'联系方式',
|
237
|
|
- rightText: data?.lxfs,
|
|
283
|
+ rightText: isDetail ? data?.lxfs : null,
|
|
284
|
+ rightChild: isDetail
|
|
285
|
+ ? null
|
|
286
|
+ : buildField(
|
|
287
|
+ text: data?.lxfs,
|
|
288
|
+ onChanged: (value) => data?.lxfs = value,
|
|
289
|
+ ),
|
238
|
290
|
bottomLine: true,
|
239
|
291
|
),
|
240
|
292
|
],
|
241
|
293
|
);
|
242
|
294
|
}
|
|
295
|
+
|
|
296
|
+ Widget buildField({
|
|
297
|
+ String? text,
|
|
298
|
+ String? hint = '点击填写',
|
|
299
|
+ TextInputType? inputType,
|
|
300
|
+ ValueChanged<String>? onChanged,
|
|
301
|
+ List<TextInputFormatter>? formatters,
|
|
302
|
+ }) {
|
|
303
|
+ return TextField(
|
|
304
|
+ controller: TextEditingController(text: text),
|
|
305
|
+ keyboardType: inputType,
|
|
306
|
+ textAlign: TextAlign.right,
|
|
307
|
+ decoration: InputDecoration(
|
|
308
|
+ hintText: hint,
|
|
309
|
+ hintStyle: const TextStyle(color: MyColor.c_666666, fontSize: 14),
|
|
310
|
+ border: InputBorder.none,
|
|
311
|
+ contentPadding: EdgeInsets.zero,
|
|
312
|
+ isDense: true,
|
|
313
|
+ ),
|
|
314
|
+ style: const TextStyle(color: Color(0xFF01B2C8), fontSize: 14, fontWeight: FontWeight.w500),
|
|
315
|
+ textInputAction: TextInputAction.next,
|
|
316
|
+ inputFormatters: formatters,
|
|
317
|
+ onChanged: onChanged,
|
|
318
|
+ );
|
|
319
|
+ }
|
243
|
320
|
}
|