overtime_detail_page.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. import '../../shared/widgets/nav_bar_config.dart';
  5. import '../../core/utils/date_utils.dart' as du;
  6. import '../../shared/widgets/status_banner.dart';
  7. import '../../shared/widgets/approval_timeline.dart';
  8. import 'overtime_model.dart';
  9. import '../../core/i18n/app_localizations.dart';
  10. import 'overtime_list_controller.dart';
  11. import '../../core/theme/app_colors.dart';
  12. import '../../core/theme/app_colors_extension.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 colors = Theme.of(context).extension<AppColorsExtension>()!;
  19. final overtime = mockOvertimes.firstWhere(
  20. (e) => e.id == id,
  21. orElse: () => mockOvertimes.first,
  22. );
  23. final l10n = AppLocalizations.of(context);
  24. final (icon, color, statusText) = _statusProps(
  25. overtime.status,
  26. l10n,
  27. colors,
  28. );
  29. setNavBarTitle(context, ref, NavBarConfig(
  30. title: l10n.get('overtimeDetail'),
  31. showBack: true,
  32. onBack: () => context.pop(),
  33. ));
  34. return Column(
  35. children: [
  36. Expanded(
  37. child: SingleChildScrollView(
  38. padding: const EdgeInsets.fromLTRB(16, 16, 16, 32),
  39. child: Column(
  40. crossAxisAlignment: CrossAxisAlignment.start,
  41. children: [
  42. StatusBanner(
  43. icon: icon,
  44. statusText: statusText,
  45. subText: _statusSubText(overtime, l10n),
  46. color: color,
  47. ),
  48. const SizedBox(height: 8),
  49. Text(
  50. '${l10n.get('submitTimeText')}:${du.DateUtils.formatDateTime(overtime.createTime)}',
  51. style: TextStyle(
  52. fontSize: AppFontSizes.caption,
  53. color: colors.textPlaceholder,
  54. ),
  55. ),
  56. const SizedBox(height: 16),
  57. _buildInfoSection(overtime, l10n, colors),
  58. const SizedBox(height: 16),
  59. _buildReasonSection(overtime, l10n, colors),
  60. const SizedBox(height: 16),
  61. if (overtime.approvalRecords.isNotEmpty ||
  62. overtime.approvalChain.isNotEmpty)
  63. Container(
  64. padding: const EdgeInsets.all(16),
  65. decoration: BoxDecoration(
  66. color: colors.bgCard,
  67. borderRadius: BorderRadius.circular(8),
  68. ),
  69. child: ApprovalTimeline(
  70. records: overtime.approvalRecords,
  71. chain: overtime.approvalChain,
  72. currentApproverId: overtime.currentApproverId,
  73. ),
  74. ),
  75. ],
  76. ),
  77. ),
  78. ),
  79. _buildActionBar(context, overtime),
  80. ],
  81. );
  82. }
  83. Widget _buildInfoSection(
  84. OvertimeModel overtime,
  85. AppLocalizations l10n,
  86. AppColorsExtension colors,
  87. ) {
  88. return Container(
  89. padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
  90. decoration: BoxDecoration(
  91. color: colors.bgCard,
  92. borderRadius: BorderRadius.circular(8),
  93. ),
  94. child: Column(
  95. children: [
  96. _infoRow(l10n.get('applicant'), overtime.applicantName, colors),
  97. _infoRow(l10n.get('department'), overtime.deptName, colors),
  98. _infoRow(l10n.get('overtimeType'), overtime.otType, colors),
  99. _infoRow(
  100. l10n.get('compensationMethod'),
  101. overtime.compensationType,
  102. colors,
  103. ),
  104. _infoRow(
  105. l10n.get('netOvertimeHours'),
  106. '${overtime.otHours.toStringAsFixed(1)}${l10n.get('hours')}',
  107. colors,
  108. ),
  109. _infoRow(
  110. l10n.get('startTime'),
  111. du.DateUtils.formatDateTime(overtime.startTime),
  112. colors,
  113. ),
  114. _infoRow(
  115. l10n.get('endTime'),
  116. du.DateUtils.formatDateTime(overtime.endTime),
  117. colors,
  118. ),
  119. ],
  120. ),
  121. );
  122. }
  123. Widget _infoRow(String label, String value, AppColorsExtension colors) {
  124. return Container(
  125. height: 44,
  126. padding: const EdgeInsets.symmetric(vertical: 0),
  127. child: Row(
  128. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  129. children: [
  130. Text(
  131. label,
  132. style: TextStyle(
  133. fontSize: AppFontSizes.body,
  134. color: colors.textSecondary,
  135. ),
  136. ),
  137. Text(
  138. value,
  139. style: TextStyle(
  140. fontSize: AppFontSizes.body,
  141. color: colors.textPrimary,
  142. ),
  143. ),
  144. ],
  145. ),
  146. );
  147. }
  148. Widget _buildReasonSection(
  149. OvertimeModel overtime,
  150. AppLocalizations l10n,
  151. AppColorsExtension colors,
  152. ) {
  153. return Container(
  154. padding: const EdgeInsets.all(16),
  155. decoration: BoxDecoration(
  156. color: colors.bgCard,
  157. borderRadius: BorderRadius.circular(8),
  158. ),
  159. child: Column(
  160. crossAxisAlignment: CrossAxisAlignment.start,
  161. children: [
  162. Text(
  163. l10n.get('overtimeReason'),
  164. style: TextStyle(
  165. fontSize: AppFontSizes.subtitle,
  166. fontWeight: FontWeight.w600,
  167. color: colors.textPrimary,
  168. ),
  169. ),
  170. const SizedBox(height: 8),
  171. Text(
  172. overtime.reason.isEmpty ? l10n.get('no') : overtime.reason,
  173. style: TextStyle(
  174. fontSize: AppFontSizes.body,
  175. color: colors.textPrimary,
  176. ),
  177. ),
  178. ],
  179. ),
  180. );
  181. }
  182. Widget _buildActionBar(BuildContext context, OvertimeModel overtime) {
  183. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  184. final l10n = AppLocalizations.of(context);
  185. final showWithdraw =
  186. overtime.status == 'pending' || overtime.status == 'draft';
  187. if (!showWithdraw) return const SizedBox.shrink();
  188. return Container(
  189. height: 72,
  190. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
  191. decoration: BoxDecoration(color: colors.bgCard),
  192. child: Row(
  193. children: [
  194. const Spacer(),
  195. SizedBox(
  196. height: 40,
  197. child: Material(
  198. color: colors.primary,
  199. borderRadius: BorderRadius.circular(22),
  200. child: InkWell(
  201. onTap: () {
  202. // 撤回逻辑,保留接口
  203. },
  204. borderRadius: BorderRadius.circular(22),
  205. child: Center(
  206. child: Padding(
  207. padding: const EdgeInsets.symmetric(horizontal: 32),
  208. child: Text(
  209. l10n.get('withdrawApplication'),
  210. style: TextStyle(
  211. fontSize: AppFontSizes.body,
  212. fontWeight: FontWeight.w500,
  213. color: Colors.white,
  214. ),
  215. ),
  216. ),
  217. ),
  218. ),
  219. ),
  220. ),
  221. const Spacer(),
  222. ],
  223. ),
  224. );
  225. }
  226. (IconData, Color, String) _statusProps(
  227. String status,
  228. AppLocalizations l10n,
  229. AppColorsExtension colors,
  230. ) {
  231. switch (status) {
  232. case 'approved':
  233. return (Icons.check_circle, colors.success, l10n.get('approved'));
  234. case 'rejected':
  235. return (Icons.cancel, colors.danger, l10n.get('rejected'));
  236. case 'draft':
  237. return (Icons.edit_note, colors.statusGray, l10n.get('draft'));
  238. case 'withdrawn':
  239. return (Icons.cancel_outlined, colors.withdrawnText, l10n.get('withdrawn'));
  240. default:
  241. return (Icons.access_time, colors.warning, l10n.get('pending'));
  242. }
  243. }
  244. String _statusSubText(OvertimeModel overtime, AppLocalizations l10n) {
  245. switch (overtime.status) {
  246. case 'pending':
  247. return overtime.currentApproverId.isNotEmpty
  248. ? '${l10n.get('currentApprover')}:${overtime.currentApproverId}'
  249. : l10n.get('waitHandle');
  250. case 'approved':
  251. final last = overtime.approvalRecords.isNotEmpty
  252. ? overtime.approvalRecords.last.approverName
  253. : '';
  254. return last.isNotEmpty
  255. ? '${l10n.get('approver')}:$last'
  256. : l10n.get('approved');
  257. case 'rejected':
  258. final last = overtime.approvalRecords.isNotEmpty
  259. ? overtime.approvalRecords.last.approverName
  260. : '';
  261. return last.isNotEmpty
  262. ? '${l10n.get('rejecter')}:$last'
  263. : l10n.get('rejected');
  264. default:
  265. return '';
  266. }
  267. }
  268. }