expense_apply_detail_page.dart 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. import 'dart:typed_data';
  2. import 'dart:io';
  3. import 'package:flutter/material.dart';
  4. import 'package:path_provider/path_provider.dart';
  5. import 'package:open_filex/open_filex.dart';
  6. import 'package:go_router/go_router.dart';
  7. import 'widgets/attachment_preview_page.dart';
  8. import 'package:tdesign_flutter/tdesign_flutter.dart';
  9. import 'package:flutter_riverpod/flutter_riverpod.dart';
  10. import '../../shared/widgets/loading_dialog.dart';
  11. import '../../core/utils/date_utils.dart' as du;
  12. import '../../shared/widgets/form_section.dart';
  13. import '../../shared/widgets/form_field_row.dart';
  14. import '../../shared/widgets/app_skeletons.dart';
  15. import '../../shared/models/bill_file_rights.dart';
  16. import '../../shared/widgets/attachment_download_helper.dart';
  17. import '../../shared/widgets/action_bar.dart';
  18. import '../../shared/widgets/status_banner.dart';
  19. import 'expense_apply_model.dart';
  20. import 'widgets/expense_apply_detail_view_dialog.dart';
  21. import '../../core/i18n/app_localizations.dart';
  22. import '../../shared/models/bill_attachment.dart';
  23. import 'expense_apply_api.dart';
  24. import '../../core/theme/app_colors.dart';
  25. import '../../core/theme/app_colors_extension.dart';
  26. class ExpenseApplyDetailPage extends ConsumerStatefulWidget {
  27. final String billNo;
  28. final int queryId;
  29. const ExpenseApplyDetailPage({
  30. super.key,
  31. required this.billNo,
  32. this.queryId = 0,
  33. });
  34. @override
  35. ConsumerState<ExpenseApplyDetailPage> createState() =>
  36. _ExpenseApplyDetailPageState();
  37. }
  38. class _ExpenseApplyDetailPageState
  39. extends ConsumerState<ExpenseApplyDetailPage> {
  40. bool _loading = true;
  41. String? _error;
  42. ExpenseApplyModel? _data;
  43. List<BillAttachment> _attachments = [];
  44. bool _attachAvailable = false;
  45. BillFileRights _billFileRights = BillFileRights.none;
  46. Map<String, dynamic>? _billStatus;
  47. bool _statusLoading = false;
  48. bool _canEdit = false;
  49. @override
  50. void initState() {
  51. super.initState();
  52. _loadData();
  53. }
  54. @override
  55. void dispose() {
  56. super.dispose();
  57. }
  58. Future<void> _loadData() async {
  59. setState(() {
  60. _loading = true;
  61. _error = null;
  62. });
  63. try {
  64. final api = ref.read(expenseApplyApiProvider);
  65. final detail = await api.fetchDetail(widget.billNo);
  66. // Load attachments (non-critical, best-effort)
  67. bool attachAvailable = false;
  68. try {
  69. attachAvailable = await api.checkAttachHealth();
  70. debugPrint('[Attach] checkAttachHealth result: $attachAvailable');
  71. } catch (e) {
  72. debugPrint('[Attach] checkAttachHealth error: $e');
  73. attachAvailable = false;
  74. }
  75. // 加载附件权限
  76. BillFileRights billFileRights = BillFileRights.none;
  77. try {
  78. billFileRights = await api.getBillFileRights('AE');
  79. } catch (_) {}
  80. List<BillAttachment> attachments = [];
  81. if (attachAvailable && billFileRights.canBrowseAttachments) {
  82. try {
  83. attachments = await api.getAttachments('AE', widget.billNo);
  84. debugPrint('[Attach] getAttachments count: ${attachments.length}');
  85. } catch (e) {
  86. debugPrint('[Attach] getAttachments error: $e');
  87. }
  88. }
  89. debugPrint(
  90. '[Attach] final state: attachAvailable=$attachAvailable, count=${attachments.length}',
  91. );
  92. if (mounted) {
  93. setState(() {
  94. _data = detail;
  95. _attachments = attachments;
  96. _attachAvailable = attachAvailable;
  97. _billFileRights = billFileRights;
  98. _loading = false;
  99. });
  100. }
  101. // 单据状态(非关键,尽力加载)
  102. setState(() => _statusLoading = true);
  103. try {
  104. final status = await api.getBillStatus(widget.billNo);
  105. if (mounted) {
  106. setState(() {
  107. _billStatus = status;
  108. _canEdit = status['canEdit'] == true;
  109. _statusLoading = false;
  110. });
  111. }
  112. } catch (_) {
  113. if (mounted) setState(() => _statusLoading = false);
  114. }
  115. } catch (e) {
  116. if (mounted) {
  117. setState(() {
  118. _error = e.toString();
  119. _loading = false;
  120. });
  121. }
  122. }
  123. }
  124. @override
  125. Widget build(BuildContext context) {
  126. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  127. final l10n = AppLocalizations.of(context);
  128. if (_loading) {
  129. return const SkeletonDetailPage();
  130. }
  131. if (_error != null) {
  132. return Center(
  133. child: Column(
  134. mainAxisSize: MainAxisSize.min,
  135. children: [
  136. Icon(Icons.error_outline, size: 48, color: colors.danger),
  137. const SizedBox(height: 16),
  138. Padding(
  139. padding: const EdgeInsets.symmetric(horizontal: 32),
  140. child: Text(
  141. _error!,
  142. textAlign: TextAlign.center,
  143. style: TextStyle(
  144. fontSize: AppFontSizes.body,
  145. color: colors.textSecondary,
  146. ),
  147. ),
  148. ),
  149. const SizedBox(height: 16),
  150. TDButton(
  151. text: l10n.get('retry'),
  152. size: TDButtonSize.medium,
  153. onTap: _loadData,
  154. ),
  155. ],
  156. ),
  157. );
  158. }
  159. final app = _data!;
  160. return Column(
  161. children: [
  162. Expanded(
  163. child: SingleChildScrollView(
  164. physics: const AlwaysScrollableScrollPhysics(),
  165. padding: const EdgeInsets.all(16),
  166. child: Column(
  167. children: [
  168. if (_statusLoading) ...[
  169. const Padding(
  170. padding: EdgeInsets.symmetric(vertical: 8),
  171. child: Center(
  172. child: TDLoading(
  173. size: TDLoadingSize.small,
  174. icon: TDLoadingIcon.activity,
  175. ),
  176. ),
  177. ),
  178. ],
  179. Builder(
  180. builder: (ctx) {
  181. final badge = _buildStatusBadge(l10n);
  182. if (badge == null) return const SizedBox.shrink();
  183. return Column(
  184. children: [badge, const SizedBox(height: 16)],
  185. );
  186. },
  187. ),
  188. _buildBasicInfoSection(app, l10n, colors),
  189. const SizedBox(height: 16),
  190. _buildExpenseDetailSection(app, l10n, colors),
  191. const SizedBox(height: 16),
  192. _buildAttachmentSection(l10n, colors),
  193. const SizedBox(height: 24),
  194. _buildPageFooter(colors),
  195. ],
  196. ),
  197. ),
  198. ),
  199. if (_canEdit)
  200. ActionBar(
  201. showLeft: false,
  202. showCenter: false,
  203. rightLabel: l10n.get('editApply'),
  204. onRightTap: () async {
  205. final result = await GoRouter.of(
  206. context,
  207. ).push('/expense-apply/edit/${widget.billNo}');
  208. if (result == true && mounted) _loadData();
  209. },
  210. ),
  211. ],
  212. );
  213. }
  214. // ═══ 状态徽章 ═══
  215. Widget? _buildStatusBadge(AppLocalizations l10n) {
  216. final isTransferred = _billStatus?['isTransferred'] == true;
  217. final approvalStatus = _billStatus?['approvalStatus'] as String?;
  218. if (isTransferred) {
  219. return StatusBanner(
  220. icon: Icons.swap_horiz,
  221. statusText: l10n.get('statusConvertedToExpense'),
  222. subText: '',
  223. color: Colors.blueGrey,
  224. );
  225. }
  226. switch (approvalStatus) {
  227. case 'SHCOUNT4':
  228. return StatusBanner(
  229. icon: Icons.check_circle_outline,
  230. statusText: l10n.get('statusApproved'),
  231. subText: '',
  232. color: Colors.green,
  233. );
  234. case 'SHCOUNT5':
  235. return StatusBanner(
  236. icon: Icons.cancel_outlined,
  237. statusText: l10n.get('statusFinalRejected'),
  238. subText: '',
  239. color: Colors.red,
  240. );
  241. case 'SHCOUNT1':
  242. return StatusBanner(
  243. icon: Icons.hourglass_empty,
  244. statusText: l10n.get('statusPendingReview'),
  245. subText: '',
  246. color: Colors.blue,
  247. );
  248. case 'SHCOUNT2':
  249. return StatusBanner(
  250. icon: Icons.block_outlined,
  251. statusText: l10n.get('statusReviewRejected'),
  252. subText: '',
  253. color: Colors.deepOrange,
  254. );
  255. default:
  256. return null;
  257. }
  258. }
  259. // ═══ 基本信息 ═══
  260. Widget _buildBasicInfoSection(
  261. ExpenseApplyModel app,
  262. AppLocalizations l10n,
  263. AppColorsExtension colors,
  264. ) {
  265. return FormSection(
  266. title: l10n.get('basicInfo'),
  267. leadingIcon: Icons.info_outline,
  268. children: [
  269. FormFieldRow(
  270. label: l10n.get('expenseApplyNo'),
  271. value: app.expenseApplyNo,
  272. readOnly: true,
  273. showArrow: false,
  274. ),
  275. const SizedBox(height: 16),
  276. FormFieldRow(
  277. label: l10n.get('date'),
  278. value: du.DateUtils.formatDate(app.createTime),
  279. readOnly: true,
  280. showArrow: false,
  281. ),
  282. const SizedBox(height: 16),
  283. FormFieldRow(
  284. label: l10n.get('applicant'),
  285. value: app.applicantId.isNotEmpty
  286. ? '${app.applicantId}${app.applicantName.isNotEmpty ? '/${app.applicantName}' : ''}'
  287. : '-',
  288. readOnly: true,
  289. showArrow: false,
  290. ),
  291. const SizedBox(height: 16),
  292. FormFieldRow(
  293. label: l10n.get('department'),
  294. value: app.deptId.isNotEmpty
  295. ? '${app.deptId}${app.deptName.isNotEmpty ? '/${app.deptName}' : ''}'
  296. : '-',
  297. readOnly: true,
  298. showArrow: false,
  299. ),
  300. const SizedBox(height: 16),
  301. SizedBox(
  302. height: 24,
  303. child: Row(
  304. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  305. children: [
  306. Text(
  307. l10n.get('emergencyLevel'),
  308. style: TextStyle(
  309. fontSize: AppFontSizes.subtitle,
  310. color: colors.textSecondary,
  311. ),
  312. ),
  313. _buildUrgencyChip(app.urgency, l10n, colors),
  314. ],
  315. ),
  316. ),
  317. const SizedBox(height: 16),
  318. FormFieldRow(
  319. label: l10n.get('applyReason'),
  320. value: app.purpose.isNotEmpty ? app.purpose : '-',
  321. readOnly: true,
  322. showArrow: false,
  323. bold: true,
  324. ),
  325. const SizedBox(height: 16),
  326. FormFieldRow(
  327. label: l10n.get('remark'),
  328. value: app.remark.isNotEmpty ? app.remark : '-',
  329. readOnly: true,
  330. showArrow: false,
  331. bold: false,
  332. ),
  333. ],
  334. );
  335. }
  336. // ═══ 费用明细 ═══
  337. Widget _buildExpenseDetailSection(
  338. ExpenseApplyModel app,
  339. AppLocalizations l10n,
  340. AppColorsExtension colors,
  341. ) {
  342. return FormSection(
  343. title: l10n.get('expenseDetails'),
  344. leadingIcon: Icons.receipt_long_outlined,
  345. children: [
  346. if (app.details.isEmpty)
  347. Padding(
  348. padding: const EdgeInsets.symmetric(vertical: 8),
  349. child: Text(
  350. l10n.get('noDetailData'),
  351. style: TextStyle(
  352. fontSize: AppFontSizes.body,
  353. color: colors.textPlaceholder,
  354. ),
  355. ),
  356. )
  357. else
  358. ...app.details.asMap().entries.map((e) {
  359. final d = e.value;
  360. final catLabel = d.categoryName.isNotEmpty
  361. ? '${d.expenseCategory}/${d.categoryName}'
  362. : d.expenseCategory;
  363. return GestureDetector(
  364. onTap: () => _showExpenseDetailDialog(context, d),
  365. child: Container(
  366. margin: const EdgeInsets.symmetric(vertical: 8),
  367. padding: const EdgeInsets.all(12),
  368. decoration: BoxDecoration(
  369. color: colors.bgPage,
  370. borderRadius: BorderRadius.circular(8),
  371. ),
  372. child: Row(
  373. crossAxisAlignment: CrossAxisAlignment.center,
  374. children: [
  375. Expanded(
  376. child: Column(
  377. crossAxisAlignment: CrossAxisAlignment.start,
  378. children: [
  379. Row(
  380. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  381. children: [
  382. Expanded(
  383. child: Text(
  384. catLabel,
  385. maxLines: 1,
  386. overflow: TextOverflow.ellipsis,
  387. style: TextStyle(
  388. fontSize: AppFontSizes.subtitle,
  389. color: colors.textPrimary,
  390. ),
  391. ),
  392. ),
  393. const SizedBox(width: 12),
  394. Text(
  395. '¥${d.estimatedAmount.toStringAsFixed(2)}',
  396. style: TextStyle(
  397. fontSize: AppFontSizes.caption,
  398. fontWeight: FontWeight.w600,
  399. color: colors.amountPrimary,
  400. ),
  401. ),
  402. ],
  403. ),
  404. if (d.acctSubjectId.isNotEmpty) ...[
  405. const SizedBox(height: 4),
  406. Text(
  407. '${l10n.get('acctSubject')}: ${d.acctSubjectId}${d.acctSubjectName.isNotEmpty ? '/${d.acctSubjectName}' : ''}',
  408. maxLines: 1,
  409. overflow: TextOverflow.ellipsis,
  410. style: TextStyle(
  411. fontSize: AppFontSizes.caption,
  412. color: colors.textSecondary,
  413. ),
  414. ),
  415. ],
  416. if (d.projectId.isNotEmpty) ...[
  417. const SizedBox(height: 4),
  418. Text(
  419. '${l10n.get('project')}: ${d.projectId}${d.projectName.isNotEmpty ? '/${d.projectName}' : ''}',
  420. maxLines: 1,
  421. overflow: TextOverflow.ellipsis,
  422. style: TextStyle(
  423. fontSize: AppFontSizes.caption,
  424. color: colors.textSecondary,
  425. ),
  426. ),
  427. ],
  428. if (d.costDeptId.isNotEmpty) ...[
  429. const SizedBox(height: 4),
  430. Text(
  431. '${l10n.get('costDept')}: ${d.costDeptId}${d.costDeptName.isNotEmpty ? '/${d.costDeptName}' : ''}',
  432. maxLines: 1,
  433. overflow: TextOverflow.ellipsis,
  434. style: TextStyle(
  435. fontSize: AppFontSizes.caption,
  436. color: colors.textSecondary,
  437. ),
  438. ),
  439. ],
  440. if (d.estimatedStartDate != null) ...[
  441. const SizedBox(height: 4),
  442. Text(
  443. '${l10n.get('estimatedDate')}: ${du.DateUtils.formatDate(d.estimatedStartDate!)}${d.estimatedEndDate != null ? ' ~ ${du.DateUtils.formatDate(d.estimatedEndDate!)}' : ''}',
  444. maxLines: 1,
  445. overflow: TextOverflow.ellipsis,
  446. style: TextStyle(
  447. fontSize: AppFontSizes.caption,
  448. color: colors.textSecondary,
  449. ),
  450. ),
  451. ],
  452. if (d.bxNo.isNotEmpty) ...[
  453. const SizedBox(height: 4),
  454. Text(
  455. '${l10n.get('expenseNo')}: ${d.bxNo}',
  456. maxLines: 1,
  457. overflow: TextOverflow.ellipsis,
  458. style: TextStyle(
  459. fontSize: AppFontSizes.caption,
  460. color: colors.textSecondary,
  461. ),
  462. ),
  463. ],
  464. if (d.remark.isNotEmpty) ...[
  465. const SizedBox(height: 4),
  466. Text(
  467. d.remark,
  468. maxLines: 2,
  469. overflow: TextOverflow.ellipsis,
  470. style: TextStyle(
  471. fontSize: AppFontSizes.caption,
  472. color: colors.textSecondary,
  473. ),
  474. ),
  475. ],
  476. ],
  477. ),
  478. ),
  479. ],
  480. ),
  481. ),
  482. );
  483. }),
  484. if (app.details.isNotEmpty) ...[
  485. const SizedBox(height: 8),
  486. Row(
  487. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  488. children: [
  489. Text(
  490. l10n.get('total'),
  491. style: TextStyle(
  492. fontSize: AppFontSizes.body,
  493. fontWeight: FontWeight.w600,
  494. color: colors.textPrimary,
  495. ),
  496. ),
  497. Text(
  498. '¥${app.details.fold<double>(0, (sum, d) => sum + d.estimatedAmount).toStringAsFixed(2)}',
  499. style: TextStyle(
  500. fontSize: AppFontSizes.subtitle,
  501. fontWeight: FontWeight.w700,
  502. color: colors.amountPrimary,
  503. ),
  504. ),
  505. ],
  506. ),
  507. ],
  508. ],
  509. );
  510. }
  511. // ═══ 附件 ═══
  512. Widget _buildAttachmentSection(
  513. AppLocalizations l10n,
  514. AppColorsExtension colors,
  515. ) {
  516. final children = <Widget>[];
  517. if (!_attachAvailable) {
  518. children.add(
  519. Text(
  520. l10n.get('attachServiceUnavailable'),
  521. style: TextStyle(
  522. fontSize: AppFontSizes.body,
  523. color: colors.textPlaceholder,
  524. ),
  525. ),
  526. );
  527. } else if (!_billFileRights.canBrowseAttachments) {
  528. children.add(
  529. Text(
  530. l10n.get('noAttachmentPermission'),
  531. style: TextStyle(
  532. fontSize: AppFontSizes.body,
  533. color: colors.textPlaceholder,
  534. ),
  535. ),
  536. );
  537. } else if (_attachments.isEmpty) {
  538. children.add(
  539. Text(
  540. l10n.get('noAttachment'),
  541. style: TextStyle(
  542. fontSize: AppFontSizes.body,
  543. color: colors.textPlaceholder,
  544. ),
  545. ),
  546. );
  547. } else {
  548. children.addAll(_attachments.map((a) => _buildAttachmentRow(a, colors)));
  549. }
  550. return FormSection(
  551. title: l10n.get('attachments'),
  552. leadingIcon: Icons.attach_file_outlined,
  553. children: children,
  554. );
  555. }
  556. Widget _buildAttachmentRow(BillAttachment a, AppColorsExtension colors) {
  557. final isImage = [
  558. 'jpg',
  559. 'jpeg',
  560. 'png',
  561. 'gif',
  562. 'bmp',
  563. 'webp',
  564. ].contains(a.ext.toLowerCase());
  565. return GestureDetector(
  566. onTap: () => _openAttachment(a),
  567. child: Container(
  568. margin: const EdgeInsets.symmetric(vertical: 4),
  569. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  570. decoration: BoxDecoration(
  571. color: colors.bgPage,
  572. borderRadius: BorderRadius.circular(8),
  573. ),
  574. child: Row(
  575. children: [
  576. if (isImage)
  577. _AttachmentThumbnail(
  578. api: ref.read(expenseApplyApiProvider),
  579. attachment: a,
  580. size: 40,
  581. )
  582. else
  583. Icon(_fileTypeIcon(a.ext), size: 40, color: colors.primary),
  584. const SizedBox(width: 10),
  585. Expanded(
  586. child: Text(
  587. a.fileName,
  588. maxLines: 1,
  589. overflow: TextOverflow.ellipsis,
  590. style: TextStyle(
  591. fontSize: AppFontSizes.body,
  592. color: colors.textPrimary,
  593. ),
  594. ),
  595. ),
  596. const SizedBox(width: 8),
  597. GestureDetector(
  598. onTap: () => AttachmentDownloadHelper.downloadAndSave(
  599. context,
  600. a,
  601. ref.read(expenseApplyApiProvider).downloadAttachment,
  602. ),
  603. child: Icon(
  604. Icons.download_outlined,
  605. size: 22,
  606. color: colors.primary,
  607. ),
  608. ),
  609. ],
  610. ),
  611. ),
  612. );
  613. }
  614. Future<void> _openAttachment(BillAttachment a) async {
  615. final l10n = AppLocalizations.of(context);
  616. final ext = a.ext.toLowerCase();
  617. final isImage = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].contains(ext);
  618. if (isImage) {
  619. // 图片 → 弹窗预览,内部自动下载并显示 loading
  620. final api = ref.read(expenseApplyApiProvider);
  621. AttachmentPreview.show(
  622. context,
  623. loader: api.downloadAttachment(a.id),
  624. fileName: a.fileName,
  625. loadingText: l10n.get('loading'),
  626. );
  627. return;
  628. }
  629. // 非图片 → 下载后调用系统工具打开
  630. try {
  631. LoadingDialog.show(context, text: l10n.get('downloading'));
  632. final api = ref.read(expenseApplyApiProvider);
  633. final bytes = await api.downloadAttachment(a.id);
  634. if (!mounted) return;
  635. LoadingDialog.hide(context);
  636. if (bytes == null) {
  637. TDToast.showText(l10n.get('downloadFailed'), context: context);
  638. return;
  639. }
  640. final dir = await getTemporaryDirectory();
  641. final file = File('${dir.path}/${a.fileName}');
  642. await file.writeAsBytes(bytes);
  643. await OpenFilex.open(file.path);
  644. } catch (_) {
  645. if (mounted) LoadingDialog.hide(context);
  646. if (mounted) TDToast.showText(l10n.get('openFailed'), context: context);
  647. }
  648. }
  649. IconData _fileTypeIcon(String ext) {
  650. switch (ext.toLowerCase()) {
  651. case 'pdf':
  652. return Icons.picture_as_pdf;
  653. case 'doc':
  654. case 'docx':
  655. return Icons.description;
  656. case 'xls':
  657. case 'xlsx':
  658. return Icons.table_chart;
  659. case 'jpg':
  660. case 'jpeg':
  661. case 'png':
  662. case 'gif':
  663. case 'bmp':
  664. return Icons.image_outlined;
  665. default:
  666. return Icons.insert_drive_file;
  667. }
  668. }
  669. Widget _buildPageFooter(AppColorsExtension colors) {
  670. final l10n = AppLocalizations.of(context);
  671. return Center(
  672. child: Padding(
  673. padding: const EdgeInsets.only(bottom: 16),
  674. child: Row(
  675. mainAxisSize: MainAxisSize.min,
  676. children: [
  677. Icon(
  678. Icons.rocket_launch_outlined,
  679. size: 16,
  680. color: colors.textPlaceholder,
  681. ),
  682. const SizedBox(width: 6),
  683. Text(
  684. l10n.get('pageFooter'),
  685. style: TextStyle(
  686. fontSize: AppFontSizes.caption,
  687. color: colors.textPlaceholder,
  688. ),
  689. ),
  690. ],
  691. ),
  692. ),
  693. );
  694. }
  695. Widget _buildUrgencyChip(
  696. String urgency,
  697. AppLocalizations l10n,
  698. AppColorsExtension colors,
  699. ) {
  700. final (label, color) = switch (urgency) {
  701. '3' || 'critical' => (l10n.get('critical'), colors.danger),
  702. '2' || 'urgent' => (l10n.get('urgent'), colors.warning),
  703. '1' || 'normal' => (l10n.get('normal'), colors.primary),
  704. _ => (l10n.get('normal'), colors.primary),
  705. };
  706. return Container(
  707. padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
  708. decoration: BoxDecoration(
  709. color: color.withValues(alpha: 0.1),
  710. borderRadius: BorderRadius.circular(4),
  711. border: Border.all(color: color, width: 0.5),
  712. ),
  713. child: Text(
  714. label,
  715. style: TextStyle(
  716. fontSize: 11,
  717. fontWeight: FontWeight.w500,
  718. color: color,
  719. ),
  720. ),
  721. );
  722. }
  723. void _showExpenseDetailDialog(
  724. BuildContext context,
  725. ExpenseApplyDetailModel d,
  726. ) {
  727. ExpenseApplyDetailViewDialog.show(context, d);
  728. }
  729. }
  730. /// 附件缩略图 — 自动调用 DownloadAttachment 加载图片
  731. class _AttachmentThumbnail extends StatefulWidget {
  732. final ExpenseApplyApi api;
  733. final BillAttachment attachment;
  734. final double size;
  735. const _AttachmentThumbnail({
  736. required this.api,
  737. required this.attachment,
  738. required this.size,
  739. });
  740. @override
  741. State<_AttachmentThumbnail> createState() => _AttachmentThumbnailState();
  742. }
  743. class _AttachmentThumbnailState extends State<_AttachmentThumbnail> {
  744. Uint8List? _bytes;
  745. bool _loading = true;
  746. @override
  747. void initState() {
  748. super.initState();
  749. _load();
  750. }
  751. Future<void> _load() async {
  752. try {
  753. final bytes = await widget.api.downloadAttachment(widget.attachment.id);
  754. if (mounted) {
  755. setState(() {
  756. _bytes = bytes;
  757. _loading = false;
  758. });
  759. }
  760. } catch (_) {
  761. if (mounted) setState(() => _loading = false);
  762. }
  763. }
  764. @override
  765. Widget build(BuildContext context) {
  766. if (_loading) {
  767. return SizedBox(
  768. width: widget.size,
  769. height: widget.size,
  770. child: const Center(
  771. child: SizedBox(
  772. width: 16,
  773. height: 16,
  774. child: CircularProgressIndicator(strokeWidth: 2),
  775. ),
  776. ),
  777. );
  778. }
  779. if (_bytes != null) {
  780. return ClipRRect(
  781. borderRadius: BorderRadius.circular(4),
  782. child: Image.memory(
  783. _bytes!,
  784. width: widget.size,
  785. height: widget.size,
  786. fit: BoxFit.cover,
  787. ),
  788. );
  789. }
  790. return Icon(
  791. Icons.broken_image,
  792. size: widget.size * 0.6,
  793. color: Colors.grey,
  794. );
  795. }
  796. }