expense_apply_detail_page.dart 26 KB

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