overtime_detail_page.dart 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import '../../core/theme/app_colors.dart';
  4. import '../../core/utils/date_utils.dart' as du;
  5. import '../../core/utils/responsive.dart';
  6. import '../../shared/models/approval_status.dart';
  7. import '../../shared/widgets/form_section.dart';
  8. import '../../shared/widgets/form_field_row.dart';
  9. import '../../shared/widgets/status_tag.dart';
  10. import 'overtime_model.dart';
  11. final overtimeDetailProvider = FutureProvider.autoDispose.family<OvertimeModel, String>((ref, id) async {
  12. return OvertimeModel(
  13. id: id,
  14. applicationNo: 'OT202605001',
  15. applicantId: 'u-001',
  16. applicantName: '张三',
  17. deptId: 'dept-001',
  18. deptName: '市场部',
  19. otDate: DateTime(2026, 5, 20),
  20. startTime: DateTime(2026, 5, 20, 18, 0),
  21. endTime: DateTime(2026, 5, 20, 21, 0),
  22. otHours: 3.0,
  23. otType: '工作日加班',
  24. compensationType: '加班费',
  25. reason: '项目上线前紧急测试',
  26. status: 'pending',
  27. createTime: DateTime(2026, 5, 20),
  28. updateTime: DateTime(2026, 5, 20),
  29. approvalRecords: [
  30. ApprovalRecord(
  31. id: 'ar-ot-001',
  32. bizId: id,
  33. bizType: 'overtime',
  34. approverId: 'u-mgr',
  35. approverName: '李四',
  36. approvalLevel: 1,
  37. action: 'pending',
  38. opinion: '',
  39. approvalTime: DateTime(2026, 5, 20),
  40. ),
  41. ],
  42. );
  43. });
  44. class OvertimeDetailPage extends ConsumerWidget {
  45. final String id;
  46. const OvertimeDetailPage({super.key, required this.id});
  47. @override
  48. Widget build(BuildContext context, WidgetRef ref) {
  49. final detailAsync = ref.watch(overtimeDetailProvider(id));
  50. final r = ResponsiveHelper.of(context);
  51. return Scaffold(
  52. appBar: AppBar(title: const Text('加班详情')),
  53. body: detailAsync.when(
  54. loading: () => const Center(child: CircularProgressIndicator()),
  55. error: (_, __) => const Center(child: Text('加载失败')),
  56. data: (o) => Align(alignment: Alignment.topCenter,
  57. child: ConstrainedBox(
  58. constraints: BoxConstraints(maxWidth: r.detailTwoColumns ? 700 : double.infinity),
  59. child: SingleChildScrollView(
  60. padding: const EdgeInsets.symmetric(vertical: 8),
  61. child: FormSection(
  62. title: '加班信息',
  63. children: [
  64. FormFieldRow(label: '申请单号', value: o.applicationNo, showArrow: false),
  65. FormFieldRow(label: '加班类型', value: o.otType, showArrow: false),
  66. FormFieldRow(label: '补偿方式', value: o.compensationType, showArrow: false),
  67. FormFieldRow(label: '开始时间', value: du.DateUtils.formatDateTime(o.startTime), showArrow: false),
  68. FormFieldRow(label: '结束时间', value: du.DateUtils.formatDateTime(o.endTime), showArrow: false),
  69. FormFieldRow(label: '预估工时', value: '${o.otHours.toStringAsFixed(1)}h', showArrow: false),
  70. FormFieldRow(label: '部门', value: o.deptName, showArrow: false),
  71. FormFieldRow(label: '申请人', value: o.applicantName, showArrow: false),
  72. FormFieldRow(label: '创建时间', value: du.DateUtils.formatDateTime(o.createTime), showArrow: false),
  73. Padding(
  74. padding: const EdgeInsets.fromLTRB(14, 0, 14, 12),
  75. child: Row(
  76. children: [
  77. const SizedBox(width: 72, child: Text('状态', style: TextStyle(color: AppColors.textSecondary, fontSize: 13))),
  78. StatusTag(status: o.status),
  79. ],
  80. ),
  81. ),
  82. FormFieldRow(label: '加班事由', value: o.reason.isEmpty ? '-' : o.reason, showArrow: false),
  83. ],
  84. ),
  85. ),
  86. ),
  87. ),
  88. ),
  89. );
  90. }
  91. }