vehicle_detail_page.dart 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import '../../core/theme/app_colors.dart';
  4. import '../../core/utils/date_utils.dart' as du;
  5. import '../../core/utils/responsive.dart';
  6. import '../../shared/widgets/form_section.dart';
  7. import '../../shared/widgets/form_field_row.dart';
  8. import '../../shared/widgets/status_tag.dart';
  9. import 'vehicle_api.dart';
  10. import 'vehicle_model.dart';
  11. final vehicleDetailProvider = FutureProvider.autoDispose.family<VehicleModel, String>((ref, id) async {
  12. return ref.read(vehicleApiProvider).fetchDetail(id);
  13. });
  14. class VehicleDetailPage extends ConsumerWidget {
  15. final String id;
  16. const VehicleDetailPage({super.key, required this.id});
  17. @override
  18. Widget build(BuildContext context, WidgetRef ref) {
  19. final detailAsync = ref.watch(vehicleDetailProvider(id));
  20. final r = ResponsiveHelper.of(context);
  21. return Scaffold(
  22. appBar: AppBar(title: const Text('用车详情')),
  23. body: detailAsync.when(
  24. loading: () => const Center(child: CircularProgressIndicator()),
  25. error: (_, __) => const Center(child: Text('加载失败')),
  26. data: (v) => Center(
  27. child: ConstrainedBox(
  28. constraints: BoxConstraints(maxWidth: r.detailTwoColumns ? 700 : double.infinity),
  29. child: SingleChildScrollView(
  30. padding: const EdgeInsets.symmetric(vertical: 8),
  31. child: FormSection(
  32. title: '用车信息',
  33. children: [
  34. FormFieldRow(label: '申请单号', value: v.applicationNo, showArrow: false),
  35. FormFieldRow(label: '用车目的', value: v.purpose, showArrow: false),
  36. FormFieldRow(label: '车型', value: v.vehicleType, showArrow: false),
  37. FormFieldRow(label: '开始时间', value: du.DateUtils.formatDateTime(v.startTime), showArrow: false),
  38. FormFieldRow(label: '结束时间', value: du.DateUtils.formatDateTime(v.endTime), showArrow: false),
  39. FormFieldRow(label: '出发地', value: v.origin, showArrow: false),
  40. FormFieldRow(label: '目的地', value: v.destination, showArrow: false),
  41. FormFieldRow(label: '乘车人数', value: '${v.passengerCount}人', showArrow: false),
  42. FormFieldRow(label: '驾驶员', value: v.driver.isEmpty ? '-' : v.driver, showArrow: false),
  43. FormFieldRow(label: '部门', value: v.deptName, showArrow: false),
  44. FormFieldRow(label: '申请人', value: v.applicantName, showArrow: false),
  45. Padding(
  46. padding: const EdgeInsets.fromLTRB(14, 0, 14, 12),
  47. child: Row(
  48. children: [
  49. const SizedBox(width: 72, child: Text('状态', style: TextStyle(color: AppColors.textSecondary, fontSize: 13))),
  50. StatusTag(status: v.status),
  51. ],
  52. ),
  53. ),
  54. FormFieldRow(label: '用车事由', value: v.reason.isEmpty ? '-' : v.reason, showArrow: false),
  55. ],
  56. ),
  57. ),
  58. ),
  59. ),
  60. ),
  61. );
  62. }
  63. }