|
|
@@ -1,4 +1,5 @@
|
|
|
import 'package:flutter/material.dart';
|
|
|
+import 'package:flutter/services.dart';
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
@@ -12,9 +13,13 @@ import '../../core/i18n/app_localizations.dart';
|
|
|
import 'expense_model.dart';
|
|
|
import '../../core/theme/app_colors.dart';
|
|
|
import '../../core/theme/app_colors_extension.dart';
|
|
|
+import '../../core/navigation/host_app_channel.dart';
|
|
|
import '../../core/data/mock_api_data.dart';
|
|
|
import 'widgets/expense_detail_dialog.dart';
|
|
|
-import 'package:image_picker/image_picker.dart';
|
|
|
+import '../../shared/widgets/action_bar.dart';
|
|
|
+import '../../shared/widgets/submitting_dialog.dart';
|
|
|
+import '../../shared/widgets/attachment_picker.dart';
|
|
|
+import 'expense_apply_import_page.dart';
|
|
|
|
|
|
class ExpenseApplyPage extends ConsumerStatefulWidget {
|
|
|
final String? editId;
|
|
|
@@ -24,58 +29,120 @@ class ExpenseApplyPage extends ConsumerStatefulWidget {
|
|
|
ConsumerState<ExpenseApplyPage> createState() => _ExpenseApplyPageState();
|
|
|
}
|
|
|
|
|
|
-class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
+class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage>
|
|
|
+ with WidgetsBindingObserver {
|
|
|
final _purposeController = TextEditingController();
|
|
|
- final List<String> _attachments = [];
|
|
|
+ final _purposeFocus = FocusNode();
|
|
|
+ final _remarkController = TextEditingController();
|
|
|
+ final _remarkFocus = FocusNode();
|
|
|
+ final _scrollCtrl = ScrollController();
|
|
|
+ late final AttachmentPickerController _attachmentController;
|
|
|
+ late Future<bool> _draftFuture;
|
|
|
+ bool _draftHandled = false;
|
|
|
+ bool _isPoppingToNative = false;
|
|
|
+
|
|
|
+ // ── 参考数据(从 API 加载) ──
|
|
|
+ List<CostTypeItem> _costTypes = [];
|
|
|
+ List<ProjectCodeItem> _projects = [];
|
|
|
+ List<DepartmentItem> _departments = [];
|
|
|
+ List<CustomerItem> _customers = [];
|
|
|
+ List<CurrencyItem> _currencies = [];
|
|
|
+ List<EmployeeItem> _employees = [];
|
|
|
+ bool _refDataLoading = true;
|
|
|
+
|
|
|
+ // ── 报销部门 ──
|
|
|
+ String _selectedDeptId = '';
|
|
|
+ String _selectedDeptName = '';
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
- WidgetsBinding.instance.addPostFrameCallback((_) => _checkDraft());
|
|
|
- }
|
|
|
-
|
|
|
- Future<void> _checkDraft() async {
|
|
|
- if (!mounted || widget.editId != null) return;
|
|
|
- final has = await ExpenseCreateController.hasDraft();
|
|
|
- if (!has || !mounted) return;
|
|
|
- final l10n = AppLocalizations.of(context);
|
|
|
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
- final yes = await showDialog<bool>(
|
|
|
- context: context,
|
|
|
- builder: (ctx) => TDAlertDialog(
|
|
|
- title: l10n.get('draftFound'),
|
|
|
- content: l10n.get('draftRestorePrompt'),
|
|
|
- leftBtn: TDDialogButtonOptions(
|
|
|
- title: l10n.get('discard'),
|
|
|
- titleColor: colors.textSecondary,
|
|
|
- action: () => Navigator.pop(ctx, false),
|
|
|
- ),
|
|
|
- rightBtn: TDDialogButtonOptions(
|
|
|
- title: l10n.get('restore'),
|
|
|
- titleColor: colors.primary,
|
|
|
- action: () => Navigator.pop(ctx, true),
|
|
|
- ),
|
|
|
+ WidgetsBinding.instance.addObserver(this);
|
|
|
+ SystemChrome.setSystemUIOverlayStyle(
|
|
|
+ const SystemUiOverlayStyle(
|
|
|
+ statusBarColor: Colors.transparent,
|
|
|
+ statusBarIconBrightness: Brightness.dark,
|
|
|
),
|
|
|
);
|
|
|
- if (yes == true && mounted) {
|
|
|
- final draft = await ExpenseCreateController.loadDraft();
|
|
|
- if (draft != null && mounted) {
|
|
|
- final api = ref.read(expenseApiProvider);
|
|
|
- ref.read(expenseCreateProvider(widget.editId).notifier)
|
|
|
- ..restoreFromDraft(draft, api);
|
|
|
- }
|
|
|
- } else {
|
|
|
- await ExpenseCreateController.deleteDraft();
|
|
|
+ _attachmentController = AttachmentPickerController(maxCount: 9)
|
|
|
+ ..addListener(() => setState(() {}));
|
|
|
+ _purposeFocus.addListener(() => _ensureVisible(_purposeFocus));
|
|
|
+ _remarkFocus.addListener(() => _ensureVisible(_remarkFocus));
|
|
|
+ _draftFuture = widget.editId == null
|
|
|
+ ? ExpenseCreateController.hasDraft()
|
|
|
+ : Future.value(false);
|
|
|
+ _loadRefData();
|
|
|
+ }
|
|
|
+
|
|
|
+ Future<void> _loadRefData() async {
|
|
|
+ try {
|
|
|
+ final api = ref.read(expenseApiProvider);
|
|
|
+ final results = await Future.wait([
|
|
|
+ api.getCostTypes(),
|
|
|
+ api.getProjectCodes(),
|
|
|
+ api.getDepartments(),
|
|
|
+ api.getCustomers(),
|
|
|
+ api.getCurrencies(),
|
|
|
+ api.getEmployees(),
|
|
|
+ ]);
|
|
|
+ if (!mounted) return;
|
|
|
+ setState(() {
|
|
|
+ _costTypes = results[0] as List<CostTypeItem>;
|
|
|
+ _projects = results[1] as List<ProjectCodeItem>;
|
|
|
+ _departments = results[2] as List<DepartmentItem>;
|
|
|
+ _customers = results[3] as List<CustomerItem>;
|
|
|
+ _currencies = results[4] as List<CurrencyItem>;
|
|
|
+ _employees = results[5] as List<EmployeeItem>;
|
|
|
+ _refDataLoading = false;
|
|
|
+ _autoSelectDept();
|
|
|
+ });
|
|
|
+ } catch (_) {
|
|
|
+ if (!mounted) return;
|
|
|
+ setState(() => _refDataLoading = false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void _ensureVisible(FocusNode node) {
|
|
|
+ if (!node.hasFocus) return;
|
|
|
+ WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
+ if (node.hasFocus && _scrollCtrl.hasClients) {
|
|
|
+ final ctx = node.context;
|
|
|
+ if (ctx != null) {
|
|
|
+ Scrollable.ensureVisible(ctx, alignment: 0.3, duration: const Duration(milliseconds: 300));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
void dispose() {
|
|
|
+ WidgetsBinding.instance.removeObserver(this);
|
|
|
_purposeController.dispose();
|
|
|
+ _purposeFocus.dispose();
|
|
|
+ _remarkController.dispose();
|
|
|
+ _remarkFocus.dispose();
|
|
|
+ _scrollCtrl.dispose();
|
|
|
+ _attachmentController.dispose();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
+ void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
|
+ if (state == AppLifecycleState.resumed && _isPoppingToNative) {
|
|
|
+ _isPoppingToNative = false;
|
|
|
+ HostAppChannel.refresh();
|
|
|
+ setState(() {
|
|
|
+ _draftHandled = false;
|
|
|
+ _draftFuture = widget.editId == null
|
|
|
+ ? ExpenseCreateController.hasDraft()
|
|
|
+ : Future.value(false);
|
|
|
+ _refDataLoading = true;
|
|
|
+ });
|
|
|
+ _loadRefData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
Widget build(BuildContext context) {
|
|
|
final controller = ref.watch(expenseCreateProvider(widget.editId).notifier);
|
|
|
final state = ref.watch(expenseCreateProvider(widget.editId));
|
|
|
@@ -90,12 +157,19 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
? l10n.get('editExpense')
|
|
|
: l10n.get('expenseApply'),
|
|
|
showBack: true,
|
|
|
- onBack: () => context.pop(),
|
|
|
+ onBack: () => _doPop(),
|
|
|
),
|
|
|
);
|
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
final bottomInset = MediaQuery.of(context).padding.bottom;
|
|
|
- return Column(
|
|
|
+
|
|
|
+ Widget pageContent = PopScope(
|
|
|
+ canPop: false,
|
|
|
+ onPopInvokedWithResult: (didPop, _) {
|
|
|
+ if (didPop) return;
|
|
|
+ _doPop();
|
|
|
+ },
|
|
|
+ child: Column(
|
|
|
children: [
|
|
|
Expanded(
|
|
|
child: Align(
|
|
|
@@ -103,6 +177,7 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
child: ConstrainedBox(
|
|
|
constraints: BoxConstraints(maxWidth: r.formMaxWidth),
|
|
|
child: SingleChildScrollView(
|
|
|
+ controller: _scrollCtrl,
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
child: Column(
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
@@ -113,7 +188,7 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
const SizedBox(height: 16),
|
|
|
_buildDetailSection(controller, state),
|
|
|
const SizedBox(height: 16),
|
|
|
- _buildInvoiceSection(controller, state),
|
|
|
+ _buildAttachmentSection(controller, state),
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
@@ -131,15 +206,199 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
),
|
|
|
),
|
|
|
],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+
|
|
|
+ return FutureBuilder<bool>(
|
|
|
+ future: _draftFuture,
|
|
|
+ builder: (ctx, snapshot) {
|
|
|
+ final hasDraft = snapshot.hasData && snapshot.data == true;
|
|
|
+
|
|
|
+ if (hasDraft && !_draftHandled) {
|
|
|
+ _draftHandled = true;
|
|
|
+ WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
+ if (mounted) _showDraftDialog();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return pageContent;
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ void _showDraftDialog() {
|
|
|
+ final l10n = AppLocalizations.of(context);
|
|
|
+ final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
+ showDialog(
|
|
|
+ context: context,
|
|
|
+ barrierDismissible: false,
|
|
|
+ builder: (ctx) => TDAlertDialog(
|
|
|
+ title: l10n.get('draftFound'),
|
|
|
+ content: l10n.get('draftRestorePrompt'),
|
|
|
+ leftBtn: TDDialogButtonOptions(
|
|
|
+ title: l10n.get('discard'),
|
|
|
+ titleColor: colors.textSecondary,
|
|
|
+ action: () {
|
|
|
+ Navigator.pop(ctx);
|
|
|
+ ExpenseCreateController.deleteDraft();
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ rightBtn: TDDialogButtonOptions(
|
|
|
+ title: l10n.get('restore'),
|
|
|
+ titleColor: colors.primary,
|
|
|
+ action: () async {
|
|
|
+ Navigator.pop(ctx);
|
|
|
+ final draft = await ExpenseCreateController.loadDraft();
|
|
|
+ if (draft != null && mounted) {
|
|
|
+ final api = ref.read(expenseApiProvider);
|
|
|
+ ref.read(expenseCreateProvider(widget.editId).notifier)
|
|
|
+ .restoreFromDraft(draft, api);
|
|
|
+ _purposeController.text = draft.purpose;
|
|
|
+ _remarkController.text = draft.remark;
|
|
|
+ if (draft.attachments.isNotEmpty) {
|
|
|
+ await _attachmentController.restoreFromPaths(draft.attachments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ // ═══ API 数据 → 弹窗类型转换 ═══
|
|
|
+
|
|
|
+ List<CostCategory> get _dialogCategories => _costTypes
|
|
|
+ .map((c) => CostCategory(code: c.typeNo, nameKey: c.typeName, acctSubjectId: c.accNo, acctSubjectName: c.accName))
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ List<Project> get _dialogProjects => _projects
|
|
|
+ .map((p) => Project(id: int.tryParse(p.objNo) ?? 0, name: p.name))
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ List<CostDept> get _dialogCostDepts => _departments
|
|
|
+ .map((d) => CostDept(id: d.dep, name: d.name))
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ String _currencyLabel(String code) {
|
|
|
+ final match = _currencies.where((c) => c.curId == code);
|
|
|
+ return match.isNotEmpty ? '${match.first.curId}/${match.first.name}' : code;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CustomerVendor> get _dialogCustomers => _customers
|
|
|
+ .map((c) => CustomerVendor(id: c.cusNo, name: c.name))
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ List<EmployeeItem> get _dialogEmployees => _employees;
|
|
|
+
|
|
|
+ void _autoSelectDept() {
|
|
|
+ if (_selectedDeptId.isNotEmpty) return;
|
|
|
+ final dep = HostAppChannel.dep;
|
|
|
+ if (dep.isEmpty) return;
|
|
|
+ final match = _departments.where((d) => d.dep == dep);
|
|
|
+ if (match.isNotEmpty) {
|
|
|
+ _selectedDeptId = match.first.dep;
|
|
|
+ _selectedDeptName = match.first.name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void _showDeptPicker() {
|
|
|
+ if (_departments.isEmpty) {
|
|
|
+ TDToast.showText(AppLocalizations.of(context).get('noData'), context: context);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final l10n = AppLocalizations.of(context);
|
|
|
+ final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
+ final labels = _departments.map((d) => d.name).toList();
|
|
|
+ TDPicker.showMultiPicker(
|
|
|
+ context,
|
|
|
+ title: l10n.get('expenseDept'),
|
|
|
+ backgroundColor: colors.bgCard,
|
|
|
+ data: [labels],
|
|
|
+ onConfirm: (selected) {
|
|
|
+ if (selected.isNotEmpty && selected[0] is int) {
|
|
|
+ final idx = selected[0] as int;
|
|
|
+ if (idx >= 0 && idx < labels.length) {
|
|
|
+ Navigator.of(context).pop();
|
|
|
+ setState(() {
|
|
|
+ _selectedDeptId = _departments[idx].dep;
|
|
|
+ _selectedDeptName = _departments[idx].name;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, dynamic> _buildSubmitData(ExpenseCreateState state) {
|
|
|
+ final expense = state.expense;
|
|
|
+ return {
|
|
|
+ 'HeadData': {
|
|
|
+ 'BX_DD': _today(),
|
|
|
+ 'DEP': _selectedDeptId,
|
|
|
+ 'USR_NO': HostAppChannel.usr,
|
|
|
+ 'PAY_ID': expense.paymentMethod,
|
|
|
+ 'PRT_SW': 'N',
|
|
|
+ 'USR': HostAppChannel.usr,
|
|
|
+ 'REM': expense.remark,
|
|
|
+ 'CUR_ID': expense.currencyCode,
|
|
|
+ 'EXC_RTO': 1,
|
|
|
+ 'REASON': expense.purpose,
|
|
|
+ },
|
|
|
+ 'BodyData1': expense.details.asMap().entries.map((e) {
|
|
|
+ final i = e.key;
|
|
|
+ final d = e.value;
|
|
|
+ return {
|
|
|
+ 'ITM': i + 1,
|
|
|
+ 'BX_DD': _today(),
|
|
|
+ 'ACC_NO': d.acctSubjectId,
|
|
|
+ 'AMT': d.amount,
|
|
|
+ 'AMTN': d.totalAmount,
|
|
|
+ 'REM': d.remark,
|
|
|
+ 'CUST': d.customerVendorId,
|
|
|
+ 'OBJ_NO': d.projectId.isNotEmpty ? d.projectId : '',
|
|
|
+ 'TAX': d.taxAmount,
|
|
|
+ 'TAX_RTO': d.taxRate,
|
|
|
+ 'DEP': d.costDeptId,
|
|
|
+ 'SQ_MAN': d.sqMan.isNotEmpty ? d.sqMan : HostAppChannel.usr,
|
|
|
+ };
|
|
|
+ }).toList(),
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
Widget _buildImportLink() {
|
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
return GestureDetector(
|
|
|
- onTap: () {
|
|
|
- TDToast.showText(l10n.get('expenseApplyImport'), context: context);
|
|
|
+ onTap: () async {
|
|
|
+ final result = await GoRouter.of(context).push<List<ImportableItem>>('/expense/import-apply');
|
|
|
+ if (result == null || result.isEmpty || !mounted) return;
|
|
|
+ // 将选中的导入数据转换为明细
|
|
|
+ final controller = ref.read(expenseCreateProvider(widget.editId).notifier);
|
|
|
+ final now = DateTime.now();
|
|
|
+ for (final item in result) {
|
|
|
+ controller.addDetail(ExpenseDetailModel(
|
|
|
+ id: '${now.millisecondsSinceEpoch}_${item.itm}',
|
|
|
+ expenseId: '',
|
|
|
+ expenseApplyId: '', expenseApplyNo: item.aeNo,
|
|
|
+ expenseApplyDate: item.aeDd.isNotEmpty ? DateTime.tryParse(item.aeDd) : null,
|
|
|
+ expenseCategory: item.typeNo, purpose: item.rem,
|
|
|
+ projectId: item.objNo, projectName: '',
|
|
|
+ costDeptId: item.dep, costDeptName: '',
|
|
|
+ acctSubjectId: item.accNo, acctSubjectName: item.accName,
|
|
|
+ amount: item.amtnYj, taxRate: 0.13, taxAmount: item.amtnYj - item.amtnYj / 1.13,
|
|
|
+ totalAmount: item.amtnYj, currencyCode: '', exchangeRate: 1.0,
|
|
|
+ baseAmount: item.amtnYj, approvedAmount: 0,
|
|
|
+ customerVendorId: '', customerVendorName: '',
|
|
|
+ offsetAmount: 0, bankName: '', bankAccountName: '', bankAccount: '',
|
|
|
+ remark: item.rem, sortOrder: item.itm,
|
|
|
+ attachments: const [],
|
|
|
+ sqMan: item.sqMan, sqManName: '',
|
|
|
+ aeNo: item.aeNo, aeDd: item.aeDd,
|
|
|
+ createTime: now, updateTime: now,
|
|
|
+ ));
|
|
|
+ }
|
|
|
+ controller.recalculateAmount();
|
|
|
+ TDToast.showSuccess(l10n.get('importSuccess'), context: context);
|
|
|
},
|
|
|
child: Container(
|
|
|
height: 44,
|
|
|
@@ -170,6 +429,7 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
ExpenseCreateState state,
|
|
|
) {
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
+ final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
final expense = state.expense;
|
|
|
return FormSection(
|
|
|
title: l10n.get('basicInfo'),
|
|
|
@@ -183,65 +443,75 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
),
|
|
|
const SizedBox(height: 16),
|
|
|
FormFieldRow(
|
|
|
- label: l10n.get('reportNo'),
|
|
|
- value: expense.expenseNo.isNotEmpty ? expense.expenseNo : null,
|
|
|
- hint: l10n.get('autoGenerated'),
|
|
|
+ label: l10n.get('expensePersonnel'),
|
|
|
+ value: HostAppChannel.usr.isNotEmpty && HostAppChannel.usrName.isNotEmpty
|
|
|
+ ? '${HostAppChannel.usr}/${HostAppChannel.usrName}'
|
|
|
+ : '--',
|
|
|
readOnly: true,
|
|
|
showArrow: false,
|
|
|
),
|
|
|
const SizedBox(height: 16),
|
|
|
FormFieldRow(
|
|
|
- label: l10n.get('currency'),
|
|
|
- value: expense.currencyCode.isNotEmpty ? expense.currencyCode : 'CNY',
|
|
|
- hint: l10n.get('selectCurrency'),
|
|
|
- onTap: () => _showCurrencyPicker(controller, expense.currencyCode),
|
|
|
+ label: l10n.get('expenseDept'),
|
|
|
+ value: _selectedDeptName.isNotEmpty
|
|
|
+ ? '$_selectedDeptId/$_selectedDeptName'
|
|
|
+ : null,
|
|
|
+ hint: l10n.get('pleaseSelect'),
|
|
|
+ onTap: _refDataLoading ? null : () => _showDeptPicker(),
|
|
|
),
|
|
|
const SizedBox(height: 16),
|
|
|
- FormFieldRow(
|
|
|
- label: l10n.get('applicant'),
|
|
|
- value: expense.applicantName.isNotEmpty
|
|
|
- ? expense.applicantName
|
|
|
- : '张三',
|
|
|
- readOnly: true,
|
|
|
- showArrow: false,
|
|
|
+ _label(l10n.get('expenseReason'), required: true),
|
|
|
+ const SizedBox(height: 8),
|
|
|
+ TDTextarea(
|
|
|
+ controller: _purposeController,
|
|
|
+ focusNode: _purposeFocus,
|
|
|
+ hintText: l10n.get('enterExpenseReason'),
|
|
|
+ maxLines: 4,
|
|
|
+ minLines: 1,
|
|
|
+ maxLength: 500,
|
|
|
+ indicator: true,
|
|
|
+ padding: EdgeInsets.zero,
|
|
|
+ bordered: true,
|
|
|
+ backgroundColor: colors.bgPage,
|
|
|
+ onChanged: (_) => controller.updatePurpose(_purposeController.text),
|
|
|
),
|
|
|
const SizedBox(height: 16),
|
|
|
FormFieldRow(
|
|
|
- label: l10n.get('department'),
|
|
|
- value: expense.deptName.isNotEmpty ? expense.deptName : '技术部',
|
|
|
- readOnly: true,
|
|
|
- showArrow: false,
|
|
|
+ label: l10n.get('paymentMethod'),
|
|
|
+ value: expense.paymentMethod,
|
|
|
+ hint: l10n.get('pleaseEnter'),
|
|
|
+ onTap: () => _showTextInput(
|
|
|
+ l10n.get('paymentMethod'),
|
|
|
+ (v) => controller.updatePaymentMethod(v),
|
|
|
+ initialText: expense.paymentMethod,
|
|
|
+ ),
|
|
|
+ onClear: () => controller.updatePaymentMethod(''),
|
|
|
),
|
|
|
const SizedBox(height: 16),
|
|
|
FormFieldRow(
|
|
|
- label: l10n.get('paymentMethod'),
|
|
|
- value: expense.paymentMethod.isNotEmpty
|
|
|
- ? expense.paymentMethod
|
|
|
+ label: l10n.get('currency'),
|
|
|
+ value: expense.currencyCode.isNotEmpty
|
|
|
+ ? _currencyLabel(expense.currencyCode)
|
|
|
: null,
|
|
|
- hint: l10n.get('selectPaymentMethod'),
|
|
|
- onTap: () => _showPaymentMethodPicker(controller),
|
|
|
+ hint: l10n.get('selectCurrency'),
|
|
|
+ onTap: () => _showCurrencyPicker(controller, expense.currencyCode),
|
|
|
+ onClear: () => controller.updateCurrencyCode(''),
|
|
|
),
|
|
|
const SizedBox(height: 16),
|
|
|
- FormFieldRow(
|
|
|
- label: l10n.get('expenseReason'),
|
|
|
- value: _purposeController.text.isNotEmpty
|
|
|
- ? _purposeController.text
|
|
|
- : null,
|
|
|
- hint: l10n.get('enterExpenseReason'),
|
|
|
- onTap: () => _showTextInput(
|
|
|
- l10n.get('expenseReason'),
|
|
|
- l10n.get('enterExpenseReason'),
|
|
|
- (v) {
|
|
|
- setState(() {
|
|
|
- _purposeController.text = v;
|
|
|
- _purposeController.selection = TextSelection.fromPosition(
|
|
|
- TextPosition(offset: v.length),
|
|
|
- );
|
|
|
- });
|
|
|
- controller.updatePurpose(v);
|
|
|
- },
|
|
|
- initialText: _purposeController.text,
|
|
|
- ),
|
|
|
+ _label(l10n.get('remark')),
|
|
|
+ const SizedBox(height: 8),
|
|
|
+ TDTextarea(
|
|
|
+ controller: _remarkController,
|
|
|
+ focusNode: _remarkFocus,
|
|
|
+ hintText: l10n.get('enterRemark'),
|
|
|
+ maxLines: 3,
|
|
|
+ minLines: 1,
|
|
|
+ maxLength: 500,
|
|
|
+ indicator: true,
|
|
|
+ padding: EdgeInsets.zero,
|
|
|
+ bordered: true,
|
|
|
+ backgroundColor: colors.bgPage,
|
|
|
+ onChanged: (_) => controller.updateRemark(_remarkController.text),
|
|
|
),
|
|
|
],
|
|
|
);
|
|
|
@@ -260,7 +530,7 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
return FormSection(
|
|
|
title: l10n.get('expenseDetails'),
|
|
|
leadingIcon: Icons.receipt_long_outlined,
|
|
|
- showAction: true,
|
|
|
+ showAction: !_refDataLoading,
|
|
|
actionText: l10n.get('add'),
|
|
|
onActionTap: () => _showAddDetailDialog(controller),
|
|
|
children: [
|
|
|
@@ -275,39 +545,46 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
else
|
|
|
...state.expense.details.asMap().entries.map((entry) {
|
|
|
final d = entry.value;
|
|
|
- return Container(
|
|
|
- margin: const EdgeInsets.symmetric(vertical: 8),
|
|
|
+ return GestureDetector(
|
|
|
+ onTap: () => _showAddDetailDialog(controller, editIndex: entry.key),
|
|
|
+ child: Container(
|
|
|
+ margin: const EdgeInsets.symmetric(vertical: 6),
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
decoration: BoxDecoration(color: colors.bgPage, borderRadius: BorderRadius.circular(8)),
|
|
|
- child: Stack(
|
|
|
+ child: Row(
|
|
|
children: [
|
|
|
- Column(
|
|
|
- crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
- children: [
|
|
|
- Row(
|
|
|
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
- children: [
|
|
|
- Expanded(child: Text(d.purpose.isNotEmpty ? d.purpose : d.expenseCategory,
|
|
|
- style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.textPrimary))),
|
|
|
- Text('¥${d.totalAmount.toStringAsFixed(2)}',
|
|
|
- style: TextStyle(fontSize: AppFontSizes.subtitle, fontWeight: FontWeight.w600, color: colors.amountPrimary)),
|
|
|
- ],
|
|
|
- ),
|
|
|
- const SizedBox(height: 4),
|
|
|
- Text('¥${d.amount.toStringAsFixed(2)} + 税${d.taxAmount.toStringAsFixed(2)} | ${d.bankName}',
|
|
|
- style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textSecondary)),
|
|
|
- ],
|
|
|
- ),
|
|
|
- Positioned(
|
|
|
- right: 0, top: 0,
|
|
|
- child: GestureDetector(
|
|
|
- onTap: () { controller.removeDetail(entry.key); controller.recalculateAmount(); },
|
|
|
- child: Container(width: 24, height: 24, decoration: BoxDecoration(color: colors.primaryLight, shape: BoxShape.circle),
|
|
|
- child: Icon(Icons.close, size: 14, color: colors.primary700)),
|
|
|
+ Expanded(
|
|
|
+ child: Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ Row(children: [
|
|
|
+ Expanded(child: Text(d.expenseCategory.isNotEmpty ? d.expenseCategory : d.purpose, style: TextStyle(fontSize: AppFontSizes.body, fontWeight: FontWeight.w500, color: colors.textPrimary))),
|
|
|
+ Text('¥${d.totalAmount.toStringAsFixed(2)}', style: TextStyle(fontSize: AppFontSizes.body, fontWeight: FontWeight.w600, color: colors.amountPrimary)),
|
|
|
+ ]),
|
|
|
+ const SizedBox(height: 4),
|
|
|
+ if (d.purpose.isNotEmpty)
|
|
|
+ Text(d.purpose, maxLines: 2, overflow: TextOverflow.ellipsis, style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textPrimary)),
|
|
|
+ const SizedBox(height: 2),
|
|
|
+ Text('¥${d.amount.toStringAsFixed(2)} ${l10n.get('tax')}¥${d.taxAmount.toStringAsFixed(2)} | ${d.acctSubjectName}', style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textSecondary)),
|
|
|
+ if (d.projectName.isNotEmpty || d.costDeptName.isNotEmpty)
|
|
|
+ Text('${d.projectName}${d.costDeptName.isNotEmpty ? " | ${d.costDeptName}" : ""}', style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textSecondary)),
|
|
|
+ if (d.customerVendorName.isNotEmpty)
|
|
|
+ Text('${l10n.get('customerVendor')}: ${d.customerVendorName}', style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textSecondary)),
|
|
|
+ if (d.bankName.isNotEmpty || d.bankAccount.isNotEmpty)
|
|
|
+ Text('${d.bankName}${d.bankAccount.isNotEmpty ? " | ${d.bankAccount}" : ""}', style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textSecondary)),
|
|
|
+ if (d.sqManName.isNotEmpty)
|
|
|
+ Text('${l10n.get('applicant')}: ${d.sqManName.isNotEmpty ? d.sqManName : d.sqMan}', style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textSecondary)),
|
|
|
+ ],
|
|
|
),
|
|
|
),
|
|
|
+ const SizedBox(width: 8),
|
|
|
+ GestureDetector(
|
|
|
+ onTap: () { controller.removeDetail(entry.key); controller.recalculateAmount(); },
|
|
|
+ child: Container(width: 24, height: 24, decoration: BoxDecoration(color: colors.primaryLight, shape: BoxShape.circle), child: Icon(Icons.close, size: 14, color: colors.primary700)),
|
|
|
+ ),
|
|
|
],
|
|
|
),
|
|
|
+ ),
|
|
|
);
|
|
|
}),
|
|
|
const SizedBox(height: 8),
|
|
|
@@ -324,185 +601,285 @@ class _ExpenseApplyPageState extends ConsumerState<ExpenseApplyPage> {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Widget _buildInvoiceSection(ExpenseCreateController controller, ExpenseCreateState state) {
|
|
|
+ Widget _buildAttachmentSection(ExpenseCreateController controller, ExpenseCreateState state) {
|
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
return FormSection(
|
|
|
- title: l10n.get('invoiceUpload'),
|
|
|
+ title: l10n.get('attachmentUpload'),
|
|
|
leadingIcon: Icons.attach_file_outlined,
|
|
|
children: [
|
|
|
- Text(l10n.get('maxInvoices'), style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textPlaceholder)),
|
|
|
+ Text(l10n.get('maxAttachment'), style: TextStyle(fontSize: AppFontSizes.caption, color: colors.textPlaceholder)),
|
|
|
const SizedBox(height: 8),
|
|
|
- if (_attachments.isEmpty)
|
|
|
- Text(l10n.get('noAttachment'), style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.textPlaceholder))
|
|
|
- else
|
|
|
- Wrap(
|
|
|
- spacing: 8,
|
|
|
- runSpacing: 8,
|
|
|
- children: [
|
|
|
- ..._attachments.asMap().entries.map((entry) {
|
|
|
- final i = entry.key;
|
|
|
- final path = entry.value;
|
|
|
- final name = path.split('/').last.split('\\').last;
|
|
|
- return SizedBox(
|
|
|
- width: 80,
|
|
|
- child: Stack(
|
|
|
- children: [
|
|
|
- Container(
|
|
|
- width: 80,
|
|
|
- height: 80,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: colors.bgPage,
|
|
|
- borderRadius: BorderRadius.circular(4),
|
|
|
- border: Border.all(color: colors.border),
|
|
|
- ),
|
|
|
- child: Column(
|
|
|
- mainAxisAlignment: MainAxisAlignment.center,
|
|
|
- children: [
|
|
|
- Icon(Icons.insert_drive_file, size: 28, color: colors.primary),
|
|
|
- const SizedBox(height: 2),
|
|
|
- Padding(
|
|
|
- padding: const EdgeInsets.symmetric(horizontal: 4),
|
|
|
- child: Text(
|
|
|
- name,
|
|
|
- maxLines: 2,
|
|
|
- overflow: TextOverflow.ellipsis,
|
|
|
- style: TextStyle(fontSize: 10, color: colors.textSecondary),
|
|
|
- textAlign: TextAlign.center,
|
|
|
- ),
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
- ),
|
|
|
- Positioned(
|
|
|
- right: 0,
|
|
|
- top: 0,
|
|
|
- child: GestureDetector(
|
|
|
- onTap: () => setState(() => _attachments.removeAt(i)),
|
|
|
- child: Container(
|
|
|
- width: 20,
|
|
|
- height: 20,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: colors.bgCard,
|
|
|
- shape: BoxShape.circle,
|
|
|
- border: Border.all(color: colors.border),
|
|
|
- ),
|
|
|
- child: Icon(Icons.close, size: 12, color: colors.textSecondary),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
- );
|
|
|
- }),
|
|
|
- if (_attachments.length < 9)
|
|
|
- GestureDetector(
|
|
|
- onTap: _pickFiles,
|
|
|
- child: Container(
|
|
|
- width: 80,
|
|
|
- height: 80,
|
|
|
- decoration: BoxDecoration(
|
|
|
- color: colors.bgPage,
|
|
|
- borderRadius: BorderRadius.circular(4),
|
|
|
- border: Border.all(color: colors.border),
|
|
|
- ),
|
|
|
- child: Center(child: Icon(Icons.add, size: 24, color: colors.textPlaceholder)),
|
|
|
- ),
|
|
|
- ),
|
|
|
- ],
|
|
|
- ),
|
|
|
+ AttachmentPicker(
|
|
|
+ controller: _attachmentController,
|
|
|
+ maxImageSizeMB: 10,
|
|
|
+ maxFileSizeMB: 20,
|
|
|
+ allowedExtensions: const ['pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt'],
|
|
|
+ onFileRejected: (file, reason) {
|
|
|
+ if (context.mounted) TDToast.showText(reason, context: context);
|
|
|
+ },
|
|
|
+ ),
|
|
|
],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Future<void> _pickFiles() async {
|
|
|
- final available = 9 - _attachments.length;
|
|
|
- if (available <= 0) return;
|
|
|
- final picker = ImagePicker();
|
|
|
- final images = await picker.pickMultiImage(limit: available);
|
|
|
- if (images.isEmpty) return;
|
|
|
- setState(() {
|
|
|
- _attachments.addAll(images.map((img) => img.path));
|
|
|
- if (_attachments.length > 9) _attachments.length = 9;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
Widget _buildBottomButtons(ExpenseCreateController controller, ExpenseCreateState state) {
|
|
|
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
- return Container(height: 72, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16), decoration: BoxDecoration(color: colors.bgCard),
|
|
|
- child: Row(children: [
|
|
|
- _btn(l10n.get('saveDraftShort'), colors.textSecondary, colors.bgCard, () async {
|
|
|
- if (state.isSubmitting) return;
|
|
|
- final ok = await controller.saveDraft();
|
|
|
- if (mounted && ok) TDToast.showText(l10n.get('draftSavedToast'), context: context);
|
|
|
- }),
|
|
|
- const SizedBox(width: 12),
|
|
|
- _btn(l10n.get('reset'), colors.textSecondary, colors.bgCard, () => setState(() => _purposeController.clear())),
|
|
|
- const SizedBox(width: 12),
|
|
|
- _btn(l10n.get('save'), colors.bgCard, colors.primary, () async {
|
|
|
- if (state.isSubmitting) return;
|
|
|
- await controller.saveDraft();
|
|
|
- if (mounted) context.pop();
|
|
|
- }),
|
|
|
- ]));
|
|
|
- }
|
|
|
-
|
|
|
- Widget _btn(String label, Color fg, Color bg, VoidCallback onTap) {
|
|
|
- return Expanded(child: SizedBox(height: 40,
|
|
|
- child: Material(color: bg, borderRadius: BorderRadius.circular(22),
|
|
|
- child: InkWell(onTap: onTap, borderRadius: BorderRadius.circular(22),
|
|
|
- child: Center(child: Text(label, style: TextStyle(fontSize: AppFontSizes.body, fontWeight: FontWeight.w500, color: fg)))))));
|
|
|
+ return ActionBar(
|
|
|
+ showLeft: false,
|
|
|
+ centerLabel: l10n.get('saveDraft'),
|
|
|
+ rightLabel: l10n.get('submit'),
|
|
|
+ centerTextOnly: true,
|
|
|
+ onCenterTap: () async {
|
|
|
+ if (state.isSubmitting) return;
|
|
|
+ controller.updateAttachments(_attachmentController.toPathList());
|
|
|
+ controller.updateDept(_selectedDeptId, _selectedDeptName);
|
|
|
+ final ok = await controller.saveDraft();
|
|
|
+ if (mounted) {
|
|
|
+ if (ok) {
|
|
|
+ _forcePop();
|
|
|
+ } else {
|
|
|
+ TDToast.showFail(l10n.get('saveFailed'), context: context);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onRightTap: () async {
|
|
|
+ if (state.isSubmitting) return;
|
|
|
+ final err = _validate(l10n, state);
|
|
|
+ if (err.isNotEmpty) {
|
|
|
+ TDToast.showText(err.first, context: context);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SubmittingDialog.show(context);
|
|
|
+ try {
|
|
|
+ final data = _buildSubmitData(state);
|
|
|
+ await ref.read(expenseApiProvider).submit(data);
|
|
|
+ await ExpenseCreateController.deleteDraft();
|
|
|
+ if (mounted) {
|
|
|
+ SubmittingDialog.hide(context);
|
|
|
+ TDToast.showSuccess(l10n.get('submittedAwaitingApproval'), context: context);
|
|
|
+ GoRouter.of(context).go('/expense/list');
|
|
|
+ }
|
|
|
+ } catch (_) {
|
|
|
+ if (mounted) {
|
|
|
+ SubmittingDialog.hide(context);
|
|
|
+ TDToast.showFail(l10n.get('submitFailedRetry'), context: context);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- Future<void> _showAddDetailDialog(ExpenseCreateController controller) async {
|
|
|
+ Future<void> _showAddDetailDialog(ExpenseCreateController controller, {int? editIndex}) async {
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
- final result = await ExpenseDetailDialog.show(context, categories: mockCostCategories, l10n: l10n);
|
|
|
+ if (_costTypes.isEmpty) {
|
|
|
+ TDToast.showText(l10n.get('noCostTypeData'), context: context);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ final state = controller.currentState;
|
|
|
+ ExpenseDetailInputData? initialData;
|
|
|
+ if (editIndex != null) {
|
|
|
+ final d = state.expense.details[editIndex];
|
|
|
+ initialData = ExpenseDetailInputData(
|
|
|
+ category: d.expenseCategory,
|
|
|
+ categoryName: '',
|
|
|
+ acctSubjectId: d.acctSubjectId,
|
|
|
+ acctSubjectName: d.acctSubjectName,
|
|
|
+ purpose: d.purpose,
|
|
|
+ amount: d.amount,
|
|
|
+ taxRate: d.taxRate,
|
|
|
+ projectId: d.projectId,
|
|
|
+ projectName: d.projectName,
|
|
|
+ costDeptId: d.costDeptId,
|
|
|
+ costDeptName: d.costDeptName,
|
|
|
+ customerVendorId: d.customerVendorId,
|
|
|
+ customerVendorName: d.customerVendorName,
|
|
|
+ offsetAmount: d.offsetAmount,
|
|
|
+ bankName: d.bankName,
|
|
|
+ bankAccountName: d.bankAccountName,
|
|
|
+ bankAccount: d.bankAccount,
|
|
|
+ remark: d.remark,
|
|
|
+ attachmentPaths: d.attachments,
|
|
|
+ sqMan: d.sqMan,
|
|
|
+ sqManName: d.sqManName,
|
|
|
+ aeNo: d.aeNo,
|
|
|
+ aeDd: d.aeDd,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ final result = await ExpenseDetailDialog.show(
|
|
|
+ context,
|
|
|
+ categories: _dialogCategories,
|
|
|
+ projects: _dialogProjects,
|
|
|
+ costDepts: _dialogCostDepts,
|
|
|
+ customers: _dialogCustomers,
|
|
|
+ employees: _dialogEmployees,
|
|
|
+ l10n: l10n,
|
|
|
+ initialData: initialData,
|
|
|
+ );
|
|
|
if (result != null && mounted) {
|
|
|
final now = DateTime.now();
|
|
|
- controller.addDetail(ExpenseDetailModel(
|
|
|
- id: now.millisecondsSinceEpoch.toString(),
|
|
|
+ final detail = ExpenseDetailModel(
|
|
|
+ id: editIndex != null ? state.expense.details[editIndex].id : now.millisecondsSinceEpoch.toString(),
|
|
|
expenseId: '',
|
|
|
expenseCategory: result.category,
|
|
|
purpose: result.purpose,
|
|
|
amount: result.amount,
|
|
|
taxRate: result.taxRate,
|
|
|
+ taxAmount: result.amount - result.amount / (1 + result.taxRate),
|
|
|
totalAmount: result.amount,
|
|
|
+ projectId: result.projectId,
|
|
|
+ projectName: result.projectName,
|
|
|
+ costDeptId: result.costDeptId,
|
|
|
+ costDeptName: result.costDeptName,
|
|
|
+ acctSubjectId: result.acctSubjectId,
|
|
|
+ acctSubjectName: result.acctSubjectName,
|
|
|
customerVendorName: result.customerVendorName,
|
|
|
offsetAmount: result.offsetAmount,
|
|
|
+ bankName: result.bankName,
|
|
|
+ bankAccountName: result.bankAccountName,
|
|
|
+ bankAccount: result.bankAccount,
|
|
|
remark: result.remark,
|
|
|
+ attachments: result.attachmentPaths,
|
|
|
createTime: now,
|
|
|
updateTime: now,
|
|
|
- ));
|
|
|
+ );
|
|
|
+ if (editIndex != null) {
|
|
|
+ controller.updateDetail(editIndex, detail);
|
|
|
+ } else {
|
|
|
+ controller.addDetail(detail);
|
|
|
+ }
|
|
|
controller.recalculateAmount();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void _showCurrencyPicker(ExpenseCreateController controller, String cur) {
|
|
|
+ if (_currencies.isEmpty) {
|
|
|
+ TDToast.showText(AppLocalizations.of(context).get('noData'), context: context);
|
|
|
+ return;
|
|
|
+ }
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
- const cs = ['CNY', 'USD', 'EUR', 'JPY', 'HKD', 'GBP'];
|
|
|
- TDPicker.showMultiPicker(context, title: l10n.get('selectCurrency'), backgroundColor: colors.bgCard, data: [cs], onConfirm: (s) {
|
|
|
- if (s.isNotEmpty && s[0] is int) { final i = s[0] as int; if (i >= 0 && i < cs.length) { Navigator.of(context).pop(); controller.updateCurrencyCode(cs[i]); } }
|
|
|
+ final codes = _currencies.map((c) => c.curId).toList();
|
|
|
+ final labels = _currencies.map((c) => '${c.curId} ${c.name}').toList();
|
|
|
+ TDPicker.showMultiPicker(context, title: l10n.get('selectCurrency'), backgroundColor: colors.bgCard, data: [labels], onConfirm: (s) {
|
|
|
+ if (s.isNotEmpty && s[0] is int) { final i = s[0] as int; if (i >= 0 && i < codes.length) { Navigator.of(context).pop(); controller.updateCurrencyCode(codes[i]); } }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- void _showPaymentMethodPicker(ExpenseCreateController controller) {
|
|
|
+ void _showTextInput(
|
|
|
+ String title,
|
|
|
+ Function(String) onConfirm, {
|
|
|
+ String initialText = '',
|
|
|
+ }) {
|
|
|
+ FocusScope.of(context).unfocus();
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
+ final c = TextEditingController(text: initialText);
|
|
|
+ showGeneralDialog(
|
|
|
+ context: context,
|
|
|
+ pageBuilder: (ctx, animation, secondaryAnimation) => TDInputDialog(
|
|
|
+ textEditingController: c,
|
|
|
+ title: title,
|
|
|
+ hintText: l10n.get('pleaseEnter'),
|
|
|
+ leftBtn: TDDialogButtonOptions(
|
|
|
+ title: l10n.get('cancel'),
|
|
|
+ action: () => Navigator.pop(ctx),
|
|
|
+ ),
|
|
|
+ rightBtn: TDDialogButtonOptions(
|
|
|
+ title: l10n.get('confirm'),
|
|
|
+ action: () {
|
|
|
+ onConfirm(c.text);
|
|
|
+ Navigator.pop(ctx);
|
|
|
+ },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ Widget _label(String t, {bool required = false}) {
|
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
- const ms = ['bankTransfer', 'cash', 'check', 'alipay', 'wechat'];
|
|
|
- TDPicker.showMultiPicker(context, title: l10n.get('selectPaymentMethod'), backgroundColor: colors.bgCard, data: [ms], onConfirm: (s) {
|
|
|
- if (s.isNotEmpty && s[0] is int) { final i = s[0] as int; if (i >= 0 && i < ms.length) { Navigator.of(context).pop(); TDToast.showText(ms[i], context: context); } }
|
|
|
- });
|
|
|
+ return Text.rich(
|
|
|
+ TextSpan(
|
|
|
+ children: [
|
|
|
+ TextSpan(text: t, style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.textSecondary)),
|
|
|
+ if (required)
|
|
|
+ TextSpan(text: ' *', style: TextStyle(fontSize: AppFontSizes.subtitle, color: colors.danger)),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> _validate(AppLocalizations l10n, ExpenseCreateState state) {
|
|
|
+ final e = <String>[];
|
|
|
+ if (_purposeController.text.trim().isEmpty) {
|
|
|
+ e.add(l10n.get('enterExpenseReason'));
|
|
|
+ }
|
|
|
+ if (state.expense.details.isEmpty) {
|
|
|
+ e.add(l10n.get('addAtLeastOneDetail'));
|
|
|
+ }
|
|
|
+ return e;
|
|
|
}
|
|
|
|
|
|
- void _showTextInput(String title, String hint, void Function(String) onConfirm, {String initialText = ''}) {
|
|
|
+ bool _hasUnsaved(ExpenseCreateState state) =>
|
|
|
+ _purposeController.text.isNotEmpty ||
|
|
|
+ state.expense.paymentMethod.isNotEmpty ||
|
|
|
+ state.expense.currencyCode.isNotEmpty ||
|
|
|
+ _remarkController.text.isNotEmpty ||
|
|
|
+ state.expense.details.isNotEmpty ||
|
|
|
+ _attachmentController.files.isNotEmpty ||
|
|
|
+ _selectedDeptId.isNotEmpty;
|
|
|
+
|
|
|
+ void _doPop() {
|
|
|
final l10n = AppLocalizations.of(context);
|
|
|
- final c = TextEditingController(text: initialText);
|
|
|
- showGeneralDialog(context: context, pageBuilder: (ctx, _, __) => TDInputDialog(
|
|
|
- textEditingController: c, title: title, hintText: hint,
|
|
|
- leftBtn: TDDialogButtonOptions(title: l10n.get('cancel'), action: () => Navigator.pop(ctx)),
|
|
|
- rightBtn: TDDialogButtonOptions(title: l10n.get('confirm'), action: () { onConfirm(c.text); Navigator.pop(ctx); })));
|
|
|
+ final state = ref.read(expenseCreateProvider(widget.editId));
|
|
|
+ if (_hasUnsaved(state)) {
|
|
|
+ _showConfirmDialog(
|
|
|
+ l10n.get('confirmExit'),
|
|
|
+ l10n.get('unsavedContentWarning'),
|
|
|
+ l10n.get('continueEditing'),
|
|
|
+ l10n.get('discardAndExit'),
|
|
|
+ () async {
|
|
|
+ try {
|
|
|
+ await ExpenseCreateController.deleteDraft();
|
|
|
+ } catch (_) {}
|
|
|
+ if (!mounted) return;
|
|
|
+ setState(() {
|
|
|
+ _selectedDeptId = '';
|
|
|
+ _selectedDeptName = '';
|
|
|
+ });
|
|
|
+ ref.read(expenseCreateProvider(widget.editId).notifier).reset();
|
|
|
+ _forcePop();
|
|
|
+ },
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ _forcePop();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void _forcePop() {
|
|
|
+ _isPoppingToNative = true;
|
|
|
+ SystemNavigator.pop();
|
|
|
+ }
|
|
|
+
|
|
|
+ void _showConfirmDialog(
|
|
|
+ String title, String content, String leftText, String rightText, VoidCallback onConfirm,
|
|
|
+ ) {
|
|
|
+ FocusScope.of(context).unfocus();
|
|
|
+ final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
+ showDialog(
|
|
|
+ context: context,
|
|
|
+ useRootNavigator: true,
|
|
|
+ builder: (ctx) => TDAlertDialog(
|
|
|
+ title: title,
|
|
|
+ content: content,
|
|
|
+ buttonStyle: TDDialogButtonStyle.text,
|
|
|
+ leftBtn: TDDialogButtonOptions(
|
|
|
+ title: leftText, titleColor: colors.primary, action: () => Navigator.pop(ctx),
|
|
|
+ ),
|
|
|
+ rightBtn: TDDialogButtonOptions(
|
|
|
+ title: rightText, titleColor: colors.danger, action: () { Navigator.pop(ctx); onConfirm(); },
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
String _today() { final n = DateTime.now(); return '${n.year}-${n.month.toString().padLeft(2, '0')}-${n.day.toString().padLeft(2, '0')}'; }
|