| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import '../../core/theme/app_colors.dart';
- import '../../core/utils/date_utils.dart' as du;
- import '../../core/utils/responsive.dart';
- import '../../shared/widgets/form_section.dart';
- import '../../shared/widgets/form_field_row.dart';
- import '../../shared/widgets/status_tag.dart';
- import 'expense_api.dart';
- import 'expense_model.dart';
- final expenseDetailProvider =
- FutureProvider.autoDispose.family<ExpenseModel, String>(
- (ref, id) async {
- return ref.read(expenseApiProvider).fetchDetail(id);
- });
- class ExpenseDetailPage extends ConsumerWidget {
- final String id;
- const ExpenseDetailPage({super.key, required this.id});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final detailAsync = ref.watch(expenseDetailProvider(id));
- final r = ResponsiveHelper.of(context);
- return Scaffold(
- appBar: AppBar(title: const Text('报销单详情')),
- body: detailAsync.when(
- loading: () =>
- const Center(child: CircularProgressIndicator()),
- error: (_, __) => const Center(child: Text('加载失败')),
- data: (expense) => Center(
- child: ConstrainedBox(
- constraints:
- BoxConstraints(maxWidth: r.detailTwoColumns ? 700 : double.infinity),
- child: SingleChildScrollView(
- padding: const EdgeInsets.symmetric(vertical: 8),
- child: Column(
- children: [
- FormSection(
- title: '基本信息',
- children: [
- FormFieldRow(
- label: '单号',
- value: expense.reportNo,
- showArrow: false),
- FormFieldRow(
- label: '报销类型',
- value: expense.expenseType,
- showArrow: false),
- FormFieldRow(
- label: '报销金额',
- value: '¥${expense.totalAmount.toStringAsFixed(2)}',
- showArrow: false),
- FormFieldRow(
- label: '部门',
- value: expense.deptName,
- showArrow: false),
- FormFieldRow(
- label: '申请人',
- value: expense.applicantName,
- showArrow: false),
- FormFieldRow(
- label: '创建时间',
- value: du.DateUtils.formatDateTime(
- expense.createTime),
- showArrow: false),
- FormFieldRow(
- label: '状态',
- value: '',
- showArrow: false,
- onTap: null,
- ), // 状态用 StatusTag
- 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))),
- StatusTag(status: expense.status),
- ],
- ),
- ),
- FormFieldRow(
- label: '备注',
- value: expense.remark.isEmpty
- ? '-'
- : expense.remark,
- showArrow: false),
- ],
- ),
- FormSection(
- title: '报销明细',
- children: expense.details.isEmpty
- ? [
- const Padding(
- padding: EdgeInsets.all(14),
- child: Text('无明细',
- style: TextStyle(
- color: AppColors.textHint,
- fontSize: 13)),
- )
- ]
- : expense.details
- .map((d) => Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 14, vertical: 8),
- child: Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: [
- Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: [
- Text(d.expenseDesc,
- style: const TextStyle(
- fontSize: 13,
- color: AppColors
- .textPrimary)),
- Text(d.invoiceNo,
- style: const TextStyle(
- fontSize: 10,
- color: AppColors
- .textHint)),
- ],
- ),
- Text(
- '¥${d.totalAmount.toStringAsFixed(2)}',
- style: const TextStyle(
- color: AppColors.primary,
- fontSize: 14)),
- ],
- ),
- ))
- .toList(),
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|