vehicle_detail_page.dart 4.2 KB

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