expense_application_detail_page.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:go_router/go_router.dart';
  4. import '../../core/theme/app_colors.dart';
  5. import '../shell/nav_bar_config.dart';
  6. import '../../core/utils/date_utils.dart' as du;
  7. import '../../shared/widgets/form_section.dart';
  8. import '../../shared/widgets/form_field_row.dart';
  9. import '../../shared/widgets/status_banner.dart';
  10. import '../../shared/widgets/action_bar.dart';
  11. import '../../shared/widgets/approval_timeline.dart';
  12. import 'expense_application_model.dart';
  13. import '../../core/i18n/app_localizations.dart';
  14. import 'expense_application_list_controller.dart';
  15. class ExpenseApplicationDetailPage extends ConsumerWidget {
  16. final String id;
  17. const ExpenseApplicationDetailPage({super.key, required this.id});
  18. @override
  19. Widget build(BuildContext context, WidgetRef ref) {
  20. final app = mockExpenseApplications.firstWhere(
  21. (e) => e.id == id,
  22. orElse: () => mockExpenseApplications.first,
  23. );
  24. final l10n = AppLocalizations.of(context);
  25. ref
  26. .read(navBarConfigProvider.notifier)
  27. .update(
  28. NavBarConfig(
  29. title: l10n.get('expenseApplyDetail'),
  30. showBack: true,
  31. onBack: () => context.pop(),
  32. ),
  33. );
  34. return Column(
  35. children: [
  36. Expanded(
  37. child: SingleChildScrollView(
  38. padding: const EdgeInsets.all(16),
  39. child: Column(
  40. children: [
  41. _buildStatusBanner(app),
  42. const SizedBox(height: 4),
  43. _buildSubmitTime(app),
  44. const SizedBox(height: 16),
  45. _buildBasicInfoSection(app, l10n),
  46. const SizedBox(height: 16),
  47. _buildExpenseDetailSection(app, l10n),
  48. const SizedBox(height: 16),
  49. _buildAttachmentSection(l10n),
  50. const SizedBox(height: 16),
  51. if (app.approvalRecords.isNotEmpty ||
  52. app.approvalChain.isNotEmpty)
  53. _buildApprovalSection(l10n, app),
  54. const SizedBox(height: 16),
  55. ],
  56. ),
  57. ),
  58. ),
  59. _buildBottomBar(context, app),
  60. ],
  61. );
  62. }
  63. Widget _buildStatusBanner(ExpenseApplicationModel app) {
  64. final (icon, color, label) = switch (app.status) {
  65. 'approved' => (Icons.check_circle, AppColors.success, '已通过'),
  66. 'rejected' => (Icons.cancel, AppColors.danger, '已拒绝'),
  67. 'draft' => (Icons.edit, AppColors.statusGray, '草稿'),
  68. _ => (Icons.schedule, AppColors.warning, '审批中'),
  69. };
  70. final approverText = switch (app.status) {
  71. 'approved' when app.approvalRecords.isNotEmpty =>
  72. '审批人:${app.approvalRecords.last.approverName}',
  73. 'rejected' when app.approvalRecords.isNotEmpty =>
  74. '拒绝人:${app.approvalRecords.last.approverName}',
  75. 'pending' when app.currentApproverId.isNotEmpty =>
  76. '当前审批人:${app.currentApproverId}',
  77. _ => '',
  78. };
  79. return StatusBanner(
  80. icon: icon,
  81. statusText: label,
  82. subText: approverText,
  83. color: color,
  84. );
  85. }
  86. Widget _buildSubmitTime(ExpenseApplicationModel app) {
  87. return Padding(
  88. padding: const EdgeInsets.only(left: 4, top: 4),
  89. child: Align(
  90. alignment: Alignment.centerLeft,
  91. child: Text(
  92. '提交时间:${du.DateUtils.formatDateTime(app.createTime)}',
  93. style: const TextStyle(
  94. fontSize: AppFontSizes.caption,
  95. color: AppColors.textPlaceholder,
  96. ),
  97. ),
  98. ),
  99. );
  100. }
  101. Widget _buildBasicInfoSection(ExpenseApplicationModel app, AppLocalizations l10n) {
  102. String urgencyLabel = switch (app.urgency) {
  103. 'urgent' => '紧急',
  104. 'normal' => '普通',
  105. _ => app.urgency,
  106. };
  107. return FormSection(
  108. title: l10n.get('basicInfo'),
  109. children: [
  110. FormFieldRow(
  111. label: l10n.get('applicant'),
  112. value: app.applicantName,
  113. readOnly: true,
  114. showArrow: false,
  115. ),
  116. FormFieldRow(
  117. label: l10n.get('department'),
  118. value: app.deptName,
  119. readOnly: true,
  120. showArrow: false,
  121. ),
  122. FormFieldRow(
  123. label: '费用类型',
  124. value: app.expenseType,
  125. readOnly: true,
  126. showArrow: false,
  127. ),
  128. Container(
  129. height: 44,
  130. padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),
  131. child: Row(
  132. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  133. children: [
  134. const Text(
  135. '申请金额',
  136. style: TextStyle(
  137. fontSize: AppFontSizes.body,
  138. color: AppColors.textSecondary,
  139. ),
  140. ),
  141. Text(
  142. '¥${app.estimatedAmount.toStringAsFixed(2)}',
  143. style: const TextStyle(
  144. fontSize: AppFontSizes.subtitle,
  145. fontWeight: FontWeight.w700,
  146. color: AppColors.amountPrimary,
  147. ),
  148. ),
  149. ],
  150. ),
  151. ),
  152. FormFieldRow(
  153. label: '关联项目',
  154. value: app.projectName.isNotEmpty ? app.projectName : null,
  155. hint: '-',
  156. readOnly: true,
  157. showArrow: false,
  158. ),
  159. FormFieldRow(
  160. label: '预算科目',
  161. value: app.budgetSubjectId.isNotEmpty ? app.budgetSubjectId : null,
  162. hint: '-',
  163. readOnly: true,
  164. showArrow: false,
  165. ),
  166. FormFieldRow(
  167. label: '紧急程度',
  168. value: urgencyLabel,
  169. readOnly: true,
  170. showArrow: false,
  171. ),
  172. ],
  173. );
  174. }
  175. Widget _buildExpenseDetailSection(ExpenseApplicationModel app, AppLocalizations l10n) {
  176. return FormSection(
  177. title: l10n.get('expenseDetails'),
  178. children: [
  179. // Table header
  180. Container(
  181. height: 36,
  182. padding: const EdgeInsets.symmetric(horizontal: 8),
  183. decoration: BoxDecoration(
  184. color: AppColors.bgPage,
  185. borderRadius: BorderRadius.circular(4),
  186. ),
  187. child: Row(
  188. children: [
  189. const Expanded(
  190. flex: 3,
  191. child: Text(
  192. '费用项目',
  193. style: TextStyle(
  194. fontSize: AppFontSizes.caption,
  195. fontWeight: FontWeight.w500,
  196. color: AppColors.textSecondary,
  197. ),
  198. ),
  199. ),
  200. Expanded(
  201. flex: 2,
  202. child: Text(
  203. '金额',
  204. textAlign: TextAlign.right,
  205. style: const TextStyle(
  206. fontSize: AppFontSizes.caption,
  207. fontWeight: FontWeight.w500,
  208. color: AppColors.textSecondary,
  209. ),
  210. ),
  211. ),
  212. ],
  213. ),
  214. ),
  215. if (app.details.isEmpty)
  216. const Padding(
  217. padding: EdgeInsets.symmetric(vertical: 8),
  218. child: Text(
  219. '暂无明细数据',
  220. style: TextStyle(
  221. fontSize: AppFontSizes.body,
  222. color: AppColors.textPlaceholder,
  223. ),
  224. ),
  225. )
  226. else
  227. ...app.details.map(
  228. (d) => SizedBox(
  229. height: 28,
  230. child: Row(
  231. children: [
  232. Expanded(
  233. flex: 3,
  234. child: Text(
  235. d.itemName,
  236. style: const TextStyle(
  237. fontSize: AppFontSizes.body,
  238. color: AppColors.textPrimary,
  239. ),
  240. ),
  241. ),
  242. Expanded(
  243. flex: 2,
  244. child: Text(
  245. '¥${d.estimatedAmount.toStringAsFixed(2)}',
  246. textAlign: TextAlign.right,
  247. style: const TextStyle(
  248. fontSize: AppFontSizes.body,
  249. fontWeight: FontWeight.w500,
  250. color: AppColors.amountPrimary,
  251. ),
  252. ),
  253. ),
  254. ],
  255. ),
  256. ),
  257. ),
  258. ],
  259. );
  260. }
  261. Widget _buildAttachmentSection(AppLocalizations l10n) {
  262. return FormSection(
  263. title: l10n.get('attachments'),
  264. children: [
  265. Wrap(
  266. spacing: 8,
  267. runSpacing: 8,
  268. children: List.generate(3, (i) {
  269. return Container(
  270. width: 80,
  271. height: 80,
  272. decoration: BoxDecoration(
  273. color: AppColors.bgPage,
  274. borderRadius: BorderRadius.circular(4),
  275. border: Border.all(
  276. color: AppColors.border,
  277. strokeAlign: BorderSide.strokeAlignInside,
  278. ),
  279. ),
  280. child: const Center(
  281. child: Icon(
  282. Icons.image_outlined,
  283. size: 24,
  284. color: AppColors.textPlaceholder,
  285. ),
  286. ),
  287. );
  288. }),
  289. ),
  290. ],
  291. );
  292. }
  293. Widget _buildApprovalSection(AppLocalizations l10n, ExpenseApplicationModel app) {
  294. return FormSection(
  295. title: l10n.get('approvalFlow'),
  296. children: [
  297. ApprovalTimeline(
  298. records: app.approvalRecords,
  299. chain: app.approvalChain,
  300. currentApproverId: app.currentApproverId,
  301. ),
  302. ],
  303. );
  304. }
  305. Widget _buildBottomBar(BuildContext context, ExpenseApplicationModel app) {
  306. final canWithdraw = app.status == 'pending' || app.status == 'draft';
  307. if (!canWithdraw) {
  308. return const SizedBox.shrink();
  309. }
  310. return ActionBar(
  311. showLeft: false,
  312. centerLabel: '撤回申请',
  313. rightLabel: '提交审批',
  314. onCenterTap: () {
  315. ScaffoldMessenger.of(
  316. context,
  317. ).showSnackBar(const SnackBar(content: Text('已撤回')));
  318. context.pop();
  319. },
  320. onRightTap: null,
  321. );
  322. }
  323. }