expense_detail_dialog.dart 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:tdesign_flutter/tdesign_flutter.dart';
  4. import '../../../core/i18n/app_localizations.dart';
  5. import '../../../core/theme/app_colors.dart';
  6. import '../../../core/theme/app_colors_extension.dart';
  7. import '../../../core/data/mock_api_data.dart';
  8. import '../expense_api.dart';
  9. import '../../../shared/widgets/attachment_picker.dart';
  10. /// 报销明细输入数据。
  11. class ExpenseDetailInputData {
  12. final String category;
  13. final String categoryName;
  14. final String acctSubjectId;
  15. final String acctSubjectName;
  16. final String purpose;
  17. final double amount; // 含税金额
  18. final double taxRate;
  19. final String projectId;
  20. final String projectName;
  21. final String costDeptId;
  22. final String costDeptName;
  23. final String customerVendorId;
  24. final String customerVendorName;
  25. final double approvedAmount;
  26. final double offsetAmount;
  27. final String bankName;
  28. final String bankAccountName;
  29. final String bankAccount;
  30. final String remark;
  31. final List<String> attachmentPaths;
  32. final String sqMan;
  33. final String sqManName;
  34. final String aeNo;
  35. final String aeDd;
  36. const ExpenseDetailInputData({
  37. required this.category,
  38. required this.categoryName,
  39. required this.acctSubjectId,
  40. required this.acctSubjectName,
  41. required this.purpose,
  42. required this.amount,
  43. required this.taxRate,
  44. this.projectId = '',
  45. this.projectName = '',
  46. this.costDeptId = '',
  47. this.costDeptName = '',
  48. this.customerVendorId = '',
  49. this.customerVendorName = '',
  50. this.approvedAmount = 0.0,
  51. this.offsetAmount = 0.0,
  52. this.bankName = '',
  53. this.bankAccountName = '',
  54. this.bankAccount = '',
  55. this.remark = '',
  56. this.attachmentPaths = const [],
  57. this.sqMan = '',
  58. this.sqManName = '',
  59. this.aeNo = '',
  60. this.aeDd = '',
  61. });
  62. }
  63. /// 报销明细编辑弹窗。
  64. ///
  65. /// 使用 [TDSlidePopupRoute] 从底部滑出,卡片化展示表单字段。
  66. /// 参照 ExpenseApplyCreatePage 的 ExpenseDetailDialog 样式。
  67. class ExpenseDetailDialog extends StatefulWidget {
  68. final List<CostCategory> categories;
  69. final List<Project> projects;
  70. final List<CostDept> costDepts;
  71. final List<CustomerVendor> customers;
  72. final List<EmployeeItem> employees;
  73. final AppLocalizations l10n;
  74. final ExpenseDetailInputData? initialData;
  75. const ExpenseDetailDialog({
  76. super.key,
  77. required this.categories,
  78. required this.projects,
  79. required this.costDepts,
  80. required this.customers,
  81. required this.employees,
  82. required this.l10n,
  83. this.initialData,
  84. });
  85. /// 显示弹窗,返回 [ExpenseDetailInputData] 或 `null`(取消时)。
  86. static Future<ExpenseDetailInputData?> show(
  87. BuildContext context, {
  88. required List<CostCategory> categories,
  89. required List<Project> projects,
  90. required List<CostDept> costDepts,
  91. required List<CustomerVendor> customers,
  92. required List<EmployeeItem> employees,
  93. required AppLocalizations l10n,
  94. ExpenseDetailInputData? initialData,
  95. }) {
  96. FocusScope.of(context).unfocus();
  97. return Navigator.push<ExpenseDetailInputData>(
  98. context,
  99. TDSlidePopupRoute<ExpenseDetailInputData>(
  100. slideTransitionFrom: SlideTransitionFrom.bottom,
  101. isDismissible: true,
  102. builder: (_) => ExpenseDetailDialog(
  103. categories: categories,
  104. projects: projects,
  105. costDepts: costDepts,
  106. customers: customers,
  107. employees: employees,
  108. l10n: l10n,
  109. initialData: initialData,
  110. ),
  111. ),
  112. );
  113. }
  114. @override
  115. State<ExpenseDetailDialog> createState() =>
  116. _ExpenseDetailDialogState();
  117. }
  118. class _ExpenseDetailDialogState extends State<ExpenseDetailDialog> {
  119. late String _cat;
  120. late TextEditingController _descCtrl;
  121. late TextEditingController _amountCtrl;
  122. CustomerVendor? _selCustomer;
  123. late TextEditingController _approvedAmountCtrl;
  124. late TextEditingController _offsetCtrl;
  125. late TextEditingController _remarkCtrl;
  126. late TextEditingController _bankNameCtrl;
  127. late TextEditingController _bankAccountNameCtrl;
  128. late TextEditingController _bankAccountCtrl;
  129. double _taxRate = 0;
  130. Project? _selProject;
  131. CostDept? _selDept;
  132. EmployeeItem? _selEmployee;
  133. late final AttachmentPickerController _attachmentCtrl;
  134. final ScrollController _scrollCtrl = ScrollController();
  135. static const _taxOptions = [0.0, 0.06, 0.09, 0.13];
  136. static const _taxLabels = ['0%', '6%', '9%', '13%'];
  137. List<CostCategory> get _cats => widget.categories;
  138. AppLocalizations get _l10n => widget.l10n;
  139. CostCategory get _selCat => _cats.firstWhere((c) => c.code == _cat);
  140. bool get _isEdit => widget.initialData != null;
  141. @override
  142. void initState() {
  143. super.initState();
  144. final d = widget.initialData;
  145. _cat = d != null
  146. ? (_cats.any((c) => c.code == d.category) ? d.category : _cats.first.code)
  147. : _cats.isNotEmpty ? _cats.first.code : 'other';
  148. _descCtrl = TextEditingController(text: d?.purpose ?? '');
  149. _amountCtrl = TextEditingController(text: d != null && d.amount > 0 ? d.amount.toStringAsFixed(2) : '');
  150. if (d != null && d.customerVendorName.isNotEmpty) {
  151. _selCustomer = CustomerVendor(id: '', name: d.customerVendorName);
  152. }
  153. _approvedAmountCtrl = TextEditingController(text: d != null && d.approvedAmount > 0 ? d.approvedAmount.toStringAsFixed(2) : '');
  154. _offsetCtrl = TextEditingController(text: d != null && d.offsetAmount > 0 ? d.offsetAmount.toStringAsFixed(2) : '');
  155. _remarkCtrl = TextEditingController(text: d?.remark ?? '');
  156. _bankNameCtrl = TextEditingController(text: d?.bankName ?? '');
  157. _bankAccountNameCtrl = TextEditingController(text: d?.bankAccountName ?? '');
  158. _bankAccountCtrl = TextEditingController(text: d?.bankAccount ?? '');
  159. _taxRate = d?.taxRate ?? 0;
  160. if (d != null && d.sqMan.isNotEmpty && widget.employees.isNotEmpty) {
  161. final idx = widget.employees.indexWhere((e) => e.salNo == d.sqMan);
  162. if (idx >= 0) _selEmployee = widget.employees[idx];
  163. }
  164. if (d != null) {
  165. if (d.projectId.isNotEmpty && widget.projects.isNotEmpty) {
  166. _selProject = widget.projects.firstWhere((p) => p.id.toString() == d.projectId, orElse: () => widget.projects.first);
  167. }
  168. if (d.costDeptId.isNotEmpty && widget.costDepts.isNotEmpty) {
  169. _selDept = widget.costDepts.firstWhere((dept) => dept.id == d.costDeptId, orElse: () => widget.costDepts.first);
  170. }
  171. if (d.attachmentPaths.isNotEmpty) {
  172. // Restore attachments will be handled after build
  173. WidgetsBinding.instance.addPostFrameCallback((_) {
  174. _attachmentCtrl.restoreFromPaths(d.attachmentPaths);
  175. });
  176. }
  177. }
  178. _attachmentCtrl = AttachmentPickerController(maxCount: 9)
  179. ..addListener(() => setState(() {}));
  180. }
  181. @override
  182. void dispose() {
  183. _descCtrl.dispose();
  184. _amountCtrl.dispose();
  185. _approvedAmountCtrl.dispose();
  186. _offsetCtrl.dispose();
  187. _remarkCtrl.dispose();
  188. _bankNameCtrl.dispose();
  189. _bankAccountNameCtrl.dispose();
  190. _bankAccountCtrl.dispose();
  191. _attachmentCtrl.dispose();
  192. _scrollCtrl.dispose();
  193. super.dispose();
  194. }
  195. void _confirm() {
  196. final amount = double.tryParse(_amountCtrl.text) ?? 0;
  197. if (amount <= 0) {
  198. TDToast.showText(_l10n.get('amountPositive'), context: context);
  199. return;
  200. }
  201. Navigator.pop(
  202. context,
  203. ExpenseDetailInputData(
  204. category: _cat,
  205. categoryName: _l10n.get(_selCat.nameKey),
  206. acctSubjectId: _selCat.acctSubjectId,
  207. acctSubjectName: _selCat.acctSubjectName,
  208. purpose: '',
  209. amount: amount,
  210. taxRate: _taxRate,
  211. projectId: _selProject?.id.toString() ?? '',
  212. projectName: _selProject?.name ?? '',
  213. costDeptId: _selDept?.id ?? '',
  214. costDeptName: _selDept?.name ?? '',
  215. customerVendorId: _selCustomer?.id ?? '',
  216. customerVendorName: _selCustomer?.name ?? '',
  217. approvedAmount: double.tryParse(_approvedAmountCtrl.text) ?? 0,
  218. offsetAmount: double.tryParse(_offsetCtrl.text) ?? 0,
  219. bankName: _bankNameCtrl.text.trim(),
  220. bankAccountName: _bankAccountNameCtrl.text.trim(),
  221. bankAccount: _bankAccountCtrl.text.trim(),
  222. remark: _remarkCtrl.text.trim(),
  223. attachmentPaths: _attachmentCtrl.toPathList(),
  224. sqMan: _selEmployee?.salNo ?? '',
  225. sqManName: _selEmployee?.name ?? '',
  226. aeNo: widget.initialData?.aeNo ?? '',
  227. aeDd: widget.initialData?.aeDd ?? '',
  228. ),
  229. );
  230. }
  231. double get _amountExclTax => _taxRate > 0
  232. ? (double.tryParse(_amountCtrl.text) ?? 0) / (1 + _taxRate)
  233. : (double.tryParse(_amountCtrl.text) ?? 0);
  234. double get _taxAmount =>
  235. (double.tryParse(_amountCtrl.text) ?? 0) - _amountExclTax;
  236. @override
  237. Widget build(BuildContext context) {
  238. final colors = Theme.of(context).extension<AppColorsExtension>()!;
  239. return SafeArea(
  240. child: ConstrainedBox(
  241. constraints: BoxConstraints(
  242. maxHeight: MediaQuery.of(context).size.height * 0.8,
  243. ),
  244. child: Container(
  245. decoration: BoxDecoration(
  246. color: colors.bgPage,
  247. borderRadius:
  248. const BorderRadius.vertical(top: Radius.circular(16)),
  249. ),
  250. child: Column(
  251. mainAxisSize: MainAxisSize.min,
  252. crossAxisAlignment: CrossAxisAlignment.stretch,
  253. children: [
  254. _buildHeader(colors),
  255. Flexible(
  256. child: GestureDetector(
  257. onTap: () => FocusScope.of(context).unfocus(),
  258. behavior: HitTestBehavior.translucent,
  259. child: SingleChildScrollView(
  260. controller: _scrollCtrl,
  261. keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
  262. padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
  263. child: Column(
  264. mainAxisSize: MainAxisSize.min,
  265. crossAxisAlignment: CrossAxisAlignment.stretch,
  266. children: [
  267. if (_isEdit && widget.initialData!.aeNo.isNotEmpty) ...[
  268. _buildAeInfoCard(colors),
  269. const SizedBox(height: 12),
  270. ],
  271. _buildCategoryCard(colors),
  272. const SizedBox(height: 12),
  273. _buildAcctSubjectCard(colors),
  274. const SizedBox(height: 12),
  275. _buildAmountCard(),
  276. const SizedBox(height: 12),
  277. _buildTaxRateCard(colors),
  278. if ((double.tryParse(_amountCtrl.text) ?? 0) > 0) ...[
  279. const SizedBox(height: 12),
  280. _buildCalcInfo(colors),
  281. ],
  282. const SizedBox(height: 12),
  283. _buildApprovedAmountCard(),
  284. const SizedBox(height: 12),
  285. _buildProjectCard(colors),
  286. const SizedBox(height: 12),
  287. _buildCostDeptCard(colors),
  288. const SizedBox(height: 12),
  289. _buildCustomerCard(colors),
  290. const SizedBox(height: 12),
  291. _buildEmployeeCard(colors),
  292. const SizedBox(height: 12),
  293. _buildBankInfoCard(colors),
  294. const SizedBox(height: 12),
  295. _buildOffsetCard(),
  296. const SizedBox(height: 12),
  297. _buildRemarkInput(colors),
  298. const SizedBox(height: 12),
  299. _buildAttachmentCard(colors),
  300. ],
  301. ),
  302. ),
  303. ),
  304. ),
  305. Container(
  306. padding: const EdgeInsets.fromLTRB(16, 12, 16, 16),
  307. decoration: BoxDecoration(
  308. color: colors.bgCard,
  309. border: Border(
  310. top: BorderSide(color: colors.border, width: 0.5),
  311. ),
  312. ),
  313. child: _buildActions(),
  314. ),
  315. ],
  316. ),
  317. ),
  318. ),
  319. );
  320. }
  321. // ── 标题栏 ──
  322. Widget _buildHeader(AppColorsExtension colors) {
  323. return Column(
  324. mainAxisSize: MainAxisSize.min,
  325. children: [
  326. Center(
  327. child: Container(
  328. margin: const EdgeInsets.only(top: 8, bottom: 4),
  329. width: 36,
  330. height: 4,
  331. decoration: BoxDecoration(
  332. color: colors.border,
  333. borderRadius: BorderRadius.circular(2),
  334. ),
  335. ),
  336. ),
  337. Padding(
  338. padding: const EdgeInsets.fromLTRB(20, 8, 12, 16),
  339. child: Row(
  340. children: [
  341. const SizedBox(width: 28),
  342. Expanded(
  343. child: Center(
  344. child: Text(
  345. _l10n.get('addExpenseDetail'),
  346. style: TextStyle(
  347. fontSize: AppFontSizes.title,
  348. fontWeight: FontWeight.w600,
  349. color: colors.textPrimary,
  350. ),
  351. ),
  352. ),
  353. ),
  354. GestureDetector(
  355. onTap: () => Navigator.pop(context),
  356. child: Padding(
  357. padding: const EdgeInsets.all(4),
  358. child: Icon(
  359. Icons.close,
  360. size: 20,
  361. color: colors.textSecondary,
  362. ),
  363. ),
  364. ),
  365. ],
  366. ),
  367. ),
  368. ],
  369. );
  370. }
  371. // ── picker 卡片 ──
  372. Widget _pickerCard({
  373. required String label,
  374. required bool required,
  375. required String currentLabel,
  376. required List<String> labels,
  377. required ValueChanged<int> onSelected,
  378. required AppColorsExtension colors,
  379. VoidCallback? onClear,
  380. }) {
  381. final tdTheme = TDTheme.of(context);
  382. final hasValue = onClear != null;
  383. return GestureDetector(
  384. onTap: () {
  385. if (labels.isEmpty) {
  386. TDToast.showText(_l10n.get('noData'), context: context);
  387. return;
  388. }
  389. TDPicker.showMultiPicker(
  390. context,
  391. title: label,
  392. backgroundColor: colors.bgCard,
  393. data: [labels],
  394. onConfirm: (selected) {
  395. if (selected.isNotEmpty && selected[0] is int) {
  396. final idx = selected[0] as int;
  397. if (idx >= 0 && idx < labels.length) {
  398. Navigator.of(context).pop();
  399. onSelected(idx);
  400. }
  401. }
  402. },
  403. );
  404. },
  405. child: Container(
  406. padding: const EdgeInsets.only(left: 16, right: 10, top: 12, bottom: 12),
  407. decoration: BoxDecoration(
  408. color: tdTheme.bgColorContainer,
  409. borderRadius: BorderRadius.circular(tdTheme.radiusDefault),
  410. border: Border.all(color: tdTheme.componentStrokeColor),
  411. ),
  412. child: Row(
  413. children: [
  414. TDText(label, maxLines: 1, overflow: TextOverflow.visible, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, style: const TextStyle(letterSpacing: 0)),
  415. if (required)
  416. Padding(padding: const EdgeInsets.only(left: 4), child: TDText('*', font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, style: TextStyle(color: tdTheme.errorColor6))),
  417. const SizedBox(width: 12),
  418. Expanded(
  419. child: Row(mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [
  420. Flexible(child: TDText(currentLabel, maxLines: 1, overflow: TextOverflow.ellipsis, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, textColor: tdTheme.textColorPrimary, textAlign: TextAlign.end)),
  421. const SizedBox(width: 4),
  422. SizedBox(
  423. width: 18, height: 18,
  424. child: hasValue
  425. ? GestureDetector(onTap: onClear, child: Icon(Icons.close, size: 18, color: tdTheme.textColorPlaceholder))
  426. : Icon(Icons.chevron_right, size: 18, color: tdTheme.textColorPlaceholder),
  427. ),
  428. ]),
  429. ),
  430. ],
  431. ),
  432. ),
  433. );
  434. }
  435. // ── 费用类别 ──
  436. Widget _buildCategoryCard(AppColorsExtension colors) {
  437. return _pickerCard(
  438. label: _l10n.get('expenseCategory'),
  439. required: true,
  440. currentLabel: '${_selCat.code}/${_l10n.get(_selCat.nameKey)}',
  441. labels: _cats.map((c) => '${c.code}/${_l10n.get(c.nameKey)}').toList(),
  442. colors: colors,
  443. onSelected: (idx) => setState(() => _cat = _cats[idx].code),
  444. );
  445. }
  446. // ── 输入卡片(对齐 pickerCard 样式) ──
  447. Widget _inputCard({
  448. required String label,
  449. required bool required,
  450. required TextEditingController controller,
  451. required String hintText,
  452. required AppColorsExtension colors,
  453. TextInputType? keyboardType,
  454. List<TextInputFormatter>? inputFormatters,
  455. }) {
  456. final tdTheme = TDTheme.of(context);
  457. final hasValue = controller.text.isNotEmpty;
  458. return Container(
  459. padding: const EdgeInsets.only(left: 16, right: 10, top: 12, bottom: 12),
  460. decoration: BoxDecoration(
  461. color: tdTheme.bgColorContainer,
  462. borderRadius: BorderRadius.circular(tdTheme.radiusDefault),
  463. border: Border.all(color: tdTheme.componentStrokeColor),
  464. ),
  465. child: Row(
  466. children: [
  467. TDText(label, maxLines: 1, overflow: TextOverflow.visible, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, style: const TextStyle(letterSpacing: 0)),
  468. if (required)
  469. Padding(padding: const EdgeInsets.only(left: 4), child: TDText('*', font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, style: TextStyle(color: tdTheme.errorColor6))),
  470. const SizedBox(width: 12),
  471. Expanded(
  472. child: Row(mainAxisAlignment: MainAxisAlignment.end, mainAxisSize: MainAxisSize.max, children: [
  473. Flexible(
  474. child: TextField(
  475. controller: controller,
  476. textAlign: TextAlign.end,
  477. keyboardType: keyboardType,
  478. inputFormatters: inputFormatters,
  479. style: TextStyle(fontSize: 16, color: colors.textPrimary),
  480. decoration: InputDecoration(
  481. hintText: hintText,
  482. hintStyle: TextStyle(fontSize: 16, color: colors.textPlaceholder),
  483. border: InputBorder.none,
  484. isDense: true,
  485. contentPadding: EdgeInsets.zero,
  486. ),
  487. onChanged: (_) => setState(() {}),
  488. ),
  489. ),
  490. const SizedBox(width: 4),
  491. SizedBox(
  492. width: 18, height: 18,
  493. child: hasValue
  494. ? GestureDetector(
  495. onTap: () { controller.clear(); setState(() {}); },
  496. child: Icon(Icons.close, size: 18, color: tdTheme.textColorPlaceholder),
  497. )
  498. : null,
  499. ),
  500. ]),
  501. ),
  502. ],
  503. ),
  504. );
  505. }
  506. // ── 含税金额 ──
  507. Widget _buildAmountCard() {
  508. return _inputCard(
  509. label: _l10n.get('amountInclTax'),
  510. required: true,
  511. controller: _amountCtrl,
  512. hintText: '>0',
  513. colors: Theme.of(context).extension<AppColorsExtension>()!,
  514. keyboardType: const TextInputType.numberWithOptions(decimal: true),
  515. inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}$'))],
  516. );
  517. }
  518. // ── 税率 ──
  519. Widget _buildTaxRateCard(AppColorsExtension colors) {
  520. final currentLabel =
  521. '${(_taxRate * 100).toStringAsFixed(0)}%';
  522. return _pickerCard(
  523. label: _l10n.get('taxRate'),
  524. required: true,
  525. currentLabel: currentLabel,
  526. labels: _taxLabels.toList(),
  527. colors: colors,
  528. onSelected: (idx) => setState(() {
  529. _taxRate = _taxOptions[idx];
  530. }),
  531. );
  532. }
  533. // ── 计算信息 ──
  534. Widget _buildCalcInfo(AppColorsExtension colors) {
  535. final amount = double.tryParse(_amountCtrl.text) ?? 0;
  536. if (amount <= 0) return const SizedBox.shrink();
  537. return Container(
  538. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
  539. decoration: BoxDecoration(
  540. color: colors.primaryLight,
  541. borderRadius: BorderRadius.circular(8),
  542. ),
  543. child: Row(
  544. children: [
  545. Expanded(
  546. child: Text(
  547. '${_l10n.get('amountExcludingTax')}: ¥${_amountExclTax.toStringAsFixed(2)}',
  548. style: TextStyle(
  549. fontSize: AppFontSizes.body,
  550. color: colors.textSecondary,
  551. ),
  552. ),
  553. ),
  554. Text(
  555. '${_l10n.get('taxAmount')}: ¥${_taxAmount.toStringAsFixed(2)}',
  556. style: TextStyle(
  557. fontSize: AppFontSizes.body,
  558. color: colors.textSecondary,
  559. ),
  560. ),
  561. ],
  562. ),
  563. );
  564. }
  565. // ── 导入单据信息 ──
  566. Widget _buildAeInfoCard(AppColorsExtension colors) {
  567. final d = widget.initialData!;
  568. final tdTheme = TDTheme.of(context);
  569. return Container(
  570. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
  571. decoration: _cardDecoration(tdTheme),
  572. child: Column(
  573. children: [
  574. _readOnlyRow(tdTheme, _l10n.get('expenseApplyNo'), d.aeNo),
  575. const SizedBox(height: 8),
  576. _readOnlyRow(tdTheme, _l10n.get('applyDate'), d.aeDd),
  577. ],
  578. ),
  579. );
  580. }
  581. Widget _readOnlyRow(TDThemeData tdTheme, String label, String value) {
  582. return Row(children: [
  583. TDText(label, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, style: const TextStyle(letterSpacing: 0)),
  584. const SizedBox(width: 12),
  585. Expanded(child: TDText(value, maxLines: 1, overflow: TextOverflow.ellipsis, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, textColor: tdTheme.textColorPrimary, textAlign: TextAlign.end)),
  586. ]);
  587. }
  588. BoxDecoration _cardDecoration(TDThemeData tdTheme) => BoxDecoration(
  589. color: tdTheme.bgColorContainer,
  590. borderRadius: BorderRadius.circular(tdTheme.radiusDefault),
  591. border: Border.all(color: tdTheme.componentStrokeColor),
  592. );
  593. // ── 申请人 ──
  594. Widget _buildEmployeeCard(AppColorsExtension colors) {
  595. final employees = widget.employees;
  596. return _pickerCard(
  597. label: _l10n.get('applicant'),
  598. required: false,
  599. currentLabel: _selEmployee != null ? '${_selEmployee!.salNo}/${_selEmployee!.name}' : _l10n.get('pleaseSelect'),
  600. labels: employees.map((e) => '${e.salNo}/${e.name}').toList(),
  601. colors: colors,
  602. onSelected: (idx) => setState(() {
  603. _selEmployee = employees[idx];
  604. _bankNameCtrl.text = _selEmployee!.bnkNo;
  605. _bankAccountNameCtrl.text = _selEmployee!.accName;
  606. _bankAccountCtrl.text = _selEmployee!.bnkId;
  607. }),
  608. onClear: _selEmployee != null ? () => setState(() {
  609. _selEmployee = null;
  610. _bankNameCtrl.clear();
  611. _bankAccountNameCtrl.clear();
  612. _bankAccountCtrl.clear();
  613. }) : null,
  614. );
  615. }
  616. // ── 客户/厂商 ──
  617. Widget _buildCustomerCard(AppColorsExtension colors) {
  618. final vendors = widget.customers;
  619. return _pickerCard(
  620. label: _l10n.get('customerVendor'),
  621. required: false,
  622. currentLabel: _selCustomer != null ? '${_selCustomer!.id}/${_selCustomer!.name}' : _l10n.get('pleaseSelect'),
  623. labels: vendors.map((v) => '${v.id}/${v.name}').toList(),
  624. colors: colors,
  625. onSelected: (idx) => setState(() => _selCustomer = vendors[idx]),
  626. onClear: _selCustomer != null ? () => setState(() => _selCustomer = null) : null,
  627. );
  628. }
  629. // ── 已充金额 ──
  630. Widget _buildApprovedAmountCard() {
  631. return _inputCard(
  632. label: _l10n.get('approvedAmount'),
  633. required: false,
  634. controller: _approvedAmountCtrl,
  635. hintText: '0',
  636. colors: Theme.of(context).extension<AppColorsExtension>()!,
  637. keyboardType: const TextInputType.numberWithOptions(decimal: true),
  638. inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}$'))],
  639. );
  640. }
  641. Widget _buildOffsetCard() {
  642. return _inputCard(
  643. label: _l10n.get('offsetAmount'),
  644. required: false,
  645. controller: _offsetCtrl,
  646. hintText: '0',
  647. colors: Theme.of(context).extension<AppColorsExtension>()!,
  648. keyboardType: const TextInputType.numberWithOptions(decimal: true),
  649. inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}$'))],
  650. );
  651. }
  652. // ── 备注 ──
  653. Widget _buildRemarkInput(AppColorsExtension colors) {
  654. final tdTheme = TDTheme.of(context);
  655. return TDTextarea(
  656. controller: _remarkCtrl,
  657. label: _l10n.get('remark'),
  658. hintText: _l10n.get('enterRemark'),
  659. maxLines: 3,
  660. minLines: 1,
  661. maxLength: 500,
  662. indicator: true,
  663. decoration: BoxDecoration(
  664. color: tdTheme.bgColorContainer,
  665. borderRadius: BorderRadius.circular(tdTheme.radiusDefault),
  666. border: Border.all(color: tdTheme.componentStrokeColor),
  667. ),
  668. onChanged: (_) => setState(() {}),
  669. );
  670. }
  671. // ── 操作按钮 ──
  672. Widget _buildAttachmentCard(AppColorsExtension colors) {
  673. final tdTheme = TDTheme.of(context);
  674. return Column(
  675. crossAxisAlignment: CrossAxisAlignment.start,
  676. children: [
  677. Padding(
  678. padding: const EdgeInsets.only(left: 4),
  679. child: TDText(
  680. _l10n.get('attachmentUpload'),
  681. font: tdTheme.fontBodyLarge,
  682. fontWeight: FontWeight.w400,
  683. style: const TextStyle(letterSpacing: 0),
  684. ),
  685. ),
  686. const SizedBox(height: 4),
  687. AttachmentPicker(
  688. controller: _attachmentCtrl,
  689. maxImageSizeMB: 10,
  690. maxFileSizeMB: 20,
  691. allowedExtensions: const ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt'],
  692. onFileRejected: (file, reason) {
  693. if (context.mounted) TDToast.showText(reason, context: context);
  694. },
  695. ),
  696. ],
  697. );
  698. }
  699. // ── 会计科目(只读,选择类别后自动带出) ──
  700. Widget _buildAcctSubjectCard(AppColorsExtension colors) {
  701. return _readOnlyCard(
  702. label: _l10n.get('acctSubject'),
  703. value: '${_selCat.acctSubjectId}/${_selCat.acctSubjectName}',
  704. colors: colors,
  705. );
  706. }
  707. Widget _readOnlyCard({
  708. required String label,
  709. required String value,
  710. required AppColorsExtension colors,
  711. }) {
  712. final tdTheme = TDTheme.of(context);
  713. return Container(
  714. padding: const EdgeInsets.only(left: 16, right: 16, top: 12, bottom: 12),
  715. decoration: BoxDecoration(
  716. color: tdTheme.bgColorContainer,
  717. borderRadius: BorderRadius.circular(tdTheme.radiusDefault),
  718. border: Border.all(color: tdTheme.componentStrokeColor),
  719. ),
  720. child: Row(
  721. children: [
  722. TDText(label, maxLines: 1, overflow: TextOverflow.visible, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400, style: const TextStyle(letterSpacing: 0)),
  723. const SizedBox(width: 12),
  724. Expanded(
  725. child: TDText(value, maxLines: 1, overflow: TextOverflow.ellipsis, font: tdTheme.fontBodyLarge, fontWeight: FontWeight.w400,
  726. textColor: tdTheme.textColorPrimary, textAlign: TextAlign.end),
  727. ),
  728. ],
  729. ),
  730. );
  731. }
  732. // ── 关联项目 ──
  733. Widget _buildProjectCard(AppColorsExtension colors) {
  734. final projects = widget.projects;
  735. return _pickerCard(
  736. label: _l10n.get('relatedProject'),
  737. required: false,
  738. currentLabel: _selProject != null ? '${_selProject!.id}/${_selProject!.name}' : _l10n.get('pleaseSelect'),
  739. labels: projects.map((p) => '${p.id}/${p.name}').toList(),
  740. colors: colors,
  741. onSelected: (idx) => setState(() => _selProject = projects[idx]),
  742. onClear: _selProject != null ? () => setState(() => _selProject = null) : null,
  743. );
  744. }
  745. // ── 费用承担部门 ──
  746. Widget _buildCostDeptCard(AppColorsExtension colors) {
  747. final depts = widget.costDepts;
  748. return _pickerCard(
  749. label: _l10n.get('costDept'),
  750. required: false,
  751. currentLabel: _selDept != null ? '${_selDept!.id}/${_selDept!.name}' : _l10n.get('pleaseSelect'),
  752. labels: depts.map((d) => '${d.id}/${d.name}').toList(),
  753. colors: colors,
  754. onSelected: (idx) => setState(() => _selDept = depts[idx]),
  755. onClear: _selDept != null ? () => setState(() => _selDept = null) : null,
  756. );
  757. }
  758. // ── 收款银行信息 ──
  759. Widget _buildBankInfoCard(AppColorsExtension colors) {
  760. return Column(
  761. crossAxisAlignment: CrossAxisAlignment.start,
  762. children: [
  763. _inputCard(label: _l10n.get('bankName'), required: false, controller: _bankNameCtrl, hintText: _l10n.get('pleaseEnter'), colors: colors),
  764. const SizedBox(height: 12),
  765. _inputCard(label: _l10n.get('bankAccountName'), required: false, controller: _bankAccountNameCtrl, hintText: _l10n.get('pleaseEnter'), colors: colors),
  766. const SizedBox(height: 12),
  767. _inputCard(label: _l10n.get('bankAccount'), required: false, controller: _bankAccountCtrl, hintText: _l10n.get('pleaseEnter'), colors: colors),
  768. ],
  769. );
  770. }
  771. Widget _buildActions() {
  772. return Row(
  773. children: [
  774. Expanded(
  775. child: TDButton(
  776. text: _l10n.get('cancel'),
  777. size: TDButtonSize.large,
  778. type: TDButtonType.outline,
  779. shape: TDButtonShape.rectangle,
  780. theme: TDButtonTheme.defaultTheme,
  781. onTap: () => Navigator.pop(context),
  782. ),
  783. ),
  784. const SizedBox(width: 12),
  785. Expanded(
  786. child: TDButton(
  787. text: _isEdit ? _l10n.get('confirmEdit') : _l10n.get('add'),
  788. size: TDButtonSize.large,
  789. type: TDButtonType.fill,
  790. shape: TDButtonShape.rectangle,
  791. theme: TDButtonTheme.primary,
  792. onTap: _confirm,
  793. ),
  794. ),
  795. ],
  796. );
  797. }
  798. }