| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							|  |  |  | import 'package:intl/intl.dart'; | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  | import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/custom_button.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/date_picker_dialog.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/picker/CupertinoDatePicker.dart'; | 
					
						
							|  |  |  | import 'package:qhd_prevention/customWidget/toast_util.dart'; | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | import 'package:qhd_prevention/pages/my_appbar.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  | import '../../http/ApiService.dart'; | 
					
						
							|  |  |  | import '../../tools/tools.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | class MineDutyApplicationPage extends StatefulWidget { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |   const MineDutyApplicationPage({super.key, required this.onClose}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  |   final Function(String) onClose; // 回调函数
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   State<MineDutyApplicationPage> createState() => _MineDutyApplicationPage(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class _MineDutyApplicationPage extends State<MineDutyApplicationPage> { | 
					
						
							|  |  |  |   DateTime? _startDate; | 
					
						
							|  |  |  |   DateTime? _endDate; | 
					
						
							|  |  |  |   final TextEditingController _reasonController = TextEditingController(); | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Future<void> _submitApplicationLeaving() async { | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       var formatter = DateFormat('yyyy-MM-dd'); // 或者使用 'dd-MM-yyyy' 取决于你的需求
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       String startTime = formatter.format(_startDate!); | 
					
						
							|  |  |  |       String endTime = formatter.format(_endDate!); | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       final result = await ApiService.submitApplicationLeaving( | 
					
						
							|  |  |  |         startTime, | 
					
						
							|  |  |  |         endTime, | 
					
						
							|  |  |  |         _reasonController.text, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  |       if (result['result'] == 'success') { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |         ToastUtil.showSuccess(context, '提交成功'); | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  |         widget.onClose('关闭提交'); // 触发回调
 | 
					
						
							|  |  |  |         Navigator.pop(context); // 关闭页面
 | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |       print('加载出错: $e'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |   Future<void> _selectDate(BuildContext context, bool isStartDate) async { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |     DateTime? picked = await BottomDateTimePicker.showDate( | 
					
						
							|  |  |  |       context, | 
					
						
							|  |  |  |       mode: BottomPickerMode.date, | 
					
						
							|  |  |  |       allowFuture: true, | 
					
						
							|  |  |  |       minTimeStr: '0-0-0 00:00', | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |     if (picked != null) { | 
					
						
							|  |  |  |       setState(() { | 
					
						
							|  |  |  |         if (isStartDate) { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           if (picked.isBefore(DateTime.now().subtract(Duration(days: 1)))) { | 
					
						
							|  |  |  |             ToastUtil.showNormal(context, '开始日期不能早于当前日期'); | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  |             _startDate = picked; | 
					
						
							|  |  |  |             // 如果结束日期早于开始日期,自动更新结束日期
 | 
					
						
							|  |  |  |             if (_endDate == null || _endDate!.isBefore(picked)) { | 
					
						
							|  |  |  |               _endDate = picked; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           if (picked.isBefore(DateTime.now().subtract(Duration(days: 1)))) { | 
					
						
							|  |  |  |             ToastUtil.showNormal(context, '结束日期不能早于当前日期'); | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           } else { | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  |             // 确保结束日期不早于开始日期
 | 
					
						
							|  |  |  |             if (_startDate != null && picked.isBefore(_startDate!)) { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |               ToastUtil.showNormal(context, '结束日期不能早于开始日期'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  |             } else { | 
					
						
							|  |  |  |               _endDate = picked; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |   void _submitApplication() async{ | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |     if (_startDate == null || _endDate == null) { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       ToastUtil.showNormal(context, '请选择离岗时间'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (_reasonController.text.isEmpty) { | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       ToastUtil.showNormal(context, '请输入离岗原因'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |     final ok = await CustomAlertDialog.showConfirm(context, title: '申请提交', content: '您确定提交离岗申请吗?', cancelText: '取消'); | 
					
						
							|  |  |  |     if (ok) { | 
					
						
							|  |  |  |       _submitApplicationLeaving(); | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-07-17 17:58:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   Widget build(BuildContext context) { | 
					
						
							|  |  |  |     return Scaffold( | 
					
						
							|  |  |  |       backgroundColor: const Color(0xFFF5F7FA), | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |       appBar: MyAppbar(title: "离岗申请"), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |       body: SingleChildScrollView( | 
					
						
							|  |  |  |         padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 20), | 
					
						
							|  |  |  |         child: Column( | 
					
						
							|  |  |  |           crossAxisAlignment: CrossAxisAlignment.start, | 
					
						
							|  |  |  |           children: [ | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             // 离岗开始时间
 | 
					
						
							|  |  |  |             _buildDateField( | 
					
						
							|  |  |  |               label: "离岗开始时间", | 
					
						
							|  |  |  |               date: _startDate, | 
					
						
							|  |  |  |               onTap: () => _selectDate(context, true), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             const SizedBox(height: 16), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             // 离岗结束时间
 | 
					
						
							|  |  |  |             _buildDateField( | 
					
						
							|  |  |  |               label: "离岗结束时间", | 
					
						
							|  |  |  |               date: _endDate, | 
					
						
							|  |  |  |               onTap: () => _selectDate(context, false), | 
					
						
							|  |  |  |             ), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             const SizedBox(height: 24), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             // 离岗原因标题
 | 
					
						
							|  |  |  |             const Text( | 
					
						
							|  |  |  |               "离岗原因", | 
					
						
							|  |  |  |               style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             const SizedBox(height: 8), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // 原因输入框
 | 
					
						
							|  |  |  |             Container( | 
					
						
							|  |  |  |               padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 10), | 
					
						
							|  |  |  |               decoration: BoxDecoration( | 
					
						
							|  |  |  |                 color: Colors.white, | 
					
						
							|  |  |  |                 borderRadius: BorderRadius.circular(12), | 
					
						
							|  |  |  |                 boxShadow: [ | 
					
						
							|  |  |  |                   BoxShadow( | 
					
						
							|  |  |  |                     color: Colors.grey.withOpacity(0.1), | 
					
						
							|  |  |  |                     spreadRadius: 1, | 
					
						
							|  |  |  |                     blurRadius: 6, | 
					
						
							|  |  |  |                     offset: const Offset(0, 2), | 
					
						
							|  |  |  |                   ), | 
					
						
							|  |  |  |                 ], | 
					
						
							|  |  |  |               ), | 
					
						
							|  |  |  |               child: TextField( | 
					
						
							|  |  |  |                 controller: _reasonController, | 
					
						
							|  |  |  |                 maxLines: 5, | 
					
						
							|  |  |  |                 decoration: const InputDecoration( | 
					
						
							|  |  |  |                   hintText: "请输入离岗原因", | 
					
						
							|  |  |  |                   hintStyle: TextStyle(color: Color(0xFF9E9E9E)), | 
					
						
							|  |  |  |                   border: InputBorder.none, | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |                 ), | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |               ), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |             ), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             const SizedBox(height: 24), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             // 申请人信息
 | 
					
						
							|  |  |  |             // _buildInfoRow("申请人", _applicant),
 | 
					
						
							|  |  |  |             _buildInfoRow("申请人", SessionService.instance.username.toString()), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |             const SizedBox(height: 40), | 
					
						
							|  |  |  |             CustomButton(text: '提交', backgroundColor: Colors.blue, onPressed: _submitApplication), | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |         ), | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _buildDateField({ | 
					
						
							|  |  |  |     required String label, | 
					
						
							|  |  |  |     required DateTime? date, | 
					
						
							|  |  |  |     required VoidCallback onTap, | 
					
						
							|  |  |  |   }) { | 
					
						
							|  |  |  |     return GestureDetector( | 
					
						
							|  |  |  |       onTap: onTap, | 
					
						
							|  |  |  |       child: Container( | 
					
						
							|  |  |  |         padding: const EdgeInsets.all(16), | 
					
						
							|  |  |  |         decoration: BoxDecoration( | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           color: Colors.white, | 
					
						
							|  |  |  |           borderRadius: BorderRadius.circular(12), | 
					
						
							|  |  |  |           boxShadow: [ | 
					
						
							|  |  |  |             BoxShadow( | 
					
						
							|  |  |  |               color: Colors.grey.withOpacity(0.1), | 
					
						
							|  |  |  |               spreadRadius: 1, | 
					
						
							|  |  |  |               blurRadius: 6, | 
					
						
							|  |  |  |               offset: const Offset(0, 2), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           ], | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |         ), | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |         child: Row( | 
					
						
							|  |  |  |           mainAxisAlignment: MainAxisAlignment.spaceBetween, | 
					
						
							|  |  |  |           children: [ | 
					
						
							|  |  |  |             Text(label, style: const TextStyle(fontSize: 14)), | 
					
						
							|  |  |  |             Text( | 
					
						
							|  |  |  |               date != null ? DateFormat('yyyy-MM-dd').format(date) : "请选择日期", | 
					
						
							|  |  |  |               style: TextStyle( | 
					
						
							|  |  |  |                 fontSize: 14, | 
					
						
							|  |  |  |                 color: date != null ? Colors.black : const Color(0xFF9E9E9E), | 
					
						
							|  |  |  |               ), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |             ), | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |           ], | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Widget _buildInfoRow(String title, String value) { | 
					
						
							|  |  |  |     return Container( | 
					
						
							|  |  |  |       padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), | 
					
						
							|  |  |  |       decoration: BoxDecoration( | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  |         color: Colors.white, | 
					
						
							|  |  |  |         borderRadius: BorderRadius.circular(12), | 
					
						
							|  |  |  |         boxShadow: [ | 
					
						
							|  |  |  |           BoxShadow( | 
					
						
							|  |  |  |             color: Colors.grey.withOpacity(0.1), | 
					
						
							|  |  |  |             spreadRadius: 1, | 
					
						
							|  |  |  |             blurRadius: 6, | 
					
						
							|  |  |  |             offset: const Offset(0, 2), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							|  |  |  |       child: Row( | 
					
						
							|  |  |  |         mainAxisAlignment: MainAxisAlignment.spaceBetween, | 
					
						
							|  |  |  |         children: [ | 
					
						
							|  |  |  |           Text(title, style: const TextStyle(fontSize: 14)), | 
					
						
							|  |  |  |           Text( | 
					
						
							|  |  |  |             value, | 
					
						
							|  |  |  |             style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500), | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ], | 
					
						
							| 
									
										
										
										
											2025-07-16 08:38:10 +08:00
										 |  |  |       ), | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-09-01 17:25:55 +08:00
										 |  |  | } |