| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- import 'package:tdesign_flutter/tdesign_flutter.dart';
- import 'package:dio/dio.dart';
- import '../../core/i18n/app_localizations.dart';
- import '../../core/network/api_exception.dart';
- import '../../core/navigation/host_app_channel.dart';
- import '../../core/theme/app_colors.dart';
- import '../../core/theme/app_colors_extension.dart';
- import '../../shared/widgets/action_bar.dart';
- import '../../shared/widgets/app_skeletons.dart';
- import '../../shared/widgets/form_field_row.dart';
- import '../../shared/widgets/form_section.dart';
- import '../../shared/widgets/loading_dialog.dart';
- import '../../shared/widgets/nav_bar_config.dart';
- import '../../shared/widgets/app_input_dialog.dart';
- import '../../shared/widgets/searchable_picker_sheet.dart';
- import 'vehicle_apply_api.dart';
- import 'vehicle_apply_list_controller.dart';
- import 'vehicle_apply_model.dart';
- class VehicleApplyEditPage extends ConsumerStatefulWidget {
- final String billNo;
- const VehicleApplyEditPage({super.key, required this.billNo});
- @override
- ConsumerState<VehicleApplyEditPage> createState() =>
- _VehicleApplyEditPageState();
- }
- class _VehicleApplyEditPageState extends ConsumerState<VehicleApplyEditPage> {
- // ── 原单数据 ──
- String _billNo = '';
- String _applyDate = '';
- // ── 基本信息 ──
- final _reasonController = TextEditingController();
- final _reasonFocus = FocusNode();
- String _originAdr = '';
- String _destAdr = '';
- DateTime? _startTime;
- DateTime? _endTime;
- // ── 车辆信息 ──
- String _licensePlate = '';
- String _vehicleType = '';
- String _brand = '';
- int _seats = 0;
- int _odometerBegin = 0;
- // ── 驾驶员 ──
- String _driverName = '';
- // ── 同行信息 ──
- int _passengerCount = 1;
- String _passengerName = '';
- // ── 参考数据 ──
- bool _firstBuild = true;
- bool _refDataLoading = true;
- bool _loadingBill = true;
- String? _loadingError;
- String _selectedDeptId = '';
- String _selectedDeptName = '';
- final _scrollCtrl = ScrollController();
- // Mock 车牌
- static const _mockLicensePlates = [
- '粤B12345',
- '京A88888',
- '京B66666',
- '京C12345',
- '京D99999',
- ];
- // Mock 车辆类型
- static const _mockVehicleTypes = ['sedan', 'suv', 'mpv', 'van', 'truck', 'pickup', 'minibus', 'bus'];
- @override
- void initState() {
- super.initState();
- SystemChrome.setSystemUIOverlayStyle(
- const SystemUiOverlayStyle(
- statusBarColor: Colors.transparent,
- statusBarIconBrightness: Brightness.dark,
- ),
- );
- _reasonFocus.addListener(() => _ensureVisible(_reasonFocus));
- _refDataLoading = true;
- _loadingBill = true;
- _loadRefData();
- _loadBillData();
- WidgetsBinding.instance.addPostFrameCallback((_) => _checkDataReady());
- }
- void _checkDataReady() {
- if (!_refDataLoading && !_loadingBill && mounted) {
- setState(() => _firstBuild = false);
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) setState(() {});
- });
- } else if (mounted) {
- WidgetsBinding.instance.addPostFrameCallback((_) => _checkDataReady());
- }
- }
- Future<void>? _refDataFuture;
- Future<void> _loadRefData({bool showLoading = false}) async {
- if (_refDataFuture != null) return _refDataFuture!;
- final completer = Completer<void>();
- _refDataFuture = completer.future;
- if (showLoading) {
- LoadingDialog.show(
- context,
- text: AppLocalizations.of(context).get('dataLoading'),
- );
- }
- try {
- final api = ref.read(vehicleApplyApiProvider);
- await Future.wait([api.getDepartments()]);
- if (!mounted) return;
- setState(() => _refDataLoading = false);
- completer.complete();
- } catch (_) {
- if (!mounted) {
- completer.complete();
- return;
- }
- setState(() => _refDataLoading = false);
- completer.complete();
- } finally {
- if (showLoading && mounted) LoadingDialog.hide(context);
- _refDataFuture = null;
- }
- }
- Future<void> _loadBillData() async {
- try {
- // 先用 mock 数据匹配
- final match = mockVehicles.where((e) => e.ycNo == widget.billNo);
- if (match.isNotEmpty) {
- _fillFromModel(match.first);
- if (mounted) setState(() => _loadingBill = false);
- return;
- }
- // 尝试 API
- final api = ref.read(vehicleApplyApiProvider);
- final detail = await api.fetchDetail(widget.billNo);
- if (!mounted) return;
- _fillFromModel(detail);
- setState(() => _loadingBill = false);
- } catch (e) {
- if (!mounted) return;
- setState(() {
- _loadingBill = false;
- _loadingError = e.toString();
- });
- }
- }
- void _fillFromModel(VehicleApplyModel model) {
- _billNo = model.ycNo;
- _applyDate = model.ycDd != null
- ? '${model.ycDd!.year}-${model.ycDd!.month.toString().padLeft(2, '0')}-${model.ycDd!.day.toString().padLeft(2, '0')}'
- : '';
- _selectedDeptId = model.dep;
- _selectedDeptName = model.deptName;
- _reasonController.text = model.reason;
- _originAdr = model.originAdr;
- _destAdr = model.destAdr;
- _startTime = model.startTime;
- _endTime = model.endTime;
- _licensePlate = model.licensePlate;
- _vehicleType = model.vehicleType;
- _brand = model.brand;
- _seats = model.seats;
- _odometerBegin = model.odometerBegin;
- _driverName = model.driverName;
- _passengerCount = model.passengerCount;
- _passengerName = model.passengerName;
- }
- 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() {
- _reasonController.dispose();
- _reasonFocus.dispose();
- _scrollCtrl.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- final l10n = AppLocalizations.of(context);
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
- if (_loadingError != null) {
- return Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(Icons.error_outline, size: 48, color: colors.danger),
- const SizedBox(height: 16),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 32),
- child: Text(
- _loadingError!,
- textAlign: TextAlign.center,
- style: TextStyle(
- fontSize: AppFontSizes.body,
- color: colors.textSecondary,
- ),
- ),
- ),
- const SizedBox(height: 16),
- TDButton(
- text: l10n.get('retry'),
- size: TDButtonSize.medium,
- onTap: () {
- setState(() {
- _loadingError = null;
- _loadingBill = true;
- });
- _loadBillData();
- },
- ),
- ],
- ),
- );
- }
- if (_firstBuild) {
- return const SkeletonFormPage();
- }
- Future.microtask(
- () => ref.read(pageBackProvider.notifier).state = () => _doPop(),
- );
- return PopScope(
- canPop: false,
- onPopInvokedWithResult: (didPop, _) {
- if (didPop) return;
- _doPop();
- },
- child: Column(
- children: [
- Expanded(
- child: GestureDetector(
- onTap: () => FocusScope.of(context).unfocus(),
- child: SingleChildScrollView(
- controller: _scrollCtrl,
- padding: const EdgeInsets.all(16),
- child: Column(
- children: [
- _buildBasicInfo(l10n),
- const SizedBox(height: 16),
- _buildVehicleInfo(l10n),
- const SizedBox(height: 16),
- _buildPassengerInfo(l10n),
- const SizedBox(height: 24),
- _buildPageFooter(),
- ],
- ),
- ),
- ),
- ),
- _buildBottomBar(l10n),
- ],
- ),
- );
- }
- // ═══ 1. 基本信息 ═══
- Widget _buildBasicInfo(AppLocalizations l10n) {
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
- return FormSection(
- title: l10n.get('basicInfo'),
- leadingIcon: Icons.info_outline,
- children: [
- FormFieldRow(
- label: l10n.get('vehicleApplyNo'),
- value: _billNo,
- readOnly: true,
- showArrow: false,
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('date'),
- value: _applyDate,
- readOnly: true,
- showArrow: false,
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('applyDept'),
- value: _selectedDeptId.isNotEmpty
- ? '$_selectedDeptId/$_selectedDeptName'
- : '',
- hint: l10n.get('pleaseSelect'),
- onTap: () => _showDeptPicker(),
- ),
- const SizedBox(height: 16),
- _label(l10n.get('vehicleReason'), required: true),
- const SizedBox(height: 8),
- TDTextarea(
- controller: _reasonController,
- focusNode: _reasonFocus,
- hintText: l10n.get('enterVehicleReason'),
- maxLines: 4,
- minLines: 1,
- maxLength: 500,
- indicator: true,
- padding: EdgeInsets.zero,
- bordered: true,
- backgroundColor: colors.bgPage,
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('origin'),
- value: _originAdr.isNotEmpty ? _originAdr : null,
- hint: l10n.get('pleaseEnter'),
- onTap: () => _showTextInput(
- l10n.get('origin'),
- (v) => setState(() => _originAdr = v),
- initialText: _originAdr,
- ),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('destination'),
- value: _destAdr.isNotEmpty ? _destAdr : null,
- hint: l10n.get('pleaseEnter'),
- onTap: () => _showTextInput(
- l10n.get('destination'),
- (v) => setState(() => _destAdr = v),
- initialText: _destAdr,
- ),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('departTime'),
- value: _startTime != null ? _formatDateTime(_startTime!) : null,
- hint: l10n.get('pleaseSelect'),
- onTap: () =>
- _pickDateTime((d) => setState(() => _startTime = d), _startTime),
- onClear: _startTime != null
- ? () => setState(() => _startTime = null)
- : null,
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('returnTime'),
- value: _endTime != null ? _formatDateTime(_endTime!) : null,
- hint: l10n.get('pleaseSelect'),
- onTap: () =>
- _pickDateTime((d) => setState(() => _endTime = d), _endTime),
- onClear: _endTime != null
- ? () => setState(() => _endTime = null)
- : null,
- ),
- if (_startTime != null &&
- _endTime != null &&
- !_endTime!.isAfter(_startTime!))
- Padding(
- padding: const EdgeInsets.only(top: 8),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- Icon(Icons.warning_amber_rounded,
- size: 14, color: colors.danger),
- const SizedBox(width: 4),
- Text(
- l10n.get('returnTimeMustLater'),
- style: TextStyle(
- fontSize: AppFontSizes.caption,
- color: colors.danger,
- ),
- ),
- ],
- ),
- ),
- ],
- );
- }
- // ═══ 2. 车辆信息 ═══
- Widget _buildVehicleInfo(AppLocalizations l10n) {
- return FormSection(
- title: l10n.get('vehicleInfo'),
- leadingIcon: Icons.directions_car_outlined,
- children: [
- FormFieldRow(
- label: l10n.get('licensePlate'),
- value: _licensePlate.isNotEmpty ? _licensePlate : null,
- hint: l10n.get('pleaseSelect'),
- onTap: () => _showLicensePlatePicker(),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('vehicleType'),
- value: _vehicleType.isNotEmpty
- ? _vehicleTypeLabel(_vehicleType, l10n)
- : null,
- hint: l10n.get('pleaseSelect'),
- onTap: () => _showVehicleTypePicker(l10n),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('brand'),
- value: _brand.isNotEmpty ? _brand : null,
- hint: l10n.get('pleaseEnter'),
- onTap: () => _showTextInput(
- l10n.get('brand'),
- (v) => setState(() => _brand = v),
- initialText: _brand,
- ),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('seats'),
- value: _seats > 0 ? '$_seats' : null,
- hint: l10n.get('pleaseEnter'),
- onTap: () => _showNumberInput(
- l10n.get('seats'),
- (v) => setState(() => _seats = v),
- _seats,
- ),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('odometerBegin'),
- value: _odometerBegin > 0 ? '$_odometerBegin' : null,
- hint: l10n.get('pleaseEnter'),
- onTap: () => _showNumberInput(
- l10n.get('odometerBegin'),
- (v) => setState(() => _odometerBegin = v),
- _odometerBegin,
- ),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('driverName'),
- value: _driverName.isNotEmpty ? _driverName : null,
- hint: l10n.get('pleaseSelect'),
- onTap: () => _showDriverPicker(),
- ),
- ],
- );
- }
- // ═══ 3. 同行信息 ═══
- Widget _buildPassengerInfo(AppLocalizations l10n) {
- return FormSection(
- title: l10n.get('companionInfo'),
- leadingIcon: Icons.people_outline,
- children: [
- FormFieldRow(
- label: l10n.get('passengerCount'),
- value: '$_passengerCount',
- onTap: () => _showNumberInput(
- l10n.get('passengerCount'),
- (v) => setState(() => _passengerCount = v < 1 ? 1 : v),
- _passengerCount,
- ),
- ),
- const SizedBox(height: 16),
- FormFieldRow(
- label: l10n.get('passengerName'),
- value: _passengerName.isNotEmpty ? _passengerName : null,
- hint: l10n.get('pleaseEnter'),
- onTap: () => _showTextInput(
- l10n.get('passengerName'),
- (v) => setState(() => _passengerName = v),
- initialText: _passengerName,
- ),
- ),
- ],
- );
- }
- // ═══ 4. 底部操作栏 ═══
- Widget _buildBottomBar(AppLocalizations l10n) {
- return ActionBar(
- showLeft: false,
- showCenter: false,
- rightLabel: l10n.get('submit'),
- onRightTap: () async {
- final err = _validate(l10n);
- if (err.isNotEmpty) {
- TDToast.showText(err.first, context: context);
- return;
- }
- FocusScope.of(context).unfocus();
- LoadingDialog.show(context, text: l10n.get('submitting'));
- try {
- final data = _buildSubmitData();
- final api = ref.read(vehicleApplyApiProvider);
- await api.submit(data);
- if (mounted) {
- LoadingDialog.hide(context);
- TDToast.showSuccess(l10n.get('submitSuccess'), context: context);
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) GoRouter.of(context).pop(true);
- });
- }
- } catch (e) {
- if (mounted) {
- LoadingDialog.hide(context);
- WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted) _showSubmitError(e, l10n);
- });
- }
- }
- },
- );
- }
- void _showSubmitError(Object e, AppLocalizations l10n) {
- final message = _extractErrorMessage(e) ?? l10n.get('submitFailedRetry');
- showGeneralDialog(
- context: context,
- pageBuilder: (ctx, animation, secondaryAnimation) => TDConfirmDialog(
- title: l10n.get('submitFailed'),
- content: message,
- buttonStyle: TDDialogButtonStyle.text,
- ),
- );
- }
- String? _extractErrorMessage(Object e) {
- if (e is DioException) {
- if (e.error is ApiException) return (e.error as ApiException).message;
- if (e.error is NetworkException) {
- return (e.error as NetworkException).message;
- }
- }
- return null;
- }
- Map<String, dynamic> _buildSubmitData() {
- return {
- 'HeadData': {
- 'YC_NO': _billNo,
- 'YC_DD': _applyDate,
- 'SAL_NO': HostAppChannel.usr,
- 'DEP': _selectedDeptId,
- 'REASON': _reasonController.text.trim(),
- 'ORIGIN_ADR': _originAdr,
- 'DEST_ADR': _destAdr,
- 'PASSENGER_COUNT': _passengerCount,
- 'PASSENGER_NAME': _passengerName,
- 'LICENSEPLATE': _licensePlate,
- 'VEHICLE_TYPE': _vehicleType,
- 'BRAND': _brand,
- 'ODOMETER_BEGIN': _odometerBegin,
- 'SEATS': _seats,
- 'DRIVER_NAME': _driverName,
- 'START_TIME': _startTime?.toIso8601String(),
- 'END_TIME': _endTime?.toIso8601String(),
- 'USR': HostAppChannel.usr,
- },
- };
- }
- List<String> _validate(AppLocalizations l10n) {
- final e = <String>[];
- if (_reasonController.text.trim().isEmpty) {
- e.add(l10n.get('enterVehicleReason'));
- }
- if (_licensePlate.isEmpty) e.add(l10n.get('selectLicensePlateHint'));
- if (_startTime != null &&
- _endTime != null &&
- !_endTime!.isAfter(_startTime!)) {
- e.add(l10n.get('returnTimeMustLater'));
- }
- return e;
- }
- // ═══ 弹窗方法 ═══
- Future<void> _showTextInput(
- String title,
- void Function(String) onConfirm, {
- String initialText = '',
- }) async {
- FocusScope.of(context).unfocus();
- FocusManager.instance.primaryFocus?.unfocus();
- final result = await AppInputDialog.show(
- context: context,
- title: title,
- initialText: initialText,
- );
- if (result != null && mounted) {
- onConfirm(result);
- }
- }
- Future<void> _showNumberInput(String title, void Function(int) onSave, int current) async {
- FocusScope.of(context).unfocus();
- FocusManager.instance.primaryFocus?.unfocus();
- final result = await AppInputDialog.show(
- context: context,
- title: title,
- initialText: current > 0 ? '$current' : '',
- inputType: AppInputType.integer,
- min: 0,
- );
- if (result != null && mounted) {
- onSave(int.tryParse(result) ?? 0);
- }
- }
- void _pickDateTime(void Function(DateTime) onPicked, DateTime? initial) {
- FocusScope.of(context).unfocus();
- final l10n = AppLocalizations.of(context);
- final now = DateTime.now();
- final d = initial ?? now;
- TDPicker.showDatePicker(
- context,
- title: l10n.get('selectDateTime'),
- useYear: true,
- useMonth: true,
- useDay: true,
- useHour: true,
- useMinute: true,
- dateStart: [now.year - 1, now.month, now.day, now.hour, now.minute],
- dateEnd: [now.year + 10, 12, 31, 23, 59],
- initialDate: [d.year, d.month, d.day, d.hour, d.minute],
- onConfirm: (selected) {
- Navigator.of(context).pop();
- onPicked(
- DateTime(
- selected['year']!,
- selected['month']!,
- selected['day']!,
- selected['hour']!,
- selected['minute']!,
- ),
- );
- },
- );
- }
- Future<void> _showDeptPicker() async {
- FocusManager.instance.primaryFocus?.unfocus();
- final l10n = AppLocalizations.of(context);
- final api = ref.read(vehicleApplyApiProvider);
- final result = await showSearchablePicker<DepartmentItem>(
- context,
- title: '${l10n.get('select')}${l10n.get('applyDept')}',
- searchHint: l10n.get('search'),
- loader: (keyword, page) =>
- api.getDepartments(keyword: keyword, page: page, size: 20),
- labelBuilder: (d) => d.name.isEmpty ? d.dep : '${d.dep} ${d.name}',
- );
- if (result != null && mounted) {
- setState(() {
- _selectedDeptId = result.dep;
- _selectedDeptName = result.name;
- });
- }
- }
- void _showLicensePlatePicker() {
- FocusScope.of(context).unfocus();
- final l10n = AppLocalizations.of(context);
- TDPicker.showMultiPicker(
- context,
- title: l10n.get('selectLicensePlate'),
- data: [_mockLicensePlates],
- onConfirm: (selected) => setState(() => _licensePlate = selected.first),
- );
- }
- void _showVehicleTypePicker(AppLocalizations l10n) {
- FocusScope.of(context).unfocus();
- final labels = _mockVehicleTypes
- .map((t) => _vehicleTypeLabel(t, l10n))
- .toList();
- TDPicker.showMultiPicker(
- context,
- title: l10n.get('selectVehicleType'),
- data: [labels],
- onConfirm: (selected) {
- final idx = labels.indexOf(selected.first);
- if (idx >= 0) setState(() => _vehicleType = _mockVehicleTypes[idx]);
- },
- );
- }
- Future<void> _showDriverPicker() async {
- FocusManager.instance.primaryFocus?.unfocus();
- final l10n = AppLocalizations.of(context);
- final api = ref.read(vehicleApplyApiProvider);
- final result = await showSearchablePicker<EmployeeItem>(
- context,
- title: '${l10n.get('select')}${l10n.get('driverName')}',
- searchHint: l10n.get('search'),
- loader: (keyword, page) =>
- api.getEmployees(keyword: keyword, page: page, size: 20),
- labelBuilder: (e) => e.name.isEmpty ? e.salNo : '${e.salNo} ${e.name}',
- );
- if (result != null && mounted) {
- setState(() {
- _driverName = result.name;
- });
- }
- }
- // ═══ 对话框 ═══
- void _doPop() {
- if (_hasUnsaved()) {
- final l10n = AppLocalizations.of(context);
- _showConfirmDialog(
- l10n.get('confirmExit'),
- l10n.get('unsavedContentWarning'),
- l10n.get('continueEditing'),
- l10n.get('discardAndExit'),
- _forcePop,
- );
- } else {
- _forcePop();
- }
- }
- void _forcePop() {
- FocusManager.instance.primaryFocus?.unfocus();
- final router = GoRouter.of(context);
- if (router.canPop()) {
- router.pop();
- } else {
- SystemNavigator.pop();
- }
- }
- bool _hasUnsaved() =>
- _reasonController.text.isNotEmpty ||
- _originAdr.isNotEmpty ||
- _destAdr.isNotEmpty ||
- _licensePlate.isNotEmpty ||
- _vehicleType.isNotEmpty ||
- _brand.isNotEmpty ||
- _driverName.isNotEmpty ||
- _passengerName.isNotEmpty ||
- _passengerCount != 1 ||
- _odometerBegin > 0;
- void _showConfirmDialog(
- String title,
- String content,
- String leftText,
- String rightText,
- VoidCallback onConfirm,
- ) {
- FocusScope.of(context).unfocus();
- FocusManager.instance.primaryFocus?.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();
- },
- ),
- ),
- );
- }
- // ═══ 工具方法 ═══
- Widget _label(String t, {bool required = false}) {
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
- 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,
- ),
- ),
- ],
- ),
- );
- }
- Widget _buildPageFooter() {
- final l10n = AppLocalizations.of(context);
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
- return Center(
- child: Padding(
- padding: const EdgeInsets.only(bottom: 16),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(
- Icons.rocket_launch_outlined,
- size: 16,
- color: colors.textPlaceholder,
- ),
- const SizedBox(width: 6),
- Text(
- l10n.get('pageFooter'),
- style: TextStyle(
- fontSize: AppFontSizes.caption,
- color: colors.textPlaceholder,
- ),
- ),
- ],
- ),
- ),
- );
- }
- String _formatDateTime(DateTime d) {
- return '${d.year}-${d.month.toString().padLeft(2, '0')}-${d.day.toString().padLeft(2, '0')} ${d.hour.toString().padLeft(2, '0')}:${d.minute.toString().padLeft(2, '0')}';
- }
- String _vehicleTypeLabel(String key, AppLocalizations l10n) {
- switch (key) {
- case 'sedan':
- return l10n.get('sedan');
- case 'suv':
- return 'SUV';
- case 'mpv':
- return l10n.get('businessVan');
- case 'van':
- return l10n.get('van');
- case 'truck':
- return l10n.get('truck');
- case 'pickup':
- return l10n.get('pickup');
- case 'minibus':
- return l10n.get('minibus');
- case 'bus':
- return l10n.get('bus');
- default:
- return key;
- }
- }
- }
|