| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  | import 'package:flutter/cupertino.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | import 'package:intl/intl.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/ItemWidgetFactory.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/custom_button.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/date_picker_dialog.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/photo_picker_row.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/toast_util.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/http/ApiService.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/pages/home/tap/item_list_widget.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/pages/my_appbar.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/tools/tools.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ImmediatelyInspection extends StatefulWidget { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |   const ImmediatelyInspection(this.id, {super.key}); | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   final String id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<ImmediatelyInspection> createState() => _ImmediatelyInspectionState(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _ImmediatelyInspectionState extends State<ImmediatelyInspection> { | 
					
						
							|  |  |  |   final TextEditingController _xunController = TextEditingController(); | 
					
						
							|  |  |  |   final TextEditingController _neiRongController = TextEditingController(); | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |   // 是否有故障
 | 
					
						
							|  |  |  |   bool _isFault = false; | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |   String dataTime = ""; | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   List<String> _guZhangImages = []; | 
					
						
							|  |  |  |   List<String> _xiuGaiImages = []; | 
					
						
							|  |  |  |   List<String> _xunJianImages = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   List<String> allImagePaths = []; | 
					
						
							|  |  |  |   List<String> allImageTypes = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |       appBar: MyAppbar(title: "开始巡检"), | 
					
						
							|  |  |  |       body: ListView( | 
					
						
							|  |  |  |         children: [ | 
					
						
							|  |  |  |           Container( | 
					
						
							|  |  |  |             color: Colors.white, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             child: Column( | 
					
						
							|  |  |  |               children: [ | 
					
						
							|  |  |  |                 ItemListWidget.singleLineTitleText( | 
					
						
							|  |  |  |                   label: '巡检人:', | 
					
						
							|  |  |  |                   isEditable: true, | 
					
						
							| 
									
										
										
										
											2025-09-08 15:11:24 +08:00
										 |  |  |                   isRequired: true, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |                   controller: _xunController, | 
					
						
							|  |  |  |                   hintText: '请输入巡检人', | 
					
						
							|  |  |  |                   text: '', | 
					
						
							|  |  |  |                 ), | 
					
						
							|  |  |  |                 const Divider(), | 
					
						
							|  |  |  |                 Padding( | 
					
						
							|  |  |  |                   padding: EdgeInsets.symmetric(horizontal: 12, vertical: 10), | 
					
						
							|  |  |  |                   child: GestureDetector( | 
					
						
							|  |  |  |                     child: ItemListWidget.selectableLineTitleTextRightButton( | 
					
						
							|  |  |  |                       label: '巡检日期', | 
					
						
							|  |  |  |                       text: dataTime.isEmpty ? '请选择' : dataTime ?? '', | 
					
						
							|  |  |  |                       isEditable: true, | 
					
						
							| 
									
										
										
										
											2025-09-08 15:11:24 +08:00
										 |  |  |                       isRequired: true, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |                       horizontalnum: 0, | 
					
						
							|  |  |  |                     ), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |                     onTap: () async { | 
					
						
							|  |  |  |                       showDialog( | 
					
						
							|  |  |  |                         context: context, | 
					
						
							|  |  |  |                         builder: | 
					
						
							|  |  |  |                             (_) => HDatePickerDialog( | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |                               initialDate: DateTime.now(), | 
					
						
							|  |  |  |                               onCancel: () => Navigator.of(context).pop(), | 
					
						
							|  |  |  |                               onConfirm: (selected) { | 
					
						
							|  |  |  |                                 Navigator.of(context).pop(); | 
					
						
							|  |  |  |                                 setState(() { | 
					
						
							|  |  |  |                                   dataTime = DateFormat( | 
					
						
							|  |  |  |                                     'yyyy-MM-dd', | 
					
						
							|  |  |  |                                   ).format(selected); | 
					
						
							|  |  |  |                                 }); | 
					
						
							|  |  |  |                               }, | 
					
						
							|  |  |  |                             ), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |                       ); | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                   ), | 
					
						
							|  |  |  |                   // ListItemFactory.createRowSpaceBetweenItem(
 | 
					
						
							|  |  |  |                   //   leftText: "巡检日期",
 | 
					
						
							|  |  |  |                   //   rightText: dataTime.isEmpty?"请选择":dataTime,
 | 
					
						
							|  |  |  |                   //   isRight: true,
 | 
					
						
							|  |  |  |                   // ),
 | 
					
						
							|  |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |               ], | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           SizedBox(height: 15), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |           Container( | 
					
						
							|  |  |  |             color: Colors.white, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             child: ItemListWidget.multiLineTitleTextField( | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |               label: '巡检内容:', | 
					
						
							|  |  |  |               isEditable: true, | 
					
						
							| 
									
										
										
										
											2025-09-08 15:11:24 +08:00
										 |  |  |               isRequired: true, | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |               controller: _neiRongController, | 
					
						
							|  |  |  |               hintText: "(必填)", | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |               text: '', | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           SizedBox(height: 15), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |           ListItemFactory.createYesNoSection( | 
					
						
							|  |  |  |             title: '是否有故障', | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             horizontalPadding: 2, | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |             groupValue: _isFault, | 
					
						
							|  |  |  |             onChanged: (val) { | 
					
						
							|  |  |  |               setState(() { | 
					
						
							|  |  |  |                 _isFault = val; | 
					
						
							|  |  |  |               }); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // if(_isFault)
 | 
					
						
							|  |  |  |           // SizedBox(height: 15,),
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           if (_isFault) | 
					
						
							|  |  |  |             RepairedPhotoSection( | 
					
						
							| 
									
										
										
										
											2025-09-08 15:11:24 +08:00
										 |  |  |               isRequired: true, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |               horizontalPadding: 15, | 
					
						
							|  |  |  |               title: "故障照片", | 
					
						
							|  |  |  |               maxCount: 4, | 
					
						
							|  |  |  |               mediaType: MediaType.image, | 
					
						
							|  |  |  |               onMediaAdded: (value) { | 
					
						
							|  |  |  |                 _guZhangImages.add(value); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               onMediaRemoved: (value) { | 
					
						
							|  |  |  |                 _guZhangImages.remove(value); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               onChanged: (files) {}, | 
					
						
							|  |  |  |               onAiIdentify: () {}, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           SizedBox(height: _isFault ? 15 : 0), | 
					
						
							|  |  |  |           if (_isFault) | 
					
						
							|  |  |  |             RepairedPhotoSection( | 
					
						
							| 
									
										
										
										
											2025-09-08 15:11:24 +08:00
										 |  |  |               isRequired: true, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |               horizontalPadding: 15, | 
					
						
							|  |  |  |               title: "故障处理后照片", | 
					
						
							|  |  |  |               maxCount: 4, | 
					
						
							|  |  |  |               mediaType: MediaType.image, | 
					
						
							|  |  |  |               onMediaAdded: (value) { | 
					
						
							|  |  |  |                 _xiuGaiImages.add(value); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               onMediaRemoved: (value) { | 
					
						
							|  |  |  |                 _xiuGaiImages.remove(value); | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               onChanged: (files) {}, | 
					
						
							|  |  |  |               onAiIdentify: () {}, | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           SizedBox(height: _isFault ? 15 : 0), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |           RepairedPhotoSection( | 
					
						
							| 
									
										
										
										
											2025-09-08 15:11:24 +08:00
										 |  |  |             isRequired: true, | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |             horizontalPadding: 15, | 
					
						
							|  |  |  |             title: "巡检照片", | 
					
						
							|  |  |  |             maxCount: 4, | 
					
						
							|  |  |  |             mediaType: MediaType.image, | 
					
						
							|  |  |  |             onMediaAdded: (value) { | 
					
						
							|  |  |  |               _xunJianImages.add(value); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             onMediaRemoved: (value) { | 
					
						
							|  |  |  |               _xunJianImages.remove(value); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             onChanged: (files) {}, | 
					
						
							|  |  |  |             onAiIdentify: () {}, | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |           ), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           SizedBox(height: 25), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |           CustomButton( | 
					
						
							|  |  |  |             text: "提交", | 
					
						
							|  |  |  |             backgroundColor: Colors.blue, | 
					
						
							|  |  |  |             height: 42, | 
					
						
							|  |  |  |             onPressed: () { | 
					
						
							|  |  |  |               _startInspection(); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           SizedBox(height: 25), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Future<void> _startInspection() async { | 
					
						
							|  |  |  |     try { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       String person = _xunController.text.trim(); | 
					
						
							|  |  |  |       if (person.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ToastUtil.showNormal(context, "请填巡检人"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       if (dataTime.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ToastUtil.showNormal(context, "请选择巡检时间"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       String content = _neiRongController.text.trim(); | 
					
						
							|  |  |  |       if (content.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ToastUtil.showNormal(context, "请选巡检内容"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       if (_isFault && _guZhangImages.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ToastUtil.showNormal(context, "请上传故障照片"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       if (_isFault && _xiuGaiImages.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ToastUtil.showNormal(context, "请上传故障处理后照片"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       if (_xunJianImages.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         ToastUtil.showNormal(context, "请上传巡检图片"); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       LoadingDialogHelper.show(message: "提交中..."); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       for (int i = 0; i < _guZhangImages.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         allImagePaths.add(_guZhangImages[i]); | 
					
						
							|  |  |  |         allImageTypes.add("24"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       for (int m = 0; m < _xiuGaiImages.length; m++) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         allImagePaths.add(_xiuGaiImages[m]); | 
					
						
							|  |  |  |         allImageTypes.add("25"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       for (int n = 0; n < _xunJianImages.length; n++) { | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         allImagePaths.add(_xunJianImages[n]); | 
					
						
							|  |  |  |         allImageTypes.add("26"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       final formData = { | 
					
						
							|  |  |  |         'SPECIALEQUIPMENT_ID': widget.id, | 
					
						
							|  |  |  |         'CREATOR': SessionService.instance.username, | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |         'ISFAULT': _isFault ? "是" : "否", | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         'INSPECTOR': person, | 
					
						
							|  |  |  |         'INSPECTIONCONTENT': content, | 
					
						
							|  |  |  |         'INSPECTIONTIME': dataTime, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |         'TYPES': allImageTypes.join(','), | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |         "CORPINFO_ID": SessionService.instance.corpinfoId, | 
					
						
							|  |  |  |         'USER_ID': SessionService.instance.loginUserId, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       final result = await ApiService.startInspection(formData, allImagePaths); | 
					
						
							| 
									
										
										
										
											2025-08-15 17:11:26 +08:00
										 |  |  |       LoadingDialogHelper.hide(); | 
					
						
							|  |  |  |       if (result['result'] == 'success') { | 
					
						
							|  |  |  |         setState(() { | 
					
						
							|  |  |  |           ToastUtil.showNormal(context, "提交成功"); | 
					
						
							|  |  |  |           Navigator.pop(context); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |       LoadingDialogHelper.hide(); | 
					
						
							|  |  |  |       print('Error fetching data: $e'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |