Quellcode durchsuchen

fix #19900 #19888 加班申请单、用车申请单

chengc vor 1 Woche
Ursprung
Commit
0b5c8795ec
1 geänderte Dateien mit 43 neuen und 3 gelöschten Zeilen
  1. 43 3
      lib/features/overtime/widgets/overtime_apply_detail_dialog.dart

+ 43 - 3
lib/features/overtime/widgets/overtime_apply_detail_dialog.dart

@@ -411,6 +411,13 @@ class _OvertimeApplyDetailDialogState extends State<OvertimeApplyDetailDialog> {
                           _buildJbDatePicker(colors),
                           const SizedBox(height: 12),
                           _buildStartTimePicker(colors),
+                          if (_startTime.isNotEmpty &&
+                              _endTime.isNotEmpty &&
+                              _startTime.compareTo(_endTime) >= 0)
+                            Padding(
+                              padding: const EdgeInsets.only(top: 8),
+                              child: _buildTimeErrorHint(),
+                            ),
                           const SizedBox(height: 12),
                           _buildEndTimePicker(colors),
                           const SizedBox(height: 12),
@@ -748,7 +755,18 @@ class _OvertimeApplyDetailDialogState extends State<OvertimeApplyDetailDialog> {
       colors: colors,
       required: true,
       showDayOfWeek: true,
-      onPick: (d) => setState(() => _jbDate = d),
+      onPick: (d) {
+        setState(() {
+          _jbDate = d;
+          if (_startTime.isNotEmpty) {
+            _startTime = '$d ${_fmtTime(_startTime)}';
+          }
+          if (_endTime.isNotEmpty) {
+            _endTime = '$d ${_fmtTime(_endTime)}';
+          }
+          _autoCalcHours();
+        });
+      },
     );
   }
 
@@ -807,6 +825,26 @@ class _OvertimeApplyDetailDialogState extends State<OvertimeApplyDetailDialog> {
     );
   }
 
+  Widget _buildTimeErrorHint() {
+    final tdTheme = TDTheme.of(context);
+    return Row(
+      mainAxisAlignment: MainAxisAlignment.end,
+      children: [
+        Icon(
+          Icons.warning_amber_rounded,
+          size: 14,
+          color: tdTheme.warningColor5,
+        ),
+        const SizedBox(width: 4),
+        TDText(
+          _l10n.get('endTimeMustLater'),
+          font: tdTheme.fontBodySmall,
+          textColor: tdTheme.warningColor5,
+        ),
+      ],
+    );
+  }
+
   String _fmtTime(String dt) {
     if (dt.length >= 16) return dt.substring(11, 16);
     return dt;
@@ -816,9 +854,11 @@ class _OvertimeApplyDetailDialogState extends State<OvertimeApplyDetailDialog> {
     if (_startTime.isEmpty || _endTime.isEmpty) return;
     final st = DateTime.tryParse(_startTime);
     final et = DateTime.tryParse(_endTime);
-    if (st == null || et == null || et.isBefore(st)) return;
+    if (st == null || et == null) return;
 
-    final totalHours = et.difference(st).inMinutes / 60.0;
+    double totalHours = et.difference(st).inMinutes / 60.0;
+    // 跨午夜:结束时间早于开始时间 → 加 24 小时
+    if (totalHours < 0) totalHours += 24;
 
     if (totalHours > 0) {
       _hoursCtrl.text = ((totalHours * 2).ceil() / 2.0).toStringAsFixed(1);