expense_create_page.dart 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_riverpod/flutter_riverpod.dart';
  5. import 'package:tdesign_flutter/tdesign_flutter.dart';
  6. import 'package:go_router/go_router.dart';
  7. import '../../shared/widgets/nav_bar_config.dart';
  8. import '../../core/utils/responsive.dart';
  9. import '../../shared/widgets/form_section.dart';
  10. import '../../shared/widgets/form_field_row.dart';
  11. import 'expense_api.dart';
  12. import 'expense_create_controller.dart';
  13. import '../../core/i18n/app_localizations.dart';
  14. import 'expense_model.dart';
  15. import '../../core/theme/app_colors.dart';
  16. import '../../core/theme/app_colors_extension.dart';
  17. import '../../core/navigation/host_app_channel.dart';
  18. import '../../core/data/mock_api_data.dart';
  19. import 'widgets/expense_detail_dialog.dart';
  20. import '../../shared/widgets/action_bar.dart';
  21. import '../../shared/widgets/loading_dialog.dart';
  22. import '../../shared/widgets/attachment_picker.dart';
  23. import 'expense_apply_import_page.dart';
  24. class ExpenseCreatePage extends ConsumerStatefulWidget {
  25. final String? editId;
  26. const ExpenseCreatePage({super.key, this.editId});
  27. @override
  28. ConsumerState<ExpenseCreatePage> createState() => _ExpenseCreatePageState();
  29. }
  30. class _ExpenseCreatePageState extends ConsumerState<ExpenseCreatePage>
  31. with WidgetsBindingObserver {
  32. final _purposeController = TextEditingController();
  33. final _purposeFocus = FocusNode();
  34. final _remarkController = TextEditingController();
  35. final _remarkFocus = FocusNode();
  36. final _scrollCtrl = ScrollController();
  37. final _detailsSectionKey = GlobalKey();
  38. late final AttachmentPickerController _attachmentController;
  39. late Future<bool> _draftFuture;
  40. bool _draftHandled = false;
  41. bool _isPoppingToNative = false;
  42. // ── 参考数据(从 API 加载) ──
  43. List<CostTypeItem> _costTypes = [];
  44. List<ProjectCodeItem> _projects = [];
  45. List<DepartmentItem> _departments = [];
  46. List<CustomerItem> _customers = [];
  47. List<CurrencyItem> _currencies = [];
  48. List<EmployeeItem> _employees = [];
  49. bool _refDataLoading = true;
  50. bool _addingDetail = false;
  51. // ── 报销部门 ──
  52. String _selectedDeptId = '';
  53. String _selectedDeptName = '';
  54. @override
  55. void initState() {
  56. super.initState();
  57. WidgetsBinding.instance.addObserver(this);
  58. SystemChrome.setSystemUIOverlayStyle(
  59. const SystemUiOverlayStyle(
  60. statusBarColor: Colors.transparent,
  61. statusBarIconBrightness: Brightness.dark,
  62. ),
  63. );
  64. _attachmentController = AttachmentPickerController(maxCount: 9)
  65. ..addListener(() => setState(() {}));
  66. _purposeFocus.addListener(() => _ensureVisible(_purposeFocus));
  67. _remarkFocus.addListener(() => _ensureVisible(_remarkFocus));
  68. _costTypes = [];
  69. _projects = [];
  70. _departments = [];
  71. _customers = [];
  72. _employees = [];
  73. _refDataLoading = true;
  74. _refDataFuture = null;
  75. _draftFuture = widget.editId == null
  76. ? ExpenseCreateController.hasDraft()
  77. : Future.value(false);
  78. _loadRefData();
  79. }
  80. Future<void>? _refDataFuture;
  81. Future<void> _loadRefData() async {
  82. if (_refDataFuture != null) return _refDataFuture!;
  83. final completer = Completer<void>();
  84. _refDataFuture = completer.future;
  85. try {
  86. final api = ref.read(expenseApiProvider);
  87. final results = await Future.wait([
  88. api.getCostTypes(),
  89. api.getProjectCodes(),
  90. api.getDepartments(),
  91. api.getCustomers(),
  92. api.getCurrencies(),
  93. api.getEmployees(),
  94. ]);
  95. if (!mounted) {
  96. completer.complete();
  97. return;
  98. }
  99. setState(() {
  100. _costTypes = results[0] as List<CostTypeItem>;
  101. _projects = results[1] as List<ProjectCodeItem>;
  102. _departments = results[2] as List<DepartmentItem>;
  103. _customers = results[3] as List<CustomerItem>;
  104. _currencies = results[4] as List<CurrencyItem>;
  105. _employees = results[5] as List<EmployeeItem>;
  106. _refDataLoading = false;
  107. _autoSelectDept();
  108. });
  109. completer.complete();
  110. } catch (_) {
  111. if (!mounted) {
  112. completer.complete();
  113. return;
  114. }
  115. setState(() => _refDataLoading = false);
  116. completer.complete();
  117. } finally {
  118. _refDataFuture = null;
  119. }
  120. }
  121. void _scrollToDetailSection() {
  122. WidgetsBinding.instance.addPostFrameCallback((_) {
  123. if (_scrollCtrl.hasClients && _detailsSectionKey.currentContext != null) {
  124. Scrollable.ensureVisible(
  125. _detailsSectionKey.currentContext!,
  126. alignment: 0.0,
  127. duration: const Duration(milliseconds: 300),
  128. );
  129. }
  130. });
  131. }
  132. void _ensureVisible(FocusNode node) {
  133. if (!node.hasFocus) return;
  134. WidgetsBinding.instance.addPostFrameCallback((_) {
  135. if (node.hasFocus && _scrollCtrl.hasClients) {
  136. final ctx = node.context;
  137. if (ctx != null) {
  138. Scrollable.ensureVisible(
  139. ctx,
  140. alignment: 0.3,
  141. duration: const Duration(milliseconds: 300),
  142. );
  143. }
  144. }
  145. });
  146. }
  147. @override
  148. void dispose() {
  149. WidgetsBinding.instance.removeObserver(this);
  150. _purposeController.dispose();
  151. _purposeFocus.dispose();
  152. _remarkController.dispose();
  153. _remarkFocus.dispose();
  154. _scrollCtrl.dispose();
  155. _attachmentController.dispose();
  156. super.dispose();
  157. }
  158. @override
  159. void didChangeAppLifecycleState(AppLifecycleState state) {
  160. if (state == AppLifecycleState.resumed && _isPoppingToNative) {
  161. _isPoppingToNative = false;
  162. HostAppChannel.refresh();
  163. _costTypes = [];
  164. _projects = [];
  165. _departments = [];
  166. _customers = [];
  167. _employees = [];
  168. _refDataFuture = null;
  169. _refDataLoading = true;
  170. _draftHandled = false;
  171. _purposeController.clear();
  172. _remarkController.clear();
  173. _selectedDeptId = '';
  174. _selectedDeptName = '';
  175. ref.read(expenseCreateProvider(widget.editId).notifier).reset();
  176. _attachmentController.clear();
  177. _draftFuture = widget.editId == null
  178. ? ExpenseCreateController.hasDraft()
  179. : Future.value(false);
  180. _loadRefData();
  181. }
  182. }
  183. @override
  184. Widget build(BuildContext context) {
  185. final controller = ref.watch(expenseCreateProvider(widget.editId).notifier);
  186. final state = ref.watch(expenseCreateProvider(widget.editId));
  187. final r = ResponsiveHelper.of(context);
  188. final l10n = AppLocalizations.of(context);
  189. ref
  190. .read(navBarConfigProvider.notifier)
  191. .update(
  192. NavBarConfig(
  193. title: widget.editId != null
  194. ? l10n.get('editExpense')
  195. : l10n.get('expenseApply'),
  196. showBack: true,
  197. onBack: () => _doPop(),
  198. ),
  199. );
  200. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  201. final bottomInset = MediaQuery.of(context).padding.bottom;
  202. Widget pageContent = PopScope(
  203. canPop: false,
  204. onPopInvokedWithResult: (didPop, _) {
  205. if (didPop) return;
  206. _doPop();
  207. },
  208. child: Column(
  209. children: [
  210. Expanded(
  211. child: Align(
  212. alignment: Alignment.topCenter,
  213. child: ConstrainedBox(
  214. constraints: BoxConstraints(maxWidth: r.formMaxWidth),
  215. child: SingleChildScrollView(
  216. controller: _scrollCtrl,
  217. padding: const EdgeInsets.all(16),
  218. child: Column(
  219. crossAxisAlignment: CrossAxisAlignment.start,
  220. children: [
  221. _buildImportLink(),
  222. const SizedBox(height: 16),
  223. _buildBasicInfoSection(controller, state),
  224. const SizedBox(height: 16),
  225. Container(
  226. key: _detailsSectionKey,
  227. child: _buildDetailSection(controller, state),
  228. ),
  229. const SizedBox(height: 16),
  230. _buildAttachmentSection(controller, state),
  231. const SizedBox(height: 24),
  232. _buildPageFooter(),
  233. ],
  234. ),
  235. ),
  236. ),
  237. ),
  238. ),
  239. ColoredBox(
  240. color: colors.bgCard,
  241. child: Column(
  242. mainAxisSize: MainAxisSize.min,
  243. children: [
  244. _buildBottomButtons(controller, state),
  245. if (bottomInset > 0) SizedBox(height: bottomInset),
  246. ],
  247. ),
  248. ),
  249. ],
  250. ),
  251. );
  252. return FutureBuilder<bool>(
  253. future: _draftFuture,
  254. builder: (ctx, snapshot) {
  255. final hasDraft = snapshot.hasData && snapshot.data == true;
  256. if (hasDraft && !_draftHandled) {
  257. _draftHandled = true;
  258. WidgetsBinding.instance.addPostFrameCallback((_) {
  259. if (mounted) _showDraftDialog();
  260. });
  261. }
  262. return pageContent;
  263. },
  264. );
  265. }
  266. void _showDraftDialog() {
  267. final l10n = AppLocalizations.of(context);
  268. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  269. showDialog(
  270. context: context,
  271. barrierDismissible: false,
  272. builder: (ctx) => TDAlertDialog(
  273. title: l10n.get('draftFound'),
  274. content: l10n.get('draftRestorePrompt'),
  275. leftBtn: TDDialogButtonOptions(
  276. title: l10n.get('discard'),
  277. titleColor: colors.textSecondary,
  278. action: () {
  279. Navigator.pop(ctx);
  280. ExpenseCreateController.deleteDraft();
  281. },
  282. ),
  283. rightBtn: TDDialogButtonOptions(
  284. title: l10n.get('restore'),
  285. titleColor: colors.primary,
  286. action: () async {
  287. Navigator.pop(ctx);
  288. final draft = await ExpenseCreateController.loadDraft();
  289. if (draft != null && mounted) {
  290. final api = ref.read(expenseApiProvider);
  291. ref
  292. .read(expenseCreateProvider(widget.editId).notifier)
  293. .restoreFromDraft(draft, api);
  294. _purposeController.text = draft.purpose;
  295. _remarkController.text = draft.remark;
  296. if (draft.attachments.isNotEmpty) {
  297. await _attachmentController.restoreFromPaths(draft.attachments);
  298. }
  299. }
  300. },
  301. ),
  302. ),
  303. );
  304. }
  305. // ═══ API 数据 → 弹窗类型转换 ═══
  306. List<CostCategory> get _dialogCategories => _costTypes
  307. .map(
  308. (c) => CostCategory(
  309. code: c.typeNo,
  310. nameKey: c.typeName,
  311. acctSubjectId: c.accNo,
  312. acctSubjectName: c.accName,
  313. ),
  314. )
  315. .toList();
  316. List<Project> get _dialogProjects => _projects
  317. .map((p) => Project(id: int.tryParse(p.objNo) ?? 0, name: p.name))
  318. .toList();
  319. List<CostDept> get _dialogCostDepts =>
  320. _departments.map((d) => CostDept(id: d.dep, name: d.name)).toList();
  321. String _currencyLabel(String code) {
  322. final match = _currencies.where((c) => c.curId == code);
  323. return match.isNotEmpty ? '${match.first.curId}/${match.first.name}' : code;
  324. }
  325. List<CustomerVendor> get _dialogCustomers =>
  326. _customers.map((c) => CustomerVendor(id: c.cusNo, name: c.name)).toList();
  327. List<EmployeeItem> get _dialogEmployees => _employees;
  328. void _autoSelectDept() {
  329. if (_selectedDeptId.isNotEmpty) return;
  330. final dep = HostAppChannel.dep;
  331. if (dep.isEmpty) return;
  332. final match = _departments.where((d) => d.dep == dep);
  333. if (match.isNotEmpty) {
  334. _selectedDeptId = match.first.dep;
  335. _selectedDeptName = match.first.name;
  336. }
  337. }
  338. void _showDeptPicker() {
  339. if (_departments.isEmpty) {
  340. TDToast.showText(
  341. AppLocalizations.of(context).get('noData'),
  342. context: context,
  343. );
  344. return;
  345. }
  346. final l10n = AppLocalizations.of(context);
  347. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  348. final labels = _departments.map((d) => '${d.dep}/${d.name}').toList();
  349. TDPicker.showMultiPicker(
  350. context,
  351. title: l10n.get('expenseDept'),
  352. backgroundColor: colors.bgCard,
  353. data: [labels],
  354. onConfirm: (selected) {
  355. if (selected.isNotEmpty && selected[0] is int) {
  356. final idx = selected[0] as int;
  357. if (idx >= 0 && idx < labels.length) {
  358. Navigator.of(context).pop();
  359. setState(() {
  360. _selectedDeptId = _departments[idx].dep;
  361. _selectedDeptName = _departments[idx].name;
  362. });
  363. }
  364. }
  365. },
  366. );
  367. }
  368. Map<String, dynamic> _buildSubmitData(ExpenseCreateState state) {
  369. final expense = state.expense;
  370. return {
  371. 'HeadData': {
  372. 'BX_DD': _today(),
  373. 'DEP': _selectedDeptId,
  374. 'USR_NO': HostAppChannel.usr,
  375. 'PAY_ID': expense.paymentMethod,
  376. 'PRT_SW': 'N',
  377. 'USR': HostAppChannel.usr,
  378. 'REM': expense.remark,
  379. 'CUR_ID': expense.currencyCode,
  380. 'EXC_RTO': 1,
  381. 'REASON': expense.purpose,
  382. 'VOH_ID': expense.isGenerateVoucher ? 'T' : 'F',
  383. },
  384. 'BodyData1': expense.details.asMap().entries.map((e) {
  385. final i = e.key;
  386. final d = e.value;
  387. return {
  388. 'ITM': i + 1,
  389. 'BX_DD': _today(),
  390. 'ACC_NO': d.acctSubjectId,
  391. 'AMT': d.amount,
  392. 'AMTN': d.totalAmount,
  393. 'AMTN_SH': d.approvedAmount > 0 ? d.approvedAmount : d.totalAmount,
  394. 'REM': d.remark,
  395. 'CUST': d.customerVendorId,
  396. 'IDX_NO': d.expenseCategory,
  397. 'OBJ_NO': d.projectId.isNotEmpty ? d.projectId : '',
  398. 'AMTN_BT': d.offsetAmount,
  399. 'TAX': d.taxAmount,
  400. 'TAX_RTO': d.taxRate,
  401. 'DEP': d.costDeptId,
  402. 'AE_NO': d.aeNo,
  403. 'AE_DD': d.aeDd,
  404. 'BNK_NO': d.bankName,
  405. 'BNK_ID': d.bankAccount,
  406. 'ACCNAME': d.bankAccountName,
  407. 'SQ_MAN': d.sqMan.isNotEmpty ? d.sqMan : HostAppChannel.usr,
  408. };
  409. }).toList(),
  410. };
  411. }
  412. Widget _buildImportLink() {
  413. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  414. final l10n = AppLocalizations.of(context);
  415. return GestureDetector(
  416. onTap: () async {
  417. final result = await GoRouter.of(
  418. context,
  419. ).push<List<ImportableItem>>('/expense/import-apply');
  420. if (result == null || result.isEmpty || !mounted) return;
  421. // 将选中的导入数据转换为明细,先移除同单号的旧数据
  422. final controller = ref.read(
  423. expenseCreateProvider(widget.editId).notifier,
  424. );
  425. final aeNos = result.map((e) => e.aeNo).toSet();
  426. for (final aeNo in aeNos) {
  427. controller.removeDetailsByAeNo(aeNo);
  428. }
  429. final now = DateTime.now();
  430. for (final item in result) {
  431. controller.addDetail(
  432. ExpenseDetailModel(
  433. id: '${now.millisecondsSinceEpoch}_${item.itm}',
  434. expenseId: '',
  435. expenseApplyId: '',
  436. expenseApplyNo: item.aeNo,
  437. expenseApplyDate: item.aeDd.isNotEmpty
  438. ? DateTime.tryParse(item.aeDd)
  439. : null,
  440. expenseCategory: item.typeNo,
  441. categoryName: item.typeName,
  442. purpose: item.rem,
  443. priority: item.priority,
  444. projectId: item.objNo,
  445. projectName: item.objName,
  446. costDeptId: item.dep,
  447. costDeptName: item.depName,
  448. acctSubjectId: item.accNo,
  449. acctSubjectName: item.accName,
  450. amount: item.amtnYj,
  451. taxRate: 0,
  452. taxAmount: 0,
  453. totalAmount: item.amtnYj,
  454. currencyCode: '',
  455. exchangeRate: 1.0,
  456. baseAmount: item.amtnYj,
  457. approvedAmount: item.amtnYj,
  458. customerVendorId: '',
  459. customerVendorName: '',
  460. offsetAmount: 0,
  461. bankName: '',
  462. bankAccountName: '',
  463. bankAccount: '',
  464. remark: item.rem,
  465. sortOrder: item.itm,
  466. attachments: const [],
  467. sqMan: item.sqMan,
  468. sqManName: item.sqName,
  469. aeNo: item.aeNo,
  470. aeDd: item.aeDd,
  471. createTime: now,
  472. updateTime: now,
  473. ),
  474. );
  475. }
  476. controller.recalculateAmount();
  477. TDToast.showSuccess(l10n.get('importSuccess'), context: context);
  478. _scrollToDetailSection();
  479. },
  480. child: Container(
  481. height: 44,
  482. decoration: BoxDecoration(
  483. color: colors.primaryLight,
  484. borderRadius: BorderRadius.circular(8),
  485. ),
  486. child: Row(
  487. mainAxisAlignment: MainAxisAlignment.center,
  488. children: [
  489. Icon(Icons.download, size: 14, color: colors.primary),
  490. const SizedBox(width: 8),
  491. Text(
  492. l10n.get('importApprovedPreApp'),
  493. style: TextStyle(
  494. fontSize: AppFontSizes.body,
  495. color: colors.primary,
  496. ),
  497. ),
  498. ],
  499. ),
  500. ),
  501. );
  502. }
  503. Widget _buildBasicInfoSection(
  504. ExpenseCreateController controller,
  505. ExpenseCreateState state,
  506. ) {
  507. final l10n = AppLocalizations.of(context);
  508. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  509. final expense = state.expense;
  510. return FormSection(
  511. title: l10n.get('basicInfo'),
  512. leadingIcon: Icons.info_outline,
  513. children: [
  514. FormFieldRow(
  515. label: l10n.get('date'),
  516. value: _today(),
  517. readOnly: true,
  518. showArrow: false,
  519. ),
  520. const SizedBox(height: 16),
  521. FormFieldRow(
  522. label: l10n.get('expensePersonnel'),
  523. value:
  524. HostAppChannel.usr.isNotEmpty && HostAppChannel.usrName.isNotEmpty
  525. ? '${HostAppChannel.usr}/${HostAppChannel.usrName}'
  526. : '--',
  527. readOnly: true,
  528. showArrow: false,
  529. ),
  530. const SizedBox(height: 16),
  531. FormFieldRow(
  532. label: l10n.get('expenseDept'),
  533. value: _selectedDeptName.isNotEmpty
  534. ? '$_selectedDeptId/$_selectedDeptName'
  535. : null,
  536. hint: l10n.get('pleaseSelect'),
  537. onTap: _refDataLoading ? null : () => _showDeptPicker(),
  538. ),
  539. const SizedBox(height: 16),
  540. _label(l10n.get('expenseReason'), required: true),
  541. const SizedBox(height: 8),
  542. TDTextarea(
  543. controller: _purposeController,
  544. focusNode: _purposeFocus,
  545. hintText: l10n.get('enterExpenseReason'),
  546. maxLines: 4,
  547. minLines: 1,
  548. maxLength: 500,
  549. indicator: true,
  550. padding: EdgeInsets.zero,
  551. bordered: true,
  552. backgroundColor: colors.bgPage,
  553. onChanged: (_) => controller.updatePurpose(_purposeController.text),
  554. ),
  555. const SizedBox(height: 16),
  556. FormFieldRow(
  557. label: l10n.get('paymentMethod'),
  558. value: expense.paymentMethod,
  559. hint: l10n.get('pleaseEnter'),
  560. onTap: () => _showTextInput(
  561. l10n.get('paymentMethod'),
  562. (v) => controller.updatePaymentMethod(v),
  563. initialText: expense.paymentMethod,
  564. ),
  565. onClear: () => controller.updatePaymentMethod(''),
  566. ),
  567. const SizedBox(height: 16),
  568. FormFieldRow(
  569. label: l10n.get('currency'),
  570. value: expense.currencyCode.isNotEmpty
  571. ? _currencyLabel(expense.currencyCode)
  572. : null,
  573. hint: l10n.get('selectCurrency'),
  574. onTap: () => _showCurrencyPicker(controller, expense.currencyCode),
  575. onClear: () => controller.updateCurrencyCode(''),
  576. ),
  577. const SizedBox(height: 16),
  578. Row(
  579. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  580. children: [
  581. Text(l10n.get('generateVoucher'), style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.textSecondary)),
  582. TDSwitch(
  583. isOn: expense.isGenerateVoucher,
  584. onChanged: (v) {
  585. controller.setGenerateVoucher(v);
  586. return v;
  587. },
  588. ),
  589. ],
  590. ),
  591. const SizedBox(height: 16),
  592. _label(l10n.get('remark')),
  593. const SizedBox(height: 8),
  594. TDTextarea(
  595. controller: _remarkController,
  596. focusNode: _remarkFocus,
  597. hintText: l10n.get('enterRemark'),
  598. maxLines: 3,
  599. minLines: 1,
  600. maxLength: 500,
  601. indicator: true,
  602. padding: EdgeInsets.zero,
  603. bordered: true,
  604. backgroundColor: colors.bgPage,
  605. onChanged: (_) => controller.updateRemark(_remarkController.text),
  606. ),
  607. ],
  608. );
  609. }
  610. Widget _buildDetailSection(
  611. ExpenseCreateController controller,
  612. ExpenseCreateState state,
  613. ) {
  614. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  615. final l10n = AppLocalizations.of(context);
  616. final totalApproved = state.expense.details.fold<double>(
  617. 0,
  618. (sum, d) => sum + d.approvedAmount,
  619. );
  620. return FormSection(
  621. title: l10n.get('expenseDetails'),
  622. leadingIcon: Icons.receipt_long_outlined,
  623. showAction: true,
  624. actionText: l10n.get('add'),
  625. onActionTap: () => _showAddDetailDialog(controller),
  626. children: [
  627. if (state.expense.details.isEmpty)
  628. Padding(
  629. padding: const EdgeInsets.symmetric(vertical: 8),
  630. child: Text(
  631. l10n.get('noDetailHint'),
  632. style: TextStyle(
  633. fontSize: AppFontSizes.subtitle,
  634. color: colors.textPlaceholder,
  635. ),
  636. ),
  637. )
  638. else
  639. ...state.expense.details.asMap().entries.map((entry) {
  640. final d = entry.value;
  641. return GestureDetector(
  642. onTap: () =>
  643. _showAddDetailDialog(controller, editIndex: entry.key),
  644. child: Container(
  645. margin: const EdgeInsets.symmetric(vertical: 6),
  646. padding: const EdgeInsets.all(12),
  647. decoration: BoxDecoration(
  648. color: colors.bgPage,
  649. borderRadius: BorderRadius.circular(8),
  650. ),
  651. child: Row(
  652. children: [
  653. Expanded(
  654. child: Column(
  655. crossAxisAlignment: CrossAxisAlignment.start,
  656. children: [
  657. Row(
  658. children: [
  659. Expanded(
  660. child: Text(
  661. d.categoryName.isNotEmpty
  662. ? '${d.expenseCategory}/${d.categoryName}'
  663. : d.expenseCategory,
  664. style: TextStyle(
  665. fontSize: AppFontSizes.body,
  666. fontWeight: FontWeight.w500,
  667. color: colors.textPrimary,
  668. ),
  669. ),
  670. ),
  671. Column(
  672. crossAxisAlignment: CrossAxisAlignment.end,
  673. children: [
  674. Text(
  675. '¥${d.totalAmount.toStringAsFixed(2)}',
  676. style: TextStyle(
  677. fontSize: AppFontSizes.body,
  678. fontWeight: FontWeight.w600,
  679. color: colors.amountPrimary,
  680. ),
  681. ),
  682. if (d.approvedAmount > 0)
  683. Text(
  684. '¥${d.approvedAmount.toStringAsFixed(2)}',
  685. style: TextStyle(
  686. fontSize: AppFontSizes.body,
  687. fontWeight: FontWeight.w600,
  688. color: colors.success,
  689. ),
  690. ),
  691. ],
  692. ),
  693. ],
  694. ),
  695. const SizedBox(height: 2),
  696. Text(
  697. '${l10n.get('amountExcludingTax')}: ¥${d.amount.toStringAsFixed(2)}',
  698. style: TextStyle(
  699. fontSize: AppFontSizes.caption,
  700. color: colors.textSecondary,
  701. ),
  702. ),
  703. if (d.taxAmount > 0)
  704. Text(
  705. '${l10n.get('taxAmount')}: ¥${d.taxAmount.toStringAsFixed(2)}',
  706. style: TextStyle(
  707. fontSize: AppFontSizes.caption,
  708. color: colors.textSecondary,
  709. ),
  710. ),
  711. if (d.acctSubjectName.isNotEmpty)
  712. Text(
  713. '${l10n.get('acctSubject')}: ${d.acctSubjectId}/${d.acctSubjectName}',
  714. maxLines: 1,
  715. overflow: TextOverflow.ellipsis,
  716. style: TextStyle(
  717. fontSize: AppFontSizes.caption,
  718. color: colors.textSecondary,
  719. ),
  720. ),
  721. if (d.aeNo.isNotEmpty)
  722. Text(
  723. '${l10n.get('expenseApplyNo')}: ${d.aeNo}',
  724. maxLines: 1,
  725. overflow: TextOverflow.ellipsis,
  726. style: TextStyle(
  727. fontSize: AppFontSizes.caption,
  728. color: colors.textSecondary,
  729. ),
  730. ),
  731. if (d.aeDd.isNotEmpty)
  732. Text(
  733. '${l10n.get('applyDate')}: ${d.aeDd}',
  734. style: TextStyle(
  735. fontSize: AppFontSizes.caption,
  736. color: colors.textSecondary,
  737. ),
  738. ),
  739. if (d.projectName.isNotEmpty)
  740. Text(
  741. '${l10n.get('project')}: ${d.projectId}/${d.projectName}',
  742. maxLines: 1,
  743. overflow: TextOverflow.ellipsis,
  744. style: TextStyle(
  745. fontSize: AppFontSizes.caption,
  746. color: colors.textSecondary,
  747. ),
  748. ),
  749. if (d.costDeptName.isNotEmpty)
  750. Text(
  751. '${l10n.get('dept')}: ${d.costDeptId}/${d.costDeptName}',
  752. maxLines: 1,
  753. overflow: TextOverflow.ellipsis,
  754. style: TextStyle(
  755. fontSize: AppFontSizes.caption,
  756. color: colors.textSecondary,
  757. ),
  758. ),
  759. if (d.customerVendorName.isNotEmpty)
  760. Text(
  761. '${l10n.get('customerVendor')}: ${d.customerVendorId}/${d.customerVendorName}',
  762. maxLines: 1,
  763. overflow: TextOverflow.ellipsis,
  764. style: TextStyle(
  765. fontSize: AppFontSizes.caption,
  766. color: colors.textSecondary,
  767. ),
  768. ),
  769. if (d.bankAccountName.isNotEmpty)
  770. Text(
  771. '${l10n.get('bankAccountName')}: ${d.bankAccountName}',
  772. maxLines: 1,
  773. overflow: TextOverflow.ellipsis,
  774. style: TextStyle(
  775. fontSize: AppFontSizes.caption,
  776. color: colors.textSecondary,
  777. ),
  778. ),
  779. if (d.bankName.isNotEmpty)
  780. Text(
  781. '${l10n.get('bankName')}: ${d.bankName}',
  782. maxLines: 1,
  783. overflow: TextOverflow.ellipsis,
  784. style: TextStyle(
  785. fontSize: AppFontSizes.caption,
  786. color: colors.textSecondary,
  787. ),
  788. ),
  789. if (d.bankAccount.isNotEmpty)
  790. Text(
  791. '${l10n.get('bankAccount')}: ${d.bankAccount}',
  792. maxLines: 1,
  793. overflow: TextOverflow.ellipsis,
  794. style: TextStyle(
  795. fontSize: AppFontSizes.caption,
  796. color: colors.textSecondary,
  797. ),
  798. ),
  799. if (d.sqManName.isNotEmpty)
  800. Text(
  801. '${l10n.get('applicant')}: ${d.sqManName.isNotEmpty ? d.sqManName : d.sqMan}',
  802. style: TextStyle(
  803. fontSize: AppFontSizes.caption,
  804. color: colors.textSecondary,
  805. ),
  806. ),
  807. if (d.remark.isNotEmpty)
  808. Text(
  809. '${l10n.get('remark')}: ${d.remark}',
  810. maxLines: 2,
  811. overflow: TextOverflow.ellipsis,
  812. style: TextStyle(
  813. fontSize: AppFontSizes.caption,
  814. color: colors.textSecondary,
  815. ),
  816. ),
  817. ],
  818. ),
  819. ),
  820. const SizedBox(width: 8),
  821. GestureDetector(
  822. onTap: () {
  823. controller.removeDetail(entry.key);
  824. controller.recalculateAmount();
  825. },
  826. child: Icon(
  827. Icons.close,
  828. size: 18,
  829. color: colors.textSecondary,
  830. ),
  831. ),
  832. ],
  833. ),
  834. ),
  835. );
  836. }),
  837. const SizedBox(height: 8),
  838. Row(
  839. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  840. children: [
  841. Text(
  842. l10n.get('totalExpense'),
  843. style: TextStyle(
  844. fontSize: AppFontSizes.body,
  845. fontWeight: FontWeight.w600,
  846. color: colors.textPrimary,
  847. ),
  848. ),
  849. Text(
  850. '¥${state.expense.totalAmount.toStringAsFixed(2)}',
  851. style: TextStyle(
  852. fontSize: AppFontSizes.subtitle,
  853. fontWeight: FontWeight.w700,
  854. color: colors.amountPrimary,
  855. ),
  856. ),
  857. ],
  858. ),
  859. const SizedBox(height: 4),
  860. Row(
  861. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  862. children: [
  863. Text(
  864. l10n.get('approvedTotal'),
  865. style: TextStyle(
  866. fontSize: AppFontSizes.body,
  867. fontWeight: FontWeight.w600,
  868. color: colors.textPrimary,
  869. ),
  870. ),
  871. Text(
  872. '¥${totalApproved.toStringAsFixed(2)}',
  873. style: TextStyle(
  874. fontSize: AppFontSizes.subtitle,
  875. fontWeight: FontWeight.w700,
  876. color: totalApproved > 0 ? colors.success : colors.textPrimary,
  877. ),
  878. ),
  879. ],
  880. ),
  881. ],
  882. );
  883. }
  884. Widget _buildAttachmentSection(
  885. ExpenseCreateController controller,
  886. ExpenseCreateState state,
  887. ) {
  888. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  889. final l10n = AppLocalizations.of(context);
  890. return FormSection(
  891. title: l10n.get('attachmentUpload'),
  892. leadingIcon: Icons.attach_file_outlined,
  893. children: [
  894. Text(
  895. l10n.get('maxAttachment'),
  896. style: TextStyle(
  897. fontSize: AppFontSizes.caption,
  898. color: colors.textPlaceholder,
  899. ),
  900. ),
  901. const SizedBox(height: 8),
  902. AttachmentPicker(
  903. controller: _attachmentController,
  904. maxImageSizeMB: 10,
  905. maxFileSizeMB: 20,
  906. allowedExtensions: const [
  907. 'pdf',
  908. 'doc',
  909. 'docx',
  910. 'xls',
  911. 'xlsx',
  912. 'ppt',
  913. 'pptx',
  914. 'txt',
  915. ],
  916. onFileRejected: (file, reason) {
  917. if (context.mounted) TDToast.showText(reason, context: context);
  918. },
  919. ),
  920. ],
  921. );
  922. }
  923. Widget _buildBottomButtons(
  924. ExpenseCreateController controller,
  925. ExpenseCreateState state,
  926. ) {
  927. final l10n = AppLocalizations.of(context);
  928. return ActionBar(
  929. showLeft: false,
  930. centerLabel: l10n.get('saveDraft'),
  931. rightLabel: l10n.get('submit'),
  932. centerTextOnly: true,
  933. onCenterTap: () async {
  934. if (state.isSubmitting) return;
  935. controller.updateAttachments(_attachmentController.toPathList());
  936. controller.updateDept(_selectedDeptId, _selectedDeptName);
  937. final ok = await controller.saveDraft();
  938. if (mounted) {
  939. if (ok) {
  940. _forcePop();
  941. } else {
  942. TDToast.showFail(l10n.get('saveFailed'), context: context);
  943. }
  944. }
  945. },
  946. onRightTap: () async {
  947. if (state.isSubmitting) return;
  948. final err = _validate(l10n, state);
  949. if (err.isNotEmpty) {
  950. TDToast.showText(err.first, context: context);
  951. return;
  952. }
  953. LoadingDialog.show(context, text: l10n.get('submitting'));
  954. try {
  955. final data = _buildSubmitData(state);
  956. final api = ref.read(expenseApiProvider);
  957. final billNo = await api.submit(data);
  958. // 上传附件(表头 + 表身)
  959. if (_attachmentController.files.isNotEmpty) {
  960. final today = _today();
  961. final usr = HostAppChannel.usr;
  962. for (var i = 0; i < _attachmentController.files.length; i++) {
  963. final file = _attachmentController.files[i];
  964. try {
  965. await api.uploadAttachment(file.path, {
  966. 'BIL_ID': 'BX',
  967. 'BIL_NO': billNo,
  968. 'SRCITM': 0,
  969. 'ITM': i + 1,
  970. 'TAG': 1,
  971. 'EFF_DD': today,
  972. 'USR': usr,
  973. 'FILENAME': file.name,
  974. 'EXT': file.name.split('.').last,
  975. });
  976. } catch (_) {
  977. // Attachment upload failure is non-fatal
  978. }
  979. }
  980. }
  981. await ExpenseCreateController.deleteDraft();
  982. if (mounted) {
  983. LoadingDialog.hide(context);
  984. TDToast.showSuccess(
  985. l10n.get('submittedAwaitingApproval'),
  986. context: context,
  987. );
  988. GoRouter.of(context).go('/expense/list');
  989. }
  990. } catch (_) {
  991. if (mounted) {
  992. LoadingDialog.hide(context);
  993. TDToast.showFail(l10n.get('submitFailedRetry'), context: context);
  994. }
  995. }
  996. },
  997. );
  998. }
  999. Future<void> _showAddDetailDialog(
  1000. ExpenseCreateController controller, {
  1001. int? editIndex,
  1002. }) async {
  1003. if (_addingDetail) return;
  1004. _addingDetail = true;
  1005. try {
  1006. final l10n = AppLocalizations.of(context);
  1007. if (_costTypes.isEmpty) {
  1008. TDToast.showText(l10n.get('noCostTypeData'), context: context);
  1009. return;
  1010. }
  1011. final state = controller.currentState;
  1012. ExpenseDetailInputData? initialData;
  1013. if (editIndex != null) {
  1014. final d = state.expense.details[editIndex];
  1015. initialData = ExpenseDetailInputData(
  1016. category: d.expenseCategory,
  1017. categoryName: d.categoryName,
  1018. acctSubjectId: d.acctSubjectId,
  1019. acctSubjectName: d.acctSubjectName,
  1020. purpose: d.purpose,
  1021. amount: d.amount,
  1022. taxRate: d.taxRate,
  1023. projectId: d.projectId,
  1024. projectName: d.projectName,
  1025. costDeptId: d.costDeptId,
  1026. costDeptName: d.costDeptName,
  1027. customerVendorId: d.customerVendorId,
  1028. customerVendorName: d.customerVendorName,
  1029. approvedAmount: d.approvedAmount,
  1030. offsetAmount: d.offsetAmount,
  1031. bankName: d.bankName,
  1032. bankAccountName: d.bankAccountName,
  1033. bankAccount: d.bankAccount,
  1034. remark: d.remark,
  1035. attachmentPaths: d.attachments,
  1036. sqMan: d.sqMan,
  1037. sqManName: d.sqManName,
  1038. aeNo: d.aeNo,
  1039. aeDd: d.aeDd,
  1040. );
  1041. }
  1042. final result = await ExpenseDetailDialog.show(
  1043. context,
  1044. categories: _dialogCategories,
  1045. projects: _dialogProjects,
  1046. costDepts: _dialogCostDepts,
  1047. customers: _dialogCustomers,
  1048. employees: _dialogEmployees,
  1049. l10n: l10n,
  1050. initialData: initialData,
  1051. );
  1052. if (result != null && mounted) {
  1053. final now = DateTime.now();
  1054. final detail = ExpenseDetailModel(
  1055. id: editIndex != null
  1056. ? state.expense.details[editIndex].id
  1057. : now.millisecondsSinceEpoch.toString(),
  1058. expenseId: '',
  1059. expenseCategory: result.category,
  1060. categoryName: result.categoryName,
  1061. purpose: result.purpose,
  1062. amount: result.taxRate > 0
  1063. ? result.amount / (1 + result.taxRate)
  1064. : result.amount,
  1065. taxRate: result.taxRate,
  1066. taxAmount: result.taxRate > 0
  1067. ? result.amount - result.amount / (1 + result.taxRate)
  1068. : 0,
  1069. totalAmount: result.amount,
  1070. projectId: result.projectId,
  1071. projectName: result.projectName,
  1072. costDeptId: result.costDeptId,
  1073. costDeptName: result.costDeptName,
  1074. acctSubjectId: result.acctSubjectId,
  1075. acctSubjectName: result.acctSubjectName,
  1076. customerVendorId: result.customerVendorId,
  1077. customerVendorName: result.customerVendorName,
  1078. approvedAmount: result.approvedAmount,
  1079. offsetAmount: result.offsetAmount,
  1080. bankName: result.bankName,
  1081. bankAccountName: result.bankAccountName,
  1082. bankAccount: result.bankAccount,
  1083. sqMan: result.sqMan,
  1084. sqManName: result.sqManName,
  1085. aeNo: result.aeNo,
  1086. aeDd: result.aeDd,
  1087. remark: result.remark,
  1088. attachments: result.attachmentPaths,
  1089. createTime: now,
  1090. updateTime: now,
  1091. );
  1092. if (editIndex != null) {
  1093. controller.updateDetail(editIndex, detail);
  1094. } else {
  1095. controller.addDetail(detail);
  1096. }
  1097. controller.recalculateAmount();
  1098. }
  1099. } finally {
  1100. _addingDetail = false;
  1101. }
  1102. }
  1103. void _showCurrencyPicker(ExpenseCreateController controller, String cur) {
  1104. if (_currencies.isEmpty) {
  1105. TDToast.showText(
  1106. AppLocalizations.of(context).get('noData'),
  1107. context: context,
  1108. );
  1109. return;
  1110. }
  1111. final l10n = AppLocalizations.of(context);
  1112. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1113. final codes = _currencies.map((c) => c.curId).toList();
  1114. final labels = _currencies.map((c) => '${c.curId}/${c.name}').toList();
  1115. TDPicker.showMultiPicker(
  1116. context,
  1117. title: l10n.get('selectCurrency'),
  1118. backgroundColor: colors.bgCard,
  1119. data: [labels],
  1120. onConfirm: (s) {
  1121. if (s.isNotEmpty && s[0] is int) {
  1122. final i = s[0] as int;
  1123. if (i >= 0 && i < codes.length) {
  1124. Navigator.of(context).pop();
  1125. controller.updateCurrencyCode(codes[i]);
  1126. }
  1127. }
  1128. },
  1129. );
  1130. }
  1131. void _showTextInput(
  1132. String title,
  1133. Function(String) onConfirm, {
  1134. String initialText = '',
  1135. }) {
  1136. FocusScope.of(context).unfocus();
  1137. final l10n = AppLocalizations.of(context);
  1138. final c = TextEditingController(text: initialText);
  1139. showGeneralDialog(
  1140. context: context,
  1141. pageBuilder: (ctx, animation, secondaryAnimation) => TDInputDialog(
  1142. textEditingController: c,
  1143. title: title,
  1144. hintText: l10n.get('pleaseEnter'),
  1145. leftBtn: TDDialogButtonOptions(
  1146. title: l10n.get('cancel'),
  1147. action: () => Navigator.pop(ctx),
  1148. ),
  1149. rightBtn: TDDialogButtonOptions(
  1150. title: l10n.get('confirm'),
  1151. action: () {
  1152. onConfirm(c.text);
  1153. Navigator.pop(ctx);
  1154. },
  1155. ),
  1156. ),
  1157. );
  1158. }
  1159. Widget _label(String t, {bool required = false}) {
  1160. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1161. return Text.rich(
  1162. TextSpan(
  1163. children: [
  1164. TextSpan(
  1165. text: t,
  1166. style: TextStyle(
  1167. fontSize: AppFontSizes.subtitle,
  1168. color: colors.textSecondary,
  1169. ),
  1170. ),
  1171. if (required)
  1172. TextSpan(
  1173. text: ' *',
  1174. style: TextStyle(
  1175. fontSize: AppFontSizes.subtitle,
  1176. color: colors.danger,
  1177. ),
  1178. ),
  1179. ],
  1180. ),
  1181. );
  1182. }
  1183. List<String> _validate(AppLocalizations l10n, ExpenseCreateState state) {
  1184. final e = <String>[];
  1185. if (_purposeController.text.trim().isEmpty) {
  1186. e.add(l10n.get('enterExpenseReason'));
  1187. }
  1188. if (state.expense.details.isEmpty) {
  1189. e.add(l10n.get('addAtLeastOneDetail'));
  1190. }
  1191. return e;
  1192. }
  1193. bool _hasUnsaved(ExpenseCreateState state) =>
  1194. _purposeController.text.isNotEmpty ||
  1195. state.expense.paymentMethod.isNotEmpty ||
  1196. state.expense.currencyCode.isNotEmpty ||
  1197. _remarkController.text.isNotEmpty ||
  1198. state.expense.details.isNotEmpty ||
  1199. _attachmentController.files.isNotEmpty ||
  1200. _selectedDeptId.isNotEmpty;
  1201. void _doPop() {
  1202. final l10n = AppLocalizations.of(context);
  1203. final state = ref.read(expenseCreateProvider(widget.editId));
  1204. if (_hasUnsaved(state)) {
  1205. _showConfirmDialog(
  1206. l10n.get('confirmExit'),
  1207. l10n.get('unsavedContentWarning'),
  1208. l10n.get('continueEditing'),
  1209. l10n.get('discardAndExit'),
  1210. () async {
  1211. try {
  1212. await ExpenseCreateController.deleteDraft();
  1213. } catch (_) {}
  1214. if (!mounted) return;
  1215. setState(() {
  1216. _selectedDeptId = '';
  1217. _selectedDeptName = '';
  1218. });
  1219. ref.read(expenseCreateProvider(widget.editId).notifier).reset();
  1220. _forcePop();
  1221. },
  1222. );
  1223. } else {
  1224. _forcePop();
  1225. }
  1226. }
  1227. void _forcePop() {
  1228. _isPoppingToNative = true;
  1229. SystemNavigator.pop();
  1230. }
  1231. void _showConfirmDialog(
  1232. String title,
  1233. String content,
  1234. String leftText,
  1235. String rightText,
  1236. VoidCallback onConfirm,
  1237. ) {
  1238. FocusScope.of(context).unfocus();
  1239. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1240. showDialog(
  1241. context: context,
  1242. useRootNavigator: true,
  1243. builder: (ctx) => TDAlertDialog(
  1244. title: title,
  1245. content: content,
  1246. buttonStyle: TDDialogButtonStyle.text,
  1247. leftBtn: TDDialogButtonOptions(
  1248. title: leftText,
  1249. titleColor: colors.primary,
  1250. action: () => Navigator.pop(ctx),
  1251. ),
  1252. rightBtn: TDDialogButtonOptions(
  1253. title: rightText,
  1254. titleColor: colors.danger,
  1255. action: () {
  1256. Navigator.pop(ctx);
  1257. onConfirm();
  1258. },
  1259. ),
  1260. ),
  1261. );
  1262. }
  1263. Widget _buildPageFooter() {
  1264. final l10n = AppLocalizations.of(context);
  1265. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1266. return Center(
  1267. child: Padding(
  1268. padding: const EdgeInsets.only(bottom: 16),
  1269. child: Row(
  1270. mainAxisSize: MainAxisSize.min,
  1271. children: [
  1272. Icon(
  1273. Icons.rocket_launch_outlined,
  1274. size: 16,
  1275. color: colors.textPlaceholder,
  1276. ),
  1277. const SizedBox(width: 6),
  1278. Text(
  1279. l10n.get('pageFooter'),
  1280. style: TextStyle(
  1281. fontSize: AppFontSizes.caption,
  1282. color: colors.textPlaceholder,
  1283. ),
  1284. ),
  1285. ],
  1286. ),
  1287. ),
  1288. );
  1289. }
  1290. String _today() {
  1291. final n = DateTime.now();
  1292. return '${n.year}-${n.month.toString().padLeft(2, '0')}-${n.day.toString().padLeft(2, '0')}';
  1293. }
  1294. }