| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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 'vehicle_api.dart';
- import 'vehicle_model.dart';
- final vehicleDetailProvider = FutureProvider.autoDispose.family<VehicleModel, String>((ref, id) async {
- return ref.read(vehicleApiProvider).fetchDetail(id);
- });
- class VehicleDetailPage extends ConsumerWidget {
- final String id;
- const VehicleDetailPage({super.key, required this.id});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final detailAsync = ref.watch(vehicleDetailProvider(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: (v) => Center(
- child: ConstrainedBox(
- constraints: BoxConstraints(maxWidth: r.detailTwoColumns ? 700 : double.infinity),
- child: SingleChildScrollView(
- padding: const EdgeInsets.symmetric(vertical: 8),
- child: FormSection(
- title: '用车信息',
- children: [
- FormFieldRow(label: '申请单号', value: v.applicationNo, showArrow: false),
- FormFieldRow(label: '用车目的', value: v.purpose, showArrow: false),
- FormFieldRow(label: '车型', value: v.vehicleType, showArrow: false),
- FormFieldRow(label: '开始时间', value: du.DateUtils.formatDateTime(v.startTime), showArrow: false),
- FormFieldRow(label: '结束时间', value: du.DateUtils.formatDateTime(v.endTime), showArrow: false),
- FormFieldRow(label: '出发地', value: v.origin, showArrow: false),
- FormFieldRow(label: '目的地', value: v.destination, showArrow: false),
- FormFieldRow(label: '乘车人数', value: '${v.passengerCount}人', showArrow: false),
- FormFieldRow(label: '驾驶员', value: v.driver.isEmpty ? '-' : v.driver, showArrow: false),
- FormFieldRow(label: '部门', value: v.deptName, showArrow: false),
- FormFieldRow(label: '申请人', value: v.applicantName, showArrow: false),
- 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: v.status),
- ],
- ),
- ),
- FormFieldRow(label: '用车事由', value: v.reason.isEmpty ? '-' : v.reason, showArrow: false),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|