expense_application_apply_page.dart 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:go_router/go_router.dart';
  4. import 'package:tdesign_flutter/tdesign_flutter.dart';
  5. import '../../core/i18n/app_localizations.dart';
  6. import '../../shared/widgets/action_bar.dart';
  7. import '../../shared/widgets/form_section.dart';
  8. import '../../shared/widgets/form_field_row.dart';
  9. import '../../shared/widgets/nav_bar_config.dart';
  10. import '../../core/theme/app_colors.dart';
  11. import '../../core/theme/app_colors_extension.dart';
  12. import '../../core/constants/enums.dart';
  13. import '../../core/data/mock_api_data.dart';
  14. class ExpenseApplicationApplyPage extends ConsumerStatefulWidget {
  15. final String? id;
  16. const ExpenseApplicationApplyPage({super.key, this.id});
  17. @override
  18. ConsumerState<ExpenseApplicationApplyPage> createState() =>
  19. _ExpenseApplicationApplyPageState();
  20. }
  21. class _ExpenseApplicationApplyPageState
  22. extends ConsumerState<ExpenseApplicationApplyPage> {
  23. // ── 基本信息 ──
  24. String _urgency = Urgency.normal.value;
  25. final Set<String> _expenseTypes = {};
  26. bool _isTaxIncluded = false;
  27. final _purposeController = TextEditingController();
  28. String _validUntil = '';
  29. // ── 关联管控 ──
  30. String? _selectedProjectName;
  31. int? _selectedProjectId;
  32. String? _selectedSubjectName;
  33. int? _selectedSubjectId;
  34. double _availableBudget = 0;
  35. final _referenceNoController = TextEditingController();
  36. // ── 费用明细 ──
  37. final List<_DetailItem> _details = [];
  38. int _detailIdCounter = 1;
  39. // ── 附件 ──
  40. final List<String> _attachments = [];
  41. // ── 专用字段 ──
  42. String _estimatedStartDate = '';
  43. String _estimatedEndDate = '';
  44. bool _isOvernight = false;
  45. String? _transportType;
  46. String? _entertainmentTarget;
  47. String? _entertainmentLevel;
  48. int _guestCount = 1;
  49. int _companionCount = 0;
  50. String _entertainmentVenue = '';
  51. String _meetingStartDate = '';
  52. String _meetingEndDate = '';
  53. String _meetingVenue = '';
  54. @override
  55. void dispose() {
  56. _purposeController.dispose();
  57. _referenceNoController.dispose();
  58. super.dispose();
  59. }
  60. @override
  61. Widget build(BuildContext context) {
  62. final l10n = AppLocalizations.of(context);
  63. ref
  64. .read(navBarConfigProvider.notifier)
  65. .update(
  66. NavBarConfig(
  67. title: l10n.get('expenseApplyRequest'),
  68. showBack: true,
  69. onBack: () {
  70. if (_hasUnsaved()) {
  71. _showConfirmDialog(
  72. l10n.get('confirmExit'),
  73. l10n.get('unsavedContentWarning'),
  74. l10n.get('continueEditing'),
  75. l10n.get('discardAndExit'),
  76. () => context.pop(),
  77. );
  78. } else {
  79. context.pop();
  80. }
  81. },
  82. ),
  83. );
  84. return PopScope(
  85. canPop: false,
  86. onPopInvokedWithResult: (didPop, _) {
  87. if (!didPop) {
  88. if (_hasUnsaved()) {
  89. _showConfirmDialog(
  90. l10n.get('confirmExit'),
  91. l10n.get('unsavedContentWarning'),
  92. l10n.get('continueEditing'),
  93. l10n.get('discardAndExit'),
  94. () => context.pop(),
  95. );
  96. } else {
  97. context.pop();
  98. }
  99. }
  100. },
  101. child: Column(
  102. children: [
  103. Expanded(
  104. child: GestureDetector(
  105. onTap: () => FocusScope.of(context).unfocus(),
  106. child: SingleChildScrollView(
  107. padding: const EdgeInsets.all(16),
  108. child: Column(
  109. children: [
  110. _buildBasicInfo(l10n),
  111. _buildTypeSpecificFields(l10n),
  112. _buildControlSection(l10n),
  113. const SizedBox(height: 16),
  114. _buildDetailsSection(l10n),
  115. const SizedBox(height: 16),
  116. _buildAttachmentSection(l10n),
  117. const SizedBox(height: 80),
  118. ],
  119. ),
  120. ),
  121. ),
  122. ),
  123. _buildBottomBar(l10n),
  124. ],
  125. ),
  126. );
  127. }
  128. // ═══ 1. 基本信息 ═══
  129. Widget _buildBasicInfo(AppLocalizations l10n) {
  130. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  131. return FormSection(
  132. title: l10n.get('basicInfo'),
  133. leadingIcon: Icons.info_outline,
  134. children: [
  135. FormFieldRow(
  136. label: l10n.get('applicant'),
  137. value: '张三',
  138. readOnly: true,
  139. showArrow: false,
  140. ),
  141. const SizedBox(height: 16),
  142. FormFieldRow(
  143. label: l10n.get('department'),
  144. value: '技术部',
  145. readOnly: true,
  146. showArrow: false,
  147. ),
  148. const SizedBox(height: 16),
  149. FormFieldRow(
  150. label: l10n.get('date'),
  151. value: _today(),
  152. readOnly: true,
  153. showArrow: false,
  154. ),
  155. const SizedBox(height: 16),
  156. _label(l10n.get('emergencyLevel'), required: true),
  157. const SizedBox(height: 8),
  158. _buildUrgencyRadio(l10n),
  159. const SizedBox(height: 16),
  160. _label(l10n.get('expenseType'), required: true),
  161. const SizedBox(height: 8),
  162. Wrap(
  163. spacing: 8,
  164. runSpacing: 8,
  165. children: ExpenseType.values.map((opt) {
  166. final sel = _expenseTypes.contains(opt.value);
  167. return GestureDetector(
  168. onTap: () => setState(() {
  169. if (sel) {
  170. _expenseTypes.remove(opt.value);
  171. } else {
  172. _expenseTypes.add(opt.value);
  173. final hints = {
  174. 'travel': 'hintTravelFields',
  175. 'entertainment': 'hintEntertainmentFields',
  176. 'meeting': 'hintMeetingFields',
  177. };
  178. final hintKey = hints[opt.value];
  179. if (hintKey != null) {
  180. TDMessage.showMessage(
  181. context: context,
  182. content: l10n.get(hintKey),
  183. theme: MessageTheme.info,
  184. icon: true,
  185. marquee: MessageMarquee(speed: 3000, loop: 1, delay: 300),
  186. duration: 3000,
  187. );
  188. }
  189. }
  190. }),
  191. child: TDTag(
  192. l10n.get(opt.labelKey),
  193. size: TDTagSize.large,
  194. theme: sel ? TDTagTheme.primary : TDTagTheme.defaultTheme,
  195. isOutline: !sel,
  196. ),
  197. );
  198. }).toList(),
  199. ),
  200. const SizedBox(height: 16),
  201. _label(l10n.get('feeReason'), required: true),
  202. const SizedBox(height: 8),
  203. TDTextarea(
  204. controller: _purposeController,
  205. hintText: l10n.get('enterFeeReason'),
  206. maxLines: 4,
  207. minLines: 1,
  208. maxLength: 500,
  209. indicator: true,
  210. padding: EdgeInsets.zero,
  211. bordered: true,
  212. backgroundColor: colors.bgPage,
  213. ),
  214. const SizedBox(height: 16),
  215. FormFieldRow(
  216. label: l10n.get('validUntil'),
  217. value: _validUntil,
  218. hint: l10n.get('pleaseSelect'),
  219. onTap: () => _pickDate((d) => setState(() => _validUntil = d)),
  220. ),
  221. ],
  222. );
  223. }
  224. Widget _buildUrgencyRadio(AppLocalizations l10n) {
  225. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  226. return Row(
  227. children: Urgency.values.asMap().entries.map((e) {
  228. final sel = _urgency == e.value.value;
  229. final isCritical = e.value.value == Urgency.critical.value;
  230. final activeColor = isCritical ? colors.danger : colors.primary;
  231. return Padding(
  232. padding: EdgeInsets.only(right: e.key < 2 ? 24 : 0),
  233. child: GestureDetector(
  234. behavior: HitTestBehavior.opaque,
  235. onTap: () => setState(() => _urgency = e.value.value),
  236. child: Row(
  237. mainAxisSize: MainAxisSize.min,
  238. children: [
  239. Container(
  240. width: 18,
  241. height: 18,
  242. decoration: BoxDecoration(
  243. shape: BoxShape.circle,
  244. border: Border.all(
  245. color: sel ? activeColor : colors.textPlaceholder,
  246. width: 2,
  247. ),
  248. ),
  249. child: sel
  250. ? Center(
  251. child: Container(
  252. width: 8,
  253. height: 8,
  254. decoration: BoxDecoration(
  255. shape: BoxShape.circle,
  256. color: activeColor,
  257. ),
  258. ),
  259. )
  260. : null,
  261. ),
  262. const SizedBox(width: 6),
  263. Text(
  264. l10n.get(e.value.labelKey),
  265. style: TextStyle(
  266. fontSize: AppFontSizes.subtitle,
  267. color: sel ? activeColor : colors.textPrimary,
  268. ),
  269. ),
  270. ],
  271. ),
  272. ),
  273. );
  274. }).toList(),
  275. );
  276. }
  277. // ═══ 2. 类型专用字段 ═══
  278. Widget _buildTypeSpecificFields(AppLocalizations l10n) {
  279. final ws = <Widget>[];
  280. if (_expenseTypes.contains('travel')) ws.add(_buildTravelFields(l10n));
  281. if (_expenseTypes.contains('entertainment')) {
  282. if (ws.isNotEmpty) ws.add(const SizedBox(height: 16));
  283. ws.add(_buildEntertainmentFields(l10n));
  284. }
  285. if (_expenseTypes.contains('meeting')) {
  286. if (ws.isNotEmpty) ws.add(const SizedBox(height: 16));
  287. ws.add(_buildMeetingFields(l10n));
  288. }
  289. if (ws.isEmpty) return const SizedBox(height: 16);
  290. return Column(
  291. children: [const SizedBox(height: 16), ...ws, const SizedBox(height: 16)],
  292. );
  293. }
  294. Widget _buildTravelFields(AppLocalizations l10n) {
  295. return FormSection(
  296. title: l10n.get('travelExpense'),
  297. leadingIcon: Icons.flight_outlined,
  298. children: [
  299. FormFieldRow(
  300. label: l10n.get('estimatedStartDate'),
  301. value: _estimatedStartDate,
  302. hint: l10n.get('pleaseSelect'),
  303. required: true,
  304. onTap: () =>
  305. _pickDate((d) => setState(() => _estimatedStartDate = d)),
  306. ),
  307. const SizedBox(height: 16),
  308. FormFieldRow(
  309. label: l10n.get('estimatedEndDate'),
  310. value: _estimatedEndDate,
  311. hint: l10n.get('pleaseSelect'),
  312. required: true,
  313. onTap: () => _pickDate((d) => setState(() => _estimatedEndDate = d)),
  314. ),
  315. const SizedBox(height: 16),
  316. Row(
  317. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  318. children: [
  319. _label(l10n.get('isOvernight')),
  320. TDSwitch(
  321. isOn: _isOvernight,
  322. onChanged: (v) {
  323. setState(() => _isOvernight = v);
  324. return true;
  325. },
  326. ),
  327. ],
  328. ),
  329. const SizedBox(height: 16),
  330. FormFieldRow(
  331. label: l10n.get('transportType'),
  332. value: _transportType != null
  333. ? l10n.get(
  334. TransportType.values
  335. .firstWhere((t) => t.value == _transportType)
  336. .labelKey,
  337. )
  338. : null,
  339. hint: l10n.get('pleaseSelect'),
  340. onTap: () => _showEnumPicker(
  341. l10n.get('selectTransport'),
  342. TransportType.values,
  343. (v) => setState(() => _transportType = v),
  344. ),
  345. ),
  346. ],
  347. );
  348. }
  349. Widget _buildEntertainmentFields(AppLocalizations l10n) {
  350. return FormSection(
  351. title: l10n.get('entertainmentExpense'),
  352. leadingIcon: Icons.people_outline,
  353. children: [
  354. FormFieldRow(
  355. label: l10n.get('entertainmentTargetUnit'),
  356. value: _entertainmentTarget,
  357. hint: l10n.get('pleaseEnter'),
  358. required: true,
  359. onTap: () => _showTextInput(
  360. l10n.get('entertainmentTargetUnit'),
  361. (v) => setState(() => _entertainmentTarget = v),
  362. initialText: _entertainmentTarget ?? '',
  363. ),
  364. ),
  365. const SizedBox(height: 16),
  366. FormFieldRow(
  367. label: l10n.get('entertainmentLevel'),
  368. value: _entertainmentLevel != null
  369. ? l10n.get(
  370. EntertainmentLevel.values
  371. .firstWhere((e) => e.value == _entertainmentLevel)
  372. .labelKey,
  373. )
  374. : null,
  375. hint: l10n.get('pleaseSelect'),
  376. onTap: () => _showEnumPicker(
  377. l10n.get('selectEntertainmentLevel'),
  378. EntertainmentLevel.values,
  379. (v) => setState(() => _entertainmentLevel = v),
  380. ),
  381. ),
  382. const SizedBox(height: 16),
  383. FormFieldRow(
  384. label: l10n.get('externalCount'),
  385. value: '$_guestCount',
  386. onTap: () => _showNumberInput(
  387. l10n.get('externalCount'),
  388. (v) => setState(() => _guestCount = v),
  389. initialValue: _guestCount,
  390. ),
  391. ),
  392. const SizedBox(height: 16),
  393. FormFieldRow(
  394. label: l10n.get('internalCount'),
  395. value: '$_companionCount',
  396. onTap: () => _showNumberInput(
  397. l10n.get('internalCount'),
  398. (v) => setState(() => _companionCount = v),
  399. initialValue: _companionCount,
  400. ),
  401. ),
  402. const SizedBox(height: 16),
  403. FormFieldRow(
  404. label: l10n.get('venue'),
  405. value: _entertainmentVenue,
  406. hint: l10n.get('pleaseEnterLocation'),
  407. onTap: () => _showTextInput(
  408. l10n.get('venue'),
  409. (v) => setState(() => _entertainmentVenue = v),
  410. initialText: _entertainmentVenue,
  411. ),
  412. ),
  413. ],
  414. );
  415. }
  416. Widget _buildMeetingFields(AppLocalizations l10n) {
  417. return FormSection(
  418. title: l10n.get('meetingExpense'),
  419. leadingIcon: Icons.meeting_room_outlined,
  420. children: [
  421. FormFieldRow(
  422. label: l10n.get('estimatedStartDate'),
  423. value: _meetingStartDate,
  424. hint: l10n.get('pleaseSelect'),
  425. required: true,
  426. onTap: () => _pickDate((d) => setState(() => _meetingStartDate = d)),
  427. ),
  428. const SizedBox(height: 16),
  429. FormFieldRow(
  430. label: l10n.get('estimatedEndDate'),
  431. value: _meetingEndDate,
  432. hint: l10n.get('pleaseSelect'),
  433. required: true,
  434. onTap: () => _pickDate((d) => setState(() => _meetingEndDate = d)),
  435. ),
  436. const SizedBox(height: 16),
  437. FormFieldRow(
  438. label: l10n.get('venue'),
  439. value: _meetingVenue,
  440. hint: l10n.get('pleaseEnterMeetingLocation'),
  441. onTap: () => _showTextInput(
  442. l10n.get('meetingLocation'),
  443. (v) => setState(() => _meetingVenue = v),
  444. initialText: _meetingVenue,
  445. ),
  446. ),
  447. ],
  448. );
  449. }
  450. // ═══ 3. 关联管控 ═══
  451. Widget _buildControlSection(AppLocalizations l10n) {
  452. return FormSection(
  453. title: l10n.get('relatedControl'),
  454. leadingIcon: Icons.link_outlined,
  455. children: [
  456. FormFieldRow(
  457. label: l10n.get('relatedProject'),
  458. value: _selectedProjectName,
  459. hint: l10n.get('selectProject'),
  460. required: true,
  461. onTap: () {
  462. _showListPicker(
  463. l10n.get('selectProject'),
  464. mockProjects.map((p) => p.name).toList(),
  465. (v) {
  466. final p = mockProjects.firstWhere((x) => x.name == v);
  467. setState(() {
  468. _selectedProjectId = p.id;
  469. _selectedProjectName = p.name;
  470. _selectedSubjectName = null;
  471. _selectedSubjectId = null;
  472. _availableBudget = 0;
  473. });
  474. },
  475. );
  476. },
  477. ),
  478. const SizedBox(height: 16),
  479. FormFieldRow(
  480. label: l10n.get('budgetSubject'),
  481. value: _selectedSubjectName,
  482. hint: l10n.get('selectSubject'),
  483. required: true,
  484. onTap: _selectedProjectId != null
  485. ? () {
  486. _showListPicker(
  487. l10n.get('selectSubject'),
  488. mockBudgetSubjects.map((s) => s.name).toList(),
  489. (v) {
  490. final s = mockBudgetSubjects.firstWhere(
  491. (x) => x.name == v,
  492. );
  493. setState(() {
  494. _selectedSubjectId = s.id;
  495. _selectedSubjectName = s.name;
  496. _availableBudget = getMockBudget(
  497. _selectedProjectId!,
  498. s.id,
  499. );
  500. });
  501. },
  502. );
  503. }
  504. : null,
  505. ),
  506. const SizedBox(height: 16),
  507. _buildBudgetRow(l10n),
  508. const SizedBox(height: 16),
  509. FormFieldRow(
  510. label: l10n.get('relatedContractNo'),
  511. value: _referenceNoController.text,
  512. hint: l10n.get('optional'),
  513. onTap: () => _showTextInput(
  514. l10n.get('relatedContractNo'),
  515. (v) => setState(() {
  516. _referenceNoController.text = v;
  517. _referenceNoController.selection = TextSelection.fromPosition(
  518. TextPosition(offset: v.length),
  519. );
  520. }),
  521. initialText: _referenceNoController.text,
  522. ),
  523. ),
  524. ],
  525. );
  526. }
  527. Widget _buildBudgetRow(AppLocalizations l10n) {
  528. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  529. final over = _availableBudget <= 0;
  530. return Row(
  531. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  532. children: [
  533. Text(
  534. l10n.get('availableBudget'),
  535. style: TextStyle(
  536. fontSize: AppFontSizes.subtitle,
  537. color: colors.textSecondary,
  538. ),
  539. ),
  540. Text(
  541. '¥${_availableBudget.toStringAsFixed(2)}',
  542. style: TextStyle(
  543. fontSize: AppFontSizes.subtitle,
  544. fontWeight: FontWeight.w700,
  545. color: over ? colors.danger : colors.amountPrimary,
  546. ),
  547. ),
  548. ],
  549. );
  550. }
  551. // ═══ 4. 费用明细 ═══
  552. Widget _buildDetailsSection(AppLocalizations l10n) {
  553. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  554. return FormSection(
  555. title: l10n.get('expenseDetails'),
  556. leadingIcon: Icons.receipt_long_outlined,
  557. showAction: true,
  558. actionText: l10n.get('add'),
  559. onActionTap: _showDetailDialog,
  560. children: [
  561. Padding(
  562. padding: const EdgeInsets.only(bottom: 12),
  563. child: Row(
  564. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  565. children: [
  566. _label(l10n.get('isTaxIncluded')),
  567. TDSwitch(
  568. isOn: _isTaxIncluded,
  569. onChanged: (v) {
  570. setState(() => _isTaxIncluded = v);
  571. return true;
  572. },
  573. ),
  574. ],
  575. ),
  576. ),
  577. if (_details.isEmpty)
  578. Padding(
  579. padding: const EdgeInsets.symmetric(vertical: 8),
  580. child: Text(
  581. l10n.get('noDetailHint'),
  582. style: TextStyle(
  583. fontSize: AppFontSizes.subtitle,
  584. color: colors.textPlaceholder,
  585. ),
  586. ),
  587. )
  588. else
  589. ..._details.asMap().entries.map((e) {
  590. final d = e.value;
  591. return Container(
  592. margin: const EdgeInsets.symmetric(vertical: 8),
  593. padding: const EdgeInsets.all(12),
  594. decoration: BoxDecoration(
  595. color: colors.bgPage,
  596. borderRadius: BorderRadius.circular(8),
  597. ),
  598. child: Row(
  599. children: [
  600. Expanded(
  601. flex: 3,
  602. child: Column(
  603. crossAxisAlignment: CrossAxisAlignment.start,
  604. children: [
  605. Text(
  606. d.categoryName,
  607. style: TextStyle(
  608. fontSize: AppFontSizes.subtitle,
  609. color: colors.textPrimary,
  610. ),
  611. ),
  612. if (d.remark.isNotEmpty)
  613. Text(
  614. d.remark,
  615. maxLines: 2,
  616. overflow: TextOverflow.ellipsis,
  617. style: TextStyle(
  618. fontSize: AppFontSizes.caption,
  619. color: colors.textSecondary,
  620. ),
  621. ),
  622. ],
  623. ),
  624. ),
  625. Text(
  626. '${d.quantity}×¥${d.unitPrice.toStringAsFixed(2)}',
  627. style: TextStyle(
  628. fontSize: AppFontSizes.body,
  629. color: colors.textSecondary,
  630. ),
  631. ),
  632. const SizedBox(width: 8),
  633. Text(
  634. '¥${d.amount.toStringAsFixed(2)}',
  635. style: TextStyle(
  636. fontSize: AppFontSizes.subtitle,
  637. fontWeight: FontWeight.w600,
  638. color: colors.amountPrimary,
  639. ),
  640. ),
  641. const SizedBox(width: 8),
  642. GestureDetector(
  643. onTap: () => setState(() => _details.removeAt(e.key)),
  644. child: Container(
  645. width: 24,
  646. height: 24,
  647. decoration: BoxDecoration(
  648. color: colors.primaryLight,
  649. shape: BoxShape.circle,
  650. ),
  651. child: Icon(
  652. Icons.close,
  653. size: 14,
  654. color: colors.primary700,
  655. ),
  656. ),
  657. ),
  658. ],
  659. ),
  660. );
  661. }),
  662. const SizedBox(height: 8),
  663. Container(
  664. height: 36,
  665. padding: const EdgeInsets.symmetric(vertical: 8),
  666. child: Row(
  667. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  668. children: [
  669. Text(
  670. l10n.get('total'),
  671. style: TextStyle(
  672. fontSize: AppFontSizes.body,
  673. fontWeight: FontWeight.w600,
  674. color: colors.textPrimary,
  675. ),
  676. ),
  677. Text(
  678. '¥${_totalAmount().toStringAsFixed(2)}',
  679. style: TextStyle(
  680. fontSize: AppFontSizes.subtitle,
  681. fontWeight: FontWeight.w700,
  682. color: colors.amountPrimary,
  683. ),
  684. ),
  685. ],
  686. ),
  687. ),
  688. if (_totalAmount() > _availableBudget)
  689. Padding(
  690. padding: const EdgeInsets.only(top: 8),
  691. child: Row(
  692. children: [
  693. Icon(Icons.warning_amber, size: 14, color: colors.danger),
  694. const SizedBox(width: 6),
  695. Expanded(
  696. child: Text(
  697. l10n.get('overBudgetTriggerApproval'),
  698. style: TextStyle(
  699. fontSize: AppFontSizes.caption,
  700. color: colors.danger,
  701. ),
  702. ),
  703. ),
  704. ],
  705. ),
  706. ),
  707. ],
  708. );
  709. }
  710. double _totalAmount() => _details.fold(0, (s, d) => s + d.amount);
  711. List<CostCategory> get _availableDetailCategories {
  712. if (_expenseTypes.isEmpty) return mockCostCategories;
  713. final codes = _expenseTypes
  714. .expand((et) => expenseTypeCategories[et] ?? <String>[])
  715. .toSet();
  716. return mockCostCategories.where((c) => codes.contains(c.code)).toList();
  717. }
  718. void _showDetailDialog() {
  719. _unfocus();
  720. final l10n = AppLocalizations.of(context);
  721. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  722. final cats = _availableDetailCategories;
  723. String cat = cats.isNotEmpty ? cats.first.code : 'other';
  724. String unit = l10n.get('unitPiece');
  725. String catLabel = l10n.get(cats.firstWhere((c) => c.code == cat).nameKey);
  726. String unitLabel = l10n.get('unitPiece');
  727. final qtyCtrl = TextEditingController(text: '1');
  728. final priceCtrl = TextEditingController();
  729. final remarkCtrl = TextEditingController();
  730. showModalBottomSheet(
  731. context: context,
  732. isScrollControlled: true,
  733. backgroundColor: colors.bgCard,
  734. shape: const RoundedRectangleBorder(
  735. borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
  736. ),
  737. builder: (ctx) => StatefulBuilder(
  738. builder: (ctx, setDlg) => Padding(
  739. padding: EdgeInsets.only(
  740. left: 16,
  741. right: 16,
  742. top: 16,
  743. bottom: 16 + MediaQuery.of(ctx).viewInsets.bottom,
  744. ),
  745. child: Column(
  746. mainAxisSize: MainAxisSize.min,
  747. crossAxisAlignment: CrossAxisAlignment.stretch,
  748. children: [
  749. Center(
  750. child: Text(
  751. l10n.get('addExpenseDetail'),
  752. style: TextStyle(
  753. fontSize: 18,
  754. fontWeight: FontWeight.w600,
  755. color: colors.textPrimary,
  756. ),
  757. ),
  758. ),
  759. const SizedBox(height: 16),
  760. // 费用类别 — 左右布局,必填
  761. Row(
  762. crossAxisAlignment: CrossAxisAlignment.center,
  763. children: [
  764. SizedBox(
  765. width: 80,
  766. child: _label(l10n.get('expenseCategory'), required: true),
  767. ),
  768. const SizedBox(width: 8),
  769. Expanded(
  770. child: Container(
  771. clipBehavior: Clip.antiAlias,
  772. padding: const EdgeInsets.symmetric(horizontal: 12),
  773. decoration: BoxDecoration(
  774. borderRadius: BorderRadius.circular(8),
  775. border: Border.all(color: colors.border, width: 1),
  776. ),
  777. child: TDDropdownMenu(
  778. items: [
  779. TDDropdownItem(
  780. label: catLabel,
  781. options: cats
  782. .map(
  783. (c) => TDDropdownItemOption(
  784. value: c.code,
  785. label: l10n.get(c.nameKey),
  786. ),
  787. )
  788. .toList(),
  789. ),
  790. ],
  791. closeOnClickOverlay: true,
  792. onMenuClosed: (index) {
  793. if (index >= 0 && index < cats.length) {
  794. cat = cats[index].code;
  795. setDlg(() {});
  796. }
  797. },
  798. ),
  799. ),
  800. ),
  801. ],
  802. ),
  803. const SizedBox(height: 12),
  804. // 数量 — 左右布局,必填
  805. Row(
  806. crossAxisAlignment: CrossAxisAlignment.center,
  807. children: [
  808. SizedBox(
  809. width: 80,
  810. child: _label(l10n.get('quantity'), required: true),
  811. ),
  812. const SizedBox(width: 8),
  813. Expanded(
  814. child: Container(
  815. clipBehavior: Clip.antiAlias,
  816. padding: const EdgeInsets.symmetric(horizontal: 12),
  817. decoration: BoxDecoration(
  818. borderRadius: BorderRadius.circular(8),
  819. border: Border.all(color: colors.border, width: 1),
  820. ),
  821. child: TDInput(
  822. controller: qtyCtrl,
  823. hintText: '>0',
  824. contentAlignment: TextAlign.center,
  825. ),
  826. ),
  827. ),
  828. ],
  829. ),
  830. const SizedBox(height: 12),
  831. // 单位 — 左右布局
  832. Row(
  833. crossAxisAlignment: CrossAxisAlignment.center,
  834. children: [
  835. SizedBox(width: 80, child: _label(l10n.get('unit'))),
  836. const SizedBox(width: 8),
  837. Expanded(
  838. child: Container(
  839. clipBehavior: Clip.antiAlias,
  840. padding: const EdgeInsets.symmetric(horizontal: 12),
  841. decoration: BoxDecoration(
  842. borderRadius: BorderRadius.circular(8),
  843. border: Border.all(color: colors.border, width: 1),
  844. ),
  845. child: TDDropdownMenu(
  846. items: [
  847. TDDropdownItem(
  848. label: unitLabel,
  849. options: unitOptions
  850. .map(
  851. (u) => TDDropdownItemOption(
  852. value: u,
  853. label: l10n.get(u),
  854. ),
  855. )
  856. .toList(),
  857. ),
  858. ],
  859. closeOnClickOverlay: true,
  860. onMenuClosed: (index) {
  861. if (index >= 0 && index < unitOptions.length) {
  862. unit = l10n.get(unitOptions[index]);
  863. setDlg(() {});
  864. }
  865. },
  866. ),
  867. ),
  868. ),
  869. ],
  870. ),
  871. const SizedBox(height: 12),
  872. // 单价 — 左右布局,必填
  873. Row(
  874. crossAxisAlignment: CrossAxisAlignment.center,
  875. children: [
  876. SizedBox(
  877. width: 80,
  878. child: _label(l10n.get('unitPrice'), required: true),
  879. ),
  880. const SizedBox(width: 8),
  881. Expanded(
  882. child: Container(
  883. clipBehavior: Clip.antiAlias,
  884. padding: const EdgeInsets.symmetric(horizontal: 12),
  885. decoration: BoxDecoration(
  886. borderRadius: BorderRadius.circular(8),
  887. border: Border.all(color: colors.border, width: 1),
  888. ),
  889. child: TDInput(
  890. controller: priceCtrl,
  891. hintText: '>0',
  892. contentAlignment: TextAlign.center,
  893. ),
  894. ),
  895. ),
  896. ],
  897. ),
  898. const SizedBox(height: 12),
  899. _label(l10n.get('detailRemark')),
  900. const SizedBox(height: 8),
  901. TDTextarea(
  902. controller: remarkCtrl,
  903. hintText: l10n.get('optional'),
  904. maxLines: 3,
  905. minLines: 1,
  906. maxLength: 200,
  907. indicator: true,
  908. padding: EdgeInsets.zero,
  909. bordered: true,
  910. backgroundColor: colors.bgPage,
  911. ),
  912. const SizedBox(height: 16),
  913. Row(
  914. children: [
  915. Expanded(
  916. child: TDButton(
  917. text: l10n.get('cancel'),
  918. size: TDButtonSize.large,
  919. type: TDButtonType.outline,
  920. shape: TDButtonShape.rectangle,
  921. theme: TDButtonTheme.defaultTheme,
  922. onTap: () => Navigator.pop(ctx),
  923. ),
  924. ),
  925. const SizedBox(width: 12),
  926. Expanded(
  927. child: TDButton(
  928. text: l10n.get('confirm'),
  929. size: TDButtonSize.large,
  930. type: TDButtonType.fill,
  931. shape: TDButtonShape.rectangle,
  932. theme: TDButtonTheme.primary,
  933. onTap: () {
  934. final q = int.tryParse(qtyCtrl.text) ?? 0;
  935. final p = double.tryParse(priceCtrl.text) ?? 0;
  936. if (q <= 0 || p <= 0) {
  937. TDToast.showText(
  938. l10n.get('quantityPricePositive'),
  939. context: context,
  940. );
  941. return;
  942. }
  943. setState(
  944. () => _details.add(
  945. _DetailItem(
  946. id: _detailIdCounter++,
  947. category: cat,
  948. categoryName: l10n.get(
  949. cats.firstWhere((c) => c.code == cat).nameKey,
  950. ),
  951. quantity: q,
  952. unit: unit,
  953. unitPrice: p,
  954. amount: q * p.toDouble(),
  955. remark: remarkCtrl.text,
  956. ),
  957. ),
  958. );
  959. Navigator.pop(ctx);
  960. },
  961. ),
  962. ),
  963. ],
  964. ),
  965. ],
  966. ),
  967. ),
  968. ),
  969. );
  970. }
  971. // ═══ 5. 附件上传 ═══
  972. Widget _buildAttachmentSection(AppLocalizations l10n) {
  973. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  974. return FormSection(
  975. title: l10n.get('attachmentUpload'),
  976. leadingIcon: Icons.attach_file_outlined,
  977. children: [
  978. Text(
  979. l10n.get('maxAttachment'),
  980. style: TextStyle(
  981. fontSize: AppFontSizes.caption,
  982. color: colors.textPlaceholder,
  983. ),
  984. ),
  985. const SizedBox(height: 8),
  986. Wrap(
  987. spacing: 8,
  988. runSpacing: 8,
  989. children: [
  990. ..._attachments.asMap().entries.map(
  991. (e) => Stack(
  992. clipBehavior: Clip.none,
  993. children: [
  994. Container(
  995. width: 80,
  996. height: 80,
  997. decoration: BoxDecoration(
  998. color: colors.primaryLight,
  999. borderRadius: BorderRadius.circular(4),
  1000. ),
  1001. child: Center(
  1002. child: Icon(Icons.image, color: colors.primary, size: 32),
  1003. ),
  1004. ),
  1005. Positioned(
  1006. right: -4,
  1007. top: -4,
  1008. child: GestureDetector(
  1009. onTap: () => setState(() => _attachments.removeAt(e.key)),
  1010. child: Container(
  1011. width: 20,
  1012. height: 20,
  1013. decoration: BoxDecoration(
  1014. color: colors.danger,
  1015. shape: BoxShape.circle,
  1016. ),
  1017. child: const Icon(
  1018. Icons.close,
  1019. size: 12,
  1020. color: Colors.white,
  1021. ),
  1022. ),
  1023. ),
  1024. ),
  1025. ],
  1026. ),
  1027. ),
  1028. if (_attachments.length < 9)
  1029. GestureDetector(
  1030. onTap: () {
  1031. // Mock: add attachment (支持图片/PDF/Word/Excel)
  1032. final exts = ['.jpg', '.png', '.pdf', '.docx', '.xlsx'];
  1033. setState(
  1034. () => _attachments.add(
  1035. '附件_${DateTime.now().millisecondsSinceEpoch}${exts[_attachments.length % exts.length]}',
  1036. ),
  1037. );
  1038. TDToast.showText(
  1039. l10n.get('mockAttachmentAdded'),
  1040. context: context,
  1041. );
  1042. },
  1043. child: Container(
  1044. width: 80,
  1045. height: 80,
  1046. decoration: BoxDecoration(
  1047. color: colors.bgPage,
  1048. borderRadius: BorderRadius.circular(4),
  1049. border: Border.all(color: colors.border, width: 1),
  1050. ),
  1051. child: Center(
  1052. child: Icon(
  1053. Icons.add,
  1054. size: 24,
  1055. color: colors.textPlaceholder,
  1056. ),
  1057. ),
  1058. ),
  1059. ),
  1060. ],
  1061. ),
  1062. ],
  1063. );
  1064. }
  1065. // ═══ 6. 底部操作栏 ═══
  1066. Widget _buildBottomBar(AppLocalizations l10n) {
  1067. final isDraft = widget.id != null;
  1068. return ActionBar(
  1069. leftLabel: isDraft ? l10n.get('reset') : null,
  1070. centerLabel: l10n.get('saveDraft'),
  1071. rightLabel: l10n.get('submitApproval'),
  1072. showLeft: isDraft,
  1073. onLeftTap: isDraft
  1074. ? () => _showConfirmDialog(
  1075. l10n.get('confirmReset'),
  1076. l10n.get('resetWarning'),
  1077. l10n.get('cancel'),
  1078. l10n.get('confirmReset'),
  1079. _resetAll,
  1080. )
  1081. : null,
  1082. onCenterTap: () {
  1083. TDToast.showSuccess(l10n.get('draftSavedToast'), context: context);
  1084. context.pop();
  1085. },
  1086. onRightTap: () {
  1087. final err = _validate(l10n);
  1088. if (err.isNotEmpty) {
  1089. TDToast.showText(err.first, context: context);
  1090. return;
  1091. }
  1092. TDToast.showSuccess(
  1093. l10n.get('submittedAwaitingApproval'),
  1094. context: context,
  1095. );
  1096. context.pop();
  1097. },
  1098. );
  1099. }
  1100. List<String> _validate(AppLocalizations l10n) {
  1101. final e = <String>[];
  1102. if (_expenseTypes.isEmpty) e.add(l10n.get('selectAtLeastOneExpenseType'));
  1103. if (_purposeController.text.trim().isEmpty) {
  1104. e.add(l10n.get('enterFeeReason'));
  1105. }
  1106. if (_selectedProjectId == null) e.add(l10n.get('selectProject'));
  1107. if (_selectedSubjectId == null) e.add(l10n.get('selectSubject'));
  1108. if (_details.isEmpty) e.add(l10n.get('addAtLeastOneDetail'));
  1109. if (_expenseTypes.contains('travel')) {
  1110. if (_estimatedStartDate.isEmpty) {
  1111. e.add(l10n.get('selectEstimatedStartDate'));
  1112. }
  1113. if (_estimatedEndDate.isEmpty) e.add(l10n.get('selectEstimatedEndDate'));
  1114. }
  1115. if (_expenseTypes.contains('entertainment')) {
  1116. if (_entertainmentTarget == null || _entertainmentTarget!.isEmpty) {
  1117. e.add(l10n.get('entertainmentTargetUnit'));
  1118. }
  1119. if (_companionCount > _guestCount) {
  1120. e.add(l10n.get('companionNotExceedGuest'));
  1121. }
  1122. }
  1123. if (_expenseTypes.contains('meeting')) {
  1124. if (_meetingStartDate.isEmpty) {
  1125. e.add(l10n.get('selectEstimatedStartDate'));
  1126. }
  1127. if (_meetingEndDate.isEmpty) e.add(l10n.get('selectEstimatedEndDate'));
  1128. }
  1129. return e;
  1130. }
  1131. void _resetAll() => setState(() {
  1132. _purposeController.clear();
  1133. _expenseTypes.clear();
  1134. _urgency = Urgency.normal.value;
  1135. _isTaxIncluded = false;
  1136. _validUntil = '';
  1137. _selectedProjectId = null;
  1138. _selectedProjectName = null;
  1139. _selectedSubjectId = null;
  1140. _selectedSubjectName = null;
  1141. _availableBudget = 0;
  1142. _referenceNoController.clear();
  1143. _details.clear();
  1144. _attachments.clear();
  1145. _estimatedStartDate = '';
  1146. _estimatedEndDate = '';
  1147. _isOvernight = false;
  1148. _transportType = null;
  1149. _entertainmentTarget = null;
  1150. _entertainmentLevel = null;
  1151. _guestCount = 1;
  1152. _companionCount = 0;
  1153. _entertainmentVenue = '';
  1154. _meetingStartDate = '';
  1155. _meetingEndDate = '';
  1156. _meetingVenue = '';
  1157. });
  1158. bool _hasUnsaved() =>
  1159. _purposeController.text.isNotEmpty ||
  1160. _expenseTypes.isNotEmpty ||
  1161. _details.isNotEmpty ||
  1162. _attachments.isNotEmpty ||
  1163. _selectedProjectId != null ||
  1164. _estimatedStartDate.isNotEmpty ||
  1165. _estimatedEndDate.isNotEmpty ||
  1166. _entertainmentTarget != null ||
  1167. _meetingStartDate.isNotEmpty;
  1168. void _unfocus() => FocusScope.of(context).unfocus();
  1169. // ═══ 通用弹窗方法 ═══
  1170. void _showConfirmDialog(
  1171. String title,
  1172. String content,
  1173. String leftText,
  1174. String rightText,
  1175. VoidCallback onConfirm,
  1176. ) {
  1177. _unfocus();
  1178. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1179. showDialog(
  1180. context: context,
  1181. builder: (ctx) => TDAlertDialog(
  1182. title: title,
  1183. content: content,
  1184. leftBtn: TDDialogButtonOptions(
  1185. title: leftText,
  1186. titleColor: colors.primary,
  1187. action: () => Navigator.pop(ctx),
  1188. ),
  1189. rightBtn: TDDialogButtonOptions(
  1190. title: rightText,
  1191. titleColor: colors.danger,
  1192. action: () {
  1193. Navigator.pop(ctx);
  1194. onConfirm();
  1195. },
  1196. ),
  1197. ),
  1198. );
  1199. }
  1200. void _showEnumPicker(
  1201. String title,
  1202. List<EnumEntry> entries,
  1203. Function(String) onPick,
  1204. ) {
  1205. _showListPicker(
  1206. title,
  1207. entries.map((e) => AppLocalizations.of(context).get(e.labelKey)).toList(),
  1208. (label) {
  1209. final entry = entries.firstWhere(
  1210. (e) => AppLocalizations.of(context).get(e.labelKey) == label,
  1211. );
  1212. onPick(entry.value);
  1213. },
  1214. );
  1215. }
  1216. void _showListPicker(
  1217. String title,
  1218. List<String> items,
  1219. Function(String) onPick,
  1220. ) {
  1221. _unfocus();
  1222. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1223. TDPicker.showMultiPicker(
  1224. context,
  1225. title: title,
  1226. backgroundColor: colors.bgCard,
  1227. data: [items],
  1228. onConfirm: (selected) {
  1229. if (selected.isNotEmpty && selected[0] is int) {
  1230. final idx = selected[0] as int;
  1231. if (idx >= 0 && idx < items.length) {
  1232. Navigator.of(context).pop();
  1233. onPick(items[idx]);
  1234. }
  1235. }
  1236. },
  1237. );
  1238. }
  1239. void _showTextInput(
  1240. String title,
  1241. Function(String) onConfirm, {
  1242. String initialText = '',
  1243. }) {
  1244. _unfocus();
  1245. final l10n = AppLocalizations.of(context);
  1246. final c = TextEditingController(text: initialText);
  1247. showGeneralDialog(
  1248. context: context,
  1249. pageBuilder: (ctx, animation, secondaryAnimation) => TDInputDialog(
  1250. textEditingController: c,
  1251. title: title,
  1252. hintText: l10n.get('pleaseEnter'),
  1253. leftBtn: TDDialogButtonOptions(
  1254. title: l10n.get('cancel'),
  1255. action: () => Navigator.pop(ctx),
  1256. ),
  1257. rightBtn: TDDialogButtonOptions(
  1258. title: l10n.get('confirm'),
  1259. action: () {
  1260. onConfirm(c.text);
  1261. Navigator.pop(ctx);
  1262. },
  1263. ),
  1264. ),
  1265. );
  1266. }
  1267. void _showNumberInput(
  1268. String title,
  1269. Function(int) onConfirm, {
  1270. int initialValue = 0,
  1271. }) {
  1272. _unfocus();
  1273. final l10n = AppLocalizations.of(context);
  1274. final c = TextEditingController(
  1275. text: initialValue > 0 ? '$initialValue' : '',
  1276. );
  1277. showGeneralDialog(
  1278. context: context,
  1279. pageBuilder: (ctx, animation, secondaryAnimation) => TDInputDialog(
  1280. textEditingController: c,
  1281. title: title,
  1282. hintText: l10n.get('enterNumber'),
  1283. leftBtn: TDDialogButtonOptions(
  1284. title: l10n.get('cancel'),
  1285. action: () => Navigator.pop(ctx),
  1286. ),
  1287. rightBtn: TDDialogButtonOptions(
  1288. title: l10n.get('confirm'),
  1289. action: () {
  1290. onConfirm(int.tryParse(c.text) ?? 0);
  1291. Navigator.pop(ctx);
  1292. },
  1293. ),
  1294. ),
  1295. );
  1296. }
  1297. void _pickDate(Function(String) onPick) {
  1298. _unfocus();
  1299. final l10n = AppLocalizations.of(context);
  1300. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1301. final theme = Theme.of(context);
  1302. final now = DateTime.now();
  1303. showModalBottomSheet(
  1304. context: context,
  1305. backgroundColor: Colors.transparent,
  1306. builder: (ctx) => Theme(
  1307. data: theme,
  1308. child: TDDatePicker(
  1309. title: l10n.get('selectDate'),
  1310. backgroundColor: colors.bgCard,
  1311. model: DatePickerModel(
  1312. useYear: true,
  1313. useMonth: true,
  1314. useDay: true,
  1315. useHour: false,
  1316. useMinute: false,
  1317. useSecond: false,
  1318. useWeekDay: false,
  1319. dateStart: [2020, 1, 1],
  1320. dateEnd: [now.year + 1, 12, 31],
  1321. dateInitial: [now.year, now.month, now.day],
  1322. ),
  1323. onConfirm: (selected) {
  1324. onPick(
  1325. '${selected['year']}-${selected['month']!.toString().padLeft(2, '0')}-${selected['day']!.toString().padLeft(2, '0')}',
  1326. );
  1327. Navigator.of(ctx).pop();
  1328. },
  1329. onCancel: (_) => Navigator.of(ctx).pop(),
  1330. ),
  1331. ),
  1332. );
  1333. }
  1334. Widget _label(String t, {bool required = false}) {
  1335. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  1336. return Text.rich(
  1337. TextSpan(
  1338. children: [
  1339. TextSpan(
  1340. text: t,
  1341. style: TextStyle(
  1342. fontSize: AppFontSizes.subtitle,
  1343. color: colors.textSecondary,
  1344. ),
  1345. ),
  1346. if (required)
  1347. TextSpan(
  1348. text: ' *',
  1349. style: TextStyle(
  1350. fontSize: AppFontSizes.subtitle,
  1351. color: colors.danger,
  1352. ),
  1353. ),
  1354. ],
  1355. ),
  1356. );
  1357. }
  1358. String _today() {
  1359. final n = DateTime.now();
  1360. return '${n.year}-${n.month.toString().padLeft(2, '0')}-${n.day.toString().padLeft(2, '0')}';
  1361. }
  1362. }
  1363. class _DetailItem {
  1364. final int id;
  1365. final String category;
  1366. final String categoryName;
  1367. final int quantity;
  1368. final String unit;
  1369. final double unitPrice;
  1370. final double amount;
  1371. final String remark;
  1372. const _DetailItem({
  1373. required this.id,
  1374. required this.category,
  1375. required this.categoryName,
  1376. required this.quantity,
  1377. required this.unit,
  1378. required this.unitPrice,
  1379. required this.amount,
  1380. required this.remark,
  1381. });
  1382. }