overtime_detail_page.dart 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:go_router/go_router.dart';
  4. import 'package:tdesign_flutter/tdesign_flutter.dart';
  5. import '../../core/theme/app_colors.dart';
  6. import '../../core/utils/date_utils.dart' as du;
  7. import '../../shared/models/user_model.dart';
  8. import '../../shared/widgets/app_card.dart';
  9. import '../../shared/widgets/approval_timeline.dart';
  10. import '../../shared/widgets/approval_actions.dart';
  11. import 'overtime_model.dart';
  12. import 'overtime_list_controller.dart';
  13. class OvertimeDetailPage extends ConsumerWidget {
  14. final String id;
  15. const OvertimeDetailPage({super.key, required this.id});
  16. @override
  17. Widget build(BuildContext context, WidgetRef ref) {
  18. final overtime = mockOvertimes.firstWhere((e) => e.id == id,
  19. orElse: () => mockOvertimes.first);
  20. return Scaffold(
  21. appBar: TDNavBar(
  22. title: '加班详情',
  23. titleColor: Colors.white,
  24. backgroundColor: const Color(0xFF00ABF3),
  25. centerTitle: false,
  26. ),
  27. body: Column(children: [
  28. Expanded(
  29. child: SingleChildScrollView(
  30. padding: const EdgeInsets.all(12),
  31. child: Column(children: [
  32. _buildStatusHeader(overtime),
  33. const SizedBox(height: 12),
  34. _buildInfoSection(overtime),
  35. const SizedBox(height: 12),
  36. if (overtime.approvalRecords.isNotEmpty || overtime.approvalChain.isNotEmpty)
  37. AppCard(
  38. child: ApprovalTimeline(
  39. records: overtime.approvalRecords,
  40. chain: overtime.approvalChain,
  41. currentApproverId: overtime.currentApproverId,
  42. ),
  43. ),
  44. ]),
  45. ),
  46. ),
  47. ApprovalActions(
  48. status: overtime.status,
  49. userRole: UserRole.employee,
  50. onApprove: () {},
  51. onReject: () {},
  52. onEdit: () => context.push('/overtime/apply?id=${overtime.id}'),
  53. onWithdraw: () {},
  54. ),
  55. ]),
  56. );
  57. }
  58. Widget _buildStatusHeader(OvertimeModel overtime) {
  59. final (icon, color, text) = switch (overtime.status) {
  60. 'approved' => (Icons.check_circle, AppColors.success, '已通过'),
  61. 'rejected' => (Icons.cancel, AppColors.error, '已拒绝'),
  62. 'draft' => (Icons.edit, AppColors.textHint, '草稿'),
  63. _ => (Icons.schedule, AppColors.warning, '待审批'),
  64. };
  65. return Container(
  66. padding: const EdgeInsets.all(20),
  67. decoration: BoxDecoration(
  68. color: color.withValues(alpha: 0.08),
  69. borderRadius: BorderRadius.circular(12)),
  70. child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
  71. Icon(icon, color: color, size: 36),
  72. const SizedBox(width: 10),
  73. Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  74. Text(text, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: color)),
  75. if (overtime.status == 'pending')
  76. Text('当前审批人:${overtime.currentApproverId}',
  77. style: const TextStyle(fontSize: 12, color: AppColors.textSecondary)),
  78. ]),
  79. ]),
  80. );
  81. }
  82. Widget _buildInfoSection(OvertimeModel overtime) {
  83. return _buildDetailCard('加班信息', [
  84. TDCell(title: '申请单号', note: overtime.applicationNo, showBottomBorder: true),
  85. TDCell(title: '申请人', note: '${overtime.applicantName} · ${overtime.deptName}', showBottomBorder: true),
  86. TDCell(title: '加班日期', note: du.DateUtils.formatDate(overtime.otDate), showBottomBorder: true),
  87. TDCell(title: '加班时段', note: '${du.DateUtils.formatTime(overtime.startTime)} - ${du.DateUtils.formatTime(overtime.endTime)}', showBottomBorder: true),
  88. TDCell(title: '加班时长', note: '${overtime.otHours.toStringAsFixed(1)}h', showBottomBorder: true),
  89. TDCell(title: '加班类型', note: overtime.otType, showBottomBorder: true),
  90. TDCell(title: '补偿方式', note: overtime.compensationType, showBottomBorder: true),
  91. TDCell(title: '加班原因', note: overtime.reason.isEmpty ? '-' : overtime.reason, showBottomBorder: overtime.remark.isNotEmpty),
  92. if (overtime.remark.isNotEmpty)
  93. TDCell(title: '备注', note: overtime.remark, showBottomBorder: false),
  94. ]);
  95. }
  96. Widget _buildDetailCard(String title, List<Widget> cells) {
  97. return Container(
  98. margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
  99. decoration: BoxDecoration(
  100. color: AppColors.cardWhite,
  101. borderRadius: BorderRadius.circular(10),
  102. boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.04), blurRadius: 4, offset: const Offset(0, 1))],
  103. ),
  104. child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  105. Padding(
  106. padding: const EdgeInsets.fromLTRB(14, 12, 14, 8),
  107. child: Text(title, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: AppColors.textPrimary)),
  108. ),
  109. ...cells,
  110. ]),
  111. );
  112. }
  113. }