vehicle_detail_page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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/models/approval_status.dart';
  7. import '../../shared/widgets/form_section.dart';
  8. import '../../shared/widgets/form_field_row.dart';
  9. import '../../shared/widgets/status_tag.dart';
  10. import 'vehicle_model.dart';
  11. final vehicleDetailProvider = FutureProvider.autoDispose.family<VehicleModel, String>((ref, id) async {
  12. return VehicleModel(
  13. id: id,
  14. applicationNo: 'VH202605001',
  15. applicantId: 'u-001',
  16. applicantName: '张三',
  17. deptId: 'dept-001',
  18. deptName: '市场部',
  19. vehicleType: '轿车',
  20. purpose: '客户拜访',
  21. startTime: DateTime(2026, 5, 22, 8, 0),
  22. endTime: DateTime(2026, 5, 22, 18, 0),
  23. origin: '公司总部',
  24. destination: '深圳分公司',
  25. passengerCount: 3,
  26. driver: '刘师傅',
  27. licensePlate: '京A·88888',
  28. estimatedMileage: 120.0,
  29. estimatedCost: 500.0,
  30. reason: '拜访重要客户,需前往深圳',
  31. status: 'pending',
  32. createTime: DateTime(2026, 5, 20),
  33. updateTime: DateTime(2026, 5, 20),
  34. approvalRecords: [
  35. ApprovalRecord(
  36. id: 'ar-vh-001',
  37. bizId: id,
  38. bizType: 'vehicle',
  39. approverId: 'u-mgr',
  40. approverName: '李四',
  41. approvalLevel: 1,
  42. action: 'pending',
  43. opinion: '',
  44. approvalTime: DateTime(2026, 5, 20),
  45. ),
  46. ],
  47. );
  48. });
  49. class VehicleDetailPage extends ConsumerWidget {
  50. final String id;
  51. const VehicleDetailPage({super.key, required this.id});
  52. @override
  53. Widget build(BuildContext context, WidgetRef ref) {
  54. final detailAsync = ref.watch(vehicleDetailProvider(id));
  55. final r = ResponsiveHelper.of(context);
  56. return Scaffold(
  57. appBar: AppBar(title: const Text('用车详情')),
  58. body: detailAsync.when(
  59. loading: () => const Center(child: CircularProgressIndicator()),
  60. error: (_, __) => const Center(child: Text('加载失败')),
  61. data: (v) => Align(alignment: Alignment.topCenter,
  62. child: ConstrainedBox(
  63. constraints: BoxConstraints(maxWidth: r.detailTwoColumns ? 700 : double.infinity),
  64. child: SingleChildScrollView(
  65. padding: const EdgeInsets.symmetric(vertical: 8),
  66. child: FormSection(
  67. title: '用车信息',
  68. children: [
  69. FormFieldRow(label: '申请单号', value: v.applicationNo, showArrow: false),
  70. FormFieldRow(label: '用车目的', value: v.purpose, showArrow: false),
  71. FormFieldRow(label: '车型', value: v.vehicleType, showArrow: false),
  72. FormFieldRow(label: '开始时间', value: du.DateUtils.formatDateTime(v.startTime), showArrow: false),
  73. FormFieldRow(label: '结束时间', value: du.DateUtils.formatDateTime(v.endTime), showArrow: false),
  74. FormFieldRow(label: '出发地', value: v.origin, showArrow: false),
  75. FormFieldRow(label: '目的地', value: v.destination, showArrow: false),
  76. FormFieldRow(label: '乘车人数', value: '${v.passengerCount}人', showArrow: false),
  77. FormFieldRow(label: '驾驶员', value: v.driver.isEmpty ? '-' : v.driver, showArrow: false),
  78. FormFieldRow(label: '部门', value: v.deptName, showArrow: false),
  79. FormFieldRow(label: '申请人', value: v.applicantName, showArrow: false),
  80. Padding(
  81. padding: const EdgeInsets.fromLTRB(14, 0, 14, 12),
  82. child: Row(
  83. children: [
  84. const SizedBox(width: 72, child: Text('状态', style: TextStyle(color: AppColors.textSecondary, fontSize: 13))),
  85. StatusTag(status: v.status),
  86. ],
  87. ),
  88. ),
  89. FormFieldRow(label: '用车事由', value: v.reason.isEmpty ? '-' : v.reason, showArrow: false),
  90. ],
  91. ),
  92. ),
  93. ),
  94. ),
  95. ),
  96. );
  97. }
  98. }