expense_apply_detail_page.dart 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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 '../../shared/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('applyDept'),
  285. value: app.deptId.isNotEmpty
  286. ? '${app.deptId}${app.deptName.isNotEmpty ? '/${app.deptName}' : ''}'
  287. : '-',
  288. readOnly: true,
  289. showArrow: false,
  290. ),
  291. const SizedBox(height: 16),
  292. SizedBox(
  293. height: 24,
  294. child: Row(
  295. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  296. children: [
  297. Text(
  298. l10n.get('emergencyLevel'),
  299. style: TextStyle(
  300. fontSize: AppFontSizes.subtitle,
  301. color: colors.textSecondary,
  302. ),
  303. ),
  304. _buildUrgencyChip(app.urgency, l10n, colors),
  305. ],
  306. ),
  307. ),
  308. const SizedBox(height: 16),
  309. FormFieldRow(
  310. label: l10n.get('applyReason'),
  311. value: app.purpose.isNotEmpty ? app.purpose : '-',
  312. readOnly: true,
  313. showArrow: false,
  314. bold: true,
  315. ),
  316. const SizedBox(height: 16),
  317. FormFieldRow(
  318. label: l10n.get('remark'),
  319. value: app.remark.isNotEmpty ? app.remark : '-',
  320. readOnly: true,
  321. showArrow: false,
  322. bold: false,
  323. ),
  324. ],
  325. );
  326. }
  327. // ═══ 费用明细 ═══
  328. Widget _buildExpenseDetailSection(
  329. ExpenseApplyModel app,
  330. AppLocalizations l10n,
  331. AppColorsExtension colors,
  332. ) {
  333. return FormSection(
  334. title: l10n.get('expenseDetails'),
  335. leadingIcon: Icons.receipt_long_outlined,
  336. children: [
  337. if (app.details.isEmpty)
  338. Padding(
  339. padding: const EdgeInsets.symmetric(vertical: 8),
  340. child: Text(
  341. l10n.get('noDetailData'),
  342. style: TextStyle(
  343. fontSize: AppFontSizes.body,
  344. color: colors.textPlaceholder,
  345. ),
  346. ),
  347. )
  348. else
  349. ...app.details.asMap().entries.map((e) {
  350. final d = e.value;
  351. final catLabel = d.categoryName.isNotEmpty
  352. ? '${d.expenseCategory}/${d.categoryName}'
  353. : d.expenseCategory;
  354. return GestureDetector(
  355. onTap: () => _showExpenseDetailDialog(context, d),
  356. child: Container(
  357. margin: const EdgeInsets.symmetric(vertical: 8),
  358. padding: const EdgeInsets.all(12),
  359. decoration: BoxDecoration(
  360. color: colors.bgPage,
  361. borderRadius: BorderRadius.circular(8),
  362. ),
  363. child: Row(
  364. crossAxisAlignment: CrossAxisAlignment.center,
  365. children: [
  366. Expanded(
  367. child: Column(
  368. crossAxisAlignment: CrossAxisAlignment.start,
  369. children: [
  370. Row(
  371. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  372. children: [
  373. Expanded(
  374. child: Text(
  375. catLabel,
  376. maxLines: 1,
  377. overflow: TextOverflow.ellipsis,
  378. style: TextStyle(
  379. fontSize: AppFontSizes.subtitle,
  380. color: colors.textPrimary,
  381. ),
  382. ),
  383. ),
  384. const SizedBox(width: 12),
  385. Text(
  386. '¥${d.estimatedAmount.toStringAsFixed(2)}',
  387. style: TextStyle(
  388. fontSize: AppFontSizes.caption,
  389. fontWeight: FontWeight.w600,
  390. color: colors.amountPrimary,
  391. ),
  392. ),
  393. ],
  394. ),
  395. if (d.acctSubjectId.isNotEmpty) ...[
  396. const SizedBox(height: 4),
  397. Text(
  398. '${l10n.get('acctSubject')}: ${d.acctSubjectId}${d.acctSubjectName.isNotEmpty ? '/${d.acctSubjectName}' : ''}',
  399. maxLines: 1,
  400. overflow: TextOverflow.ellipsis,
  401. style: TextStyle(
  402. fontSize: AppFontSizes.caption,
  403. color: colors.textSecondary,
  404. ),
  405. ),
  406. ],
  407. if (d.sqMan.isNotEmpty) ...[
  408. const SizedBox(height: 4),
  409. Text(
  410. '${l10n.get('applicant')}: ${d.sqMan}${d.sqName.isNotEmpty ? '/${d.sqName}' : ''}',
  411. maxLines: 1,
  412. overflow: TextOverflow.ellipsis,
  413. style: TextStyle(
  414. fontSize: AppFontSizes.caption,
  415. color: colors.textSecondary,
  416. ),
  417. ),
  418. ],
  419. if (d.projectId.isNotEmpty) ...[
  420. const SizedBox(height: 4),
  421. Text(
  422. '${l10n.get('project')}: ${d.projectId}${d.projectName.isNotEmpty ? '/${d.projectName}' : ''}',
  423. maxLines: 1,
  424. overflow: TextOverflow.ellipsis,
  425. style: TextStyle(
  426. fontSize: AppFontSizes.caption,
  427. color: colors.textSecondary,
  428. ),
  429. ),
  430. ],
  431. if (d.costDeptId.isNotEmpty) ...[
  432. const SizedBox(height: 4),
  433. Text(
  434. '${l10n.get('costDept')}: ${d.costDeptId}${d.costDeptName.isNotEmpty ? '/${d.costDeptName}' : ''}',
  435. maxLines: 1,
  436. overflow: TextOverflow.ellipsis,
  437. style: TextStyle(
  438. fontSize: AppFontSizes.caption,
  439. color: colors.textSecondary,
  440. ),
  441. ),
  442. ],
  443. if (d.estimatedStartDate != null) ...[
  444. const SizedBox(height: 4),
  445. Text(
  446. '${l10n.get('estimatedDate')}: ${du.DateUtils.formatDate(d.estimatedStartDate!)}${d.estimatedEndDate != null ? ' ~ ${du.DateUtils.formatDate(d.estimatedEndDate!)}' : ''}',
  447. maxLines: 1,
  448. overflow: TextOverflow.ellipsis,
  449. style: TextStyle(
  450. fontSize: AppFontSizes.caption,
  451. color: colors.textSecondary,
  452. ),
  453. ),
  454. ],
  455. if (d.bxNo.isNotEmpty) ...[
  456. const SizedBox(height: 4),
  457. Text(
  458. '${l10n.get('expenseNo')}: ${d.bxNo}',
  459. maxLines: 1,
  460. overflow: TextOverflow.ellipsis,
  461. style: TextStyle(
  462. fontSize: AppFontSizes.caption,
  463. color: colors.textSecondary,
  464. ),
  465. ),
  466. ],
  467. if (d.remark.isNotEmpty) ...[
  468. const SizedBox(height: 4),
  469. Text(
  470. d.remark,
  471. maxLines: 2,
  472. overflow: TextOverflow.ellipsis,
  473. style: TextStyle(
  474. fontSize: AppFontSizes.caption,
  475. color: colors.textSecondary,
  476. ),
  477. ),
  478. ],
  479. ],
  480. ),
  481. ),
  482. ],
  483. ),
  484. ),
  485. );
  486. }),
  487. if (app.details.isNotEmpty) ...[
  488. const SizedBox(height: 8),
  489. Row(
  490. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  491. children: [
  492. Text(
  493. l10n.get('total'),
  494. style: TextStyle(
  495. fontSize: AppFontSizes.body,
  496. fontWeight: FontWeight.w600,
  497. color: colors.textPrimary,
  498. ),
  499. ),
  500. Text(
  501. '¥${app.details.fold<double>(0, (sum, d) => sum + d.estimatedAmount).toStringAsFixed(2)}',
  502. style: TextStyle(
  503. fontSize: AppFontSizes.subtitle,
  504. fontWeight: FontWeight.w700,
  505. color: colors.amountPrimary,
  506. ),
  507. ),
  508. ],
  509. ),
  510. ],
  511. ],
  512. );
  513. }
  514. // ═══ 附件 ═══
  515. Widget _buildAttachmentSection(
  516. AppLocalizations l10n,
  517. AppColorsExtension colors,
  518. ) {
  519. final children = <Widget>[];
  520. if (!_attachAvailable) {
  521. children.add(
  522. Text(
  523. l10n.get('attachServiceUnavailable'),
  524. style: TextStyle(
  525. fontSize: AppFontSizes.body,
  526. color: colors.textPlaceholder,
  527. ),
  528. ),
  529. );
  530. } else if (!_billFileRights.canBrowseAttachments) {
  531. children.add(
  532. Text(
  533. l10n.get('noAttachmentPermission'),
  534. style: TextStyle(
  535. fontSize: AppFontSizes.body,
  536. color: colors.textPlaceholder,
  537. ),
  538. ),
  539. );
  540. } else if (_attachments.isEmpty) {
  541. children.add(
  542. Text(
  543. l10n.get('noAttachment'),
  544. style: TextStyle(
  545. fontSize: AppFontSizes.body,
  546. color: colors.textPlaceholder,
  547. ),
  548. ),
  549. );
  550. } else {
  551. children.addAll(_attachments.map((a) => _buildAttachmentRow(a, colors)));
  552. }
  553. return FormSection(
  554. title: l10n.get('attachments'),
  555. leadingIcon: Icons.attach_file_outlined,
  556. children: children,
  557. );
  558. }
  559. Widget _buildAttachmentRow(BillAttachment a, AppColorsExtension colors) {
  560. final isImage = [
  561. 'jpg',
  562. 'jpeg',
  563. 'png',
  564. 'gif',
  565. 'bmp',
  566. 'webp',
  567. ].contains(a.ext.toLowerCase());
  568. return GestureDetector(
  569. onTap: () => _openAttachment(a),
  570. child: Container(
  571. margin: const EdgeInsets.symmetric(vertical: 4),
  572. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
  573. decoration: BoxDecoration(
  574. color: colors.bgPage,
  575. borderRadius: BorderRadius.circular(8),
  576. ),
  577. child: Row(
  578. children: [
  579. if (isImage)
  580. _AttachmentThumbnail(
  581. api: ref.read(expenseApplyApiProvider),
  582. attachment: a,
  583. size: 40,
  584. )
  585. else
  586. Icon(_fileTypeIcon(a.ext), size: 40, color: colors.primary),
  587. const SizedBox(width: 10),
  588. Expanded(
  589. child: Text(
  590. a.fileName,
  591. maxLines: 1,
  592. overflow: TextOverflow.ellipsis,
  593. style: TextStyle(
  594. fontSize: AppFontSizes.body,
  595. color: colors.textPrimary,
  596. ),
  597. ),
  598. ),
  599. const SizedBox(width: 8),
  600. GestureDetector(
  601. onTap: () => AttachmentDownloadHelper.downloadAndSave(
  602. context,
  603. a,
  604. ref.read(expenseApplyApiProvider).downloadAttachment,
  605. ),
  606. child: Icon(
  607. Icons.download_outlined,
  608. size: 22,
  609. color: colors.primary,
  610. ),
  611. ),
  612. ],
  613. ),
  614. ),
  615. );
  616. }
  617. Future<void> _openAttachment(BillAttachment a) async {
  618. final l10n = AppLocalizations.of(context);
  619. final ext = a.ext.toLowerCase();
  620. final isImage = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].contains(ext);
  621. if (isImage) {
  622. // 图片 → 弹窗预览,内部自动下载并显示 loading
  623. final api = ref.read(expenseApplyApiProvider);
  624. AttachmentPreview.show(
  625. context,
  626. loader: api.downloadAttachment(a.id),
  627. fileName: a.fileName,
  628. loadingText: l10n.get('loading'),
  629. );
  630. return;
  631. }
  632. // 非图片 → 下载后调用系统工具打开
  633. try {
  634. LoadingDialog.show(context, text: l10n.get('downloading'));
  635. final api = ref.read(expenseApplyApiProvider);
  636. final bytes = await api.downloadAttachment(a.id);
  637. if (!mounted) return;
  638. LoadingDialog.hide(context);
  639. if (bytes == null) {
  640. TDToast.showText(l10n.get('downloadFailed'), context: context);
  641. return;
  642. }
  643. final dir = await getTemporaryDirectory();
  644. final file = File('${dir.path}/${a.fileName}');
  645. await file.writeAsBytes(bytes);
  646. await OpenFilex.open(file.path);
  647. } catch (_) {
  648. if (mounted) LoadingDialog.hide(context);
  649. if (mounted) TDToast.showText(l10n.get('openFailed'), context: context);
  650. }
  651. }
  652. IconData _fileTypeIcon(String ext) {
  653. switch (ext.toLowerCase()) {
  654. case 'pdf':
  655. return Icons.picture_as_pdf;
  656. case 'doc':
  657. case 'docx':
  658. return Icons.description;
  659. case 'xls':
  660. case 'xlsx':
  661. return Icons.table_chart;
  662. case 'jpg':
  663. case 'jpeg':
  664. case 'png':
  665. case 'gif':
  666. case 'bmp':
  667. return Icons.image_outlined;
  668. default:
  669. return Icons.insert_drive_file;
  670. }
  671. }
  672. Widget _buildPageFooter(AppColorsExtension colors) {
  673. final l10n = AppLocalizations.of(context);
  674. return Center(
  675. child: Padding(
  676. padding: const EdgeInsets.only(bottom: 16),
  677. child: Row(
  678. mainAxisSize: MainAxisSize.min,
  679. children: [
  680. Icon(
  681. Icons.rocket_launch_outlined,
  682. size: 16,
  683. color: colors.textPlaceholder,
  684. ),
  685. const SizedBox(width: 6),
  686. Text(
  687. l10n.get('pageFooter'),
  688. style: TextStyle(
  689. fontSize: AppFontSizes.caption,
  690. color: colors.textPlaceholder,
  691. ),
  692. ),
  693. ],
  694. ),
  695. ),
  696. );
  697. }
  698. Widget _buildUrgencyChip(
  699. String urgency,
  700. AppLocalizations l10n,
  701. AppColorsExtension colors,
  702. ) {
  703. final (label, color) = switch (urgency) {
  704. '3' || 'critical' => (l10n.get('critical'), colors.danger),
  705. '2' || 'urgent' => (l10n.get('urgent'), colors.warning),
  706. '1' || 'normal' => (l10n.get('normal'), colors.primary),
  707. _ => (l10n.get('normal'), colors.primary),
  708. };
  709. return Container(
  710. padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 1),
  711. decoration: BoxDecoration(
  712. color: color.withValues(alpha: 0.1),
  713. borderRadius: BorderRadius.circular(4),
  714. border: Border.all(color: color, width: 0.5),
  715. ),
  716. child: Text(
  717. label,
  718. style: TextStyle(
  719. fontSize: 11,
  720. fontWeight: FontWeight.w500,
  721. color: color,
  722. ),
  723. ),
  724. );
  725. }
  726. void _showExpenseDetailDialog(
  727. BuildContext context,
  728. ExpenseApplyDetailModel d,
  729. ) {
  730. ExpenseApplyDetailViewDialog.show(context, d);
  731. }
  732. }
  733. /// 附件缩略图 — 自动调用 DownloadAttachment 加载图片
  734. class _AttachmentThumbnail extends StatefulWidget {
  735. final ExpenseApplyApi api;
  736. final BillAttachment attachment;
  737. final double size;
  738. const _AttachmentThumbnail({
  739. required this.api,
  740. required this.attachment,
  741. required this.size,
  742. });
  743. @override
  744. State<_AttachmentThumbnail> createState() => _AttachmentThumbnailState();
  745. }
  746. class _AttachmentThumbnailState extends State<_AttachmentThumbnail> {
  747. Uint8List? _bytes;
  748. bool _loading = true;
  749. @override
  750. void initState() {
  751. super.initState();
  752. _load();
  753. }
  754. Future<void> _load() async {
  755. try {
  756. final bytes = await widget.api.downloadAttachment(widget.attachment.id);
  757. if (mounted) {
  758. setState(() {
  759. _bytes = bytes;
  760. _loading = false;
  761. });
  762. }
  763. } catch (_) {
  764. if (mounted) setState(() => _loading = false);
  765. }
  766. }
  767. @override
  768. Widget build(BuildContext context) {
  769. if (_loading) {
  770. return SizedBox(
  771. width: widget.size,
  772. height: widget.size,
  773. child: const Center(
  774. child: SizedBox(
  775. width: 16,
  776. height: 16,
  777. child: CircularProgressIndicator(strokeWidth: 2),
  778. ),
  779. ),
  780. );
  781. }
  782. if (_bytes != null) {
  783. return ClipRRect(
  784. borderRadius: BorderRadius.circular(4),
  785. child: Image.memory(
  786. _bytes!,
  787. width: widget.size,
  788. height: widget.size,
  789. fit: BoxFit.cover,
  790. ),
  791. );
  792. }
  793. return Icon(
  794. Icons.broken_image,
  795. size: widget.size * 0.6,
  796. color: Colors.grey,
  797. );
  798. }
  799. }