import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:tdesign_flutter/tdesign_flutter.dart'; import '../../core/theme/app_colors.dart'; import '../../core/utils/responsive.dart'; import '../../shared/widgets/form_section.dart'; import '../../shared/widgets/form_field_row.dart'; class ExpenseApplicationApplyPage extends ConsumerStatefulWidget { final String? id; const ExpenseApplicationApplyPage({super.key, this.id}); @override ConsumerState createState() => _ExpenseApplicationApplyPageState(); } class _ExpenseApplicationApplyPageState extends ConsumerState { final _formKey = GlobalKey(); String _expenseType = '差旅费'; final _amountController = TextEditingController(); final _purposeController = TextEditingController(); final _remarkController = TextEditingController(); static const _types = ['差旅费', '办公用品', '招待费', '交通费', '通讯费', '其他']; @override void dispose() { _amountController.dispose(); _purposeController.dispose(); _remarkController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final r = ResponsiveHelper.of(context); return Scaffold( appBar: TDNavBar( title: '报销申请', titleColor: Colors.white, backgroundColor: const Color(0xFF00ABF3), centerTitle: false, ), body: Column( children: [ Expanded( child: Align(alignment: Alignment.topCenter, child: ConstrainedBox( constraints: BoxConstraints(maxWidth: r.formMaxWidth), child: SingleChildScrollView( padding: const EdgeInsets.symmetric(vertical: 8), child: Form( key: _formKey, child: _buildForm(), ), ), ), ), ), _buildBottomButtons(), ], ), ); } Widget _buildForm() { return FormSection( title: '基本信息', children: [ FormFieldRow( label: '费用类型', value: _expenseType, onTap: _showTypePicker, ), Padding( padding: const EdgeInsets.fromLTRB(14, 0, 14, 12), child: Row( children: [ const SizedBox( width: 72, child: Text('预计金额', style: TextStyle( color: AppColors.textSecondary, fontSize: 13)), ), const SizedBox(width: 8), Expanded( child: TextFormField( controller: _amountController, keyboardType: const TextInputType.numberWithOptions(decimal: true), decoration: const InputDecoration( hintText: '请输入金额', border: OutlineInputBorder(), contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), isDense: true, ), validator: (value) { if (value == null || value.isEmpty) { return '请输入预计金额'; } if (double.tryParse(value) == null) { return '请输入有效数字'; } return null; }, ), ), ], ), ), Padding( padding: const EdgeInsets.fromLTRB(14, 0, 14, 12), child: Row( children: [ const SizedBox( width: 72, child: Text('用途说明', style: TextStyle( color: AppColors.textSecondary, fontSize: 13)), ), const SizedBox(width: 8), Expanded( child: TextFormField( controller: _purposeController, maxLines: 2, decoration: const InputDecoration( hintText: '请输入用途说明', border: OutlineInputBorder(), contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 8), isDense: true, ), validator: (value) { if (value == null || value.isEmpty) { return '请输入用途说明'; } return null; }, ), ), ], ), ), FormFieldRow( label: '备注', value: _remarkController.text.isEmpty ? null : _remarkController.text, hint: '选填', onTap: _showRemarkEditor, ), ], ); } Widget _buildBottomButtons() { return Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withValues(alpha: 0.05), blurRadius: 4, offset: const Offset(0, -1), ), ], ), child: Row( children: [ Expanded( child: TDButton( text: '存草稿', type: TDButtonType.outline, theme: TDButtonTheme.primary, size: TDButtonSize.medium, onTap: _handleSaveDraft, ), ), const SizedBox(width: 12), Expanded( flex: 2, child: TDButton( text: '提交申请', type: TDButtonType.fill, theme: TDButtonTheme.primary, size: TDButtonSize.medium, onTap: _handleSubmit, ), ), ], ), ); } void _showTypePicker() { showModalBottomSheet( context: context, builder: (_) => Column( mainAxisSize: MainAxisSize.min, children: _types .map((t) => ListTile( title: Text(t), onTap: () { setState(() => _expenseType = t); Navigator.pop(context); }, )) .toList(), ), ); } void _showRemarkEditor() { showGeneralDialog( context: context, pageBuilder: (_, __, ___) => TDAlertDialog( title: '备注', contentWidget: TextField( controller: _remarkController, maxLines: 3, decoration: const InputDecoration( hintText: '请输入备注信息…', border: OutlineInputBorder()), ), leftBtn: TDDialogButtonOptions( title: '取消', action: () => Navigator.pop(context), ), rightBtn: TDDialogButtonOptions( title: '确定', theme: TDButtonTheme.primary, action: () { setState(() {}); Navigator.pop(context); }, ), ), ); } void _handleSaveDraft() { if (!_formKey.currentState!.validate()) return; ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('草稿已保存')), ); context.pop(); } void _handleSubmit() { if (!_formKey.currentState!.validate()) return; ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('提交成功')), ); context.pop(); } }