| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- import 'package:tdesign_flutter/tdesign_flutter.dart';
- import '../../core/theme/app_colors.dart';
- import '../../core/utils/date_utils.dart' as du;
- import '../../shared/models/user_model.dart';
- import '../../shared/widgets/app_card.dart';
- import '../../shared/widgets/approval_timeline.dart';
- import '../../shared/widgets/approval_actions.dart';
- import 'vehicle_model.dart';
- import 'vehicle_list_controller.dart';
- class VehicleDetailPage extends ConsumerWidget {
- final String id;
- const VehicleDetailPage({super.key, required this.id});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final vehicle = mockVehicles.firstWhere((e) => e.id == id,
- orElse: () => mockVehicles.first);
- return Scaffold(
- appBar: TDNavBar(
- title: '用车详情',
- titleColor: Colors.white,
- backgroundColor: const Color(0xFF00ABF3),
- centerTitle: false,
- ),
- body: Column(children: [
- Expanded(
- child: SingleChildScrollView(
- padding: const EdgeInsets.all(12),
- child: Column(children: [
- _buildStatusHeader(vehicle),
- const SizedBox(height: 12),
- _buildInfoSection(vehicle),
- const SizedBox(height: 12),
- if (vehicle.approvalRecords.isNotEmpty || vehicle.approvalChain.isNotEmpty)
- AppCard(
- child: ApprovalTimeline(
- records: vehicle.approvalRecords,
- chain: vehicle.approvalChain,
- currentApproverId: vehicle.currentApproverId,
- ),
- ),
- ]),
- ),
- ),
- ApprovalActions(
- status: vehicle.status,
- userRole: UserRole.employee,
- onApprove: () {},
- onReject: () {},
- onEdit: () => context.push('/vehicle/apply?id=${vehicle.id}'),
- onWithdraw: () {},
- ),
- ]),
- );
- }
- Widget _buildStatusHeader(VehicleModel vehicle) {
- final (icon, color, text) = switch (vehicle.status) {
- 'approved' => (Icons.check_circle, AppColors.success, '已通过'),
- 'rejected' => (Icons.cancel, AppColors.error, '已拒绝'),
- 'draft' => (Icons.edit, AppColors.textHint, '草稿'),
- _ => (Icons.schedule, AppColors.warning, '待审批'),
- };
- return Container(
- padding: const EdgeInsets.all(20),
- decoration: BoxDecoration(
- color: color.withValues(alpha: 0.08),
- borderRadius: BorderRadius.circular(12)),
- child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
- Icon(icon, color: color, size: 36),
- const SizedBox(width: 10),
- Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
- Text(text, style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: color)),
- if (vehicle.status == 'pending')
- Text('当前审批人:${vehicle.currentApproverId}',
- style: const TextStyle(fontSize: 12, color: AppColors.textSecondary)),
- ]),
- ]),
- );
- }
- Widget _buildInfoSection(VehicleModel vehicle) {
- return _buildDetailCard('基本信息', [
- TDCell(title: '申请单号', note: vehicle.applicationNo, showBottomBorder: true),
- TDCell(title: '申请人', note: '${vehicle.applicantName} · ${vehicle.deptName}', showBottomBorder: true),
- TDCell(title: '车辆类型', note: vehicle.vehicleType, showBottomBorder: true),
- TDCell(title: '用车目的', note: vehicle.purpose, showBottomBorder: true),
- TDCell(title: '出发地', note: vehicle.origin, showBottomBorder: true),
- TDCell(title: '目的地', note: vehicle.destination, showBottomBorder: true),
- TDCell(title: '预计时间', note: '${du.DateUtils.formatDateTime(vehicle.startTime)} ~ ${du.DateUtils.formatDateTime(vehicle.endTime)}', showBottomBorder: true),
- TDCell(title: '乘车人数', note: '${vehicle.passengerCount}人', showBottomBorder: true),
- TDCell(title: '驾驶员', note: vehicle.driver.isEmpty ? '-' : vehicle.driver, showBottomBorder: true),
- TDCell(title: '预估里程', note: '${vehicle.estimatedMileage}公里', showBottomBorder: true),
- TDCell(title: '预估费用', note: '¥${vehicle.estimatedCost.toStringAsFixed(2)}', showBottomBorder: vehicle.reason.isNotEmpty),
- if (vehicle.reason.isNotEmpty)
- TDCell(title: '用车事由', note: vehicle.reason, showBottomBorder: false),
- ]);
- }
- Widget _buildDetailCard(String title, List<Widget> cells) {
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
- decoration: BoxDecoration(
- color: AppColors.cardWhite,
- borderRadius: BorderRadius.circular(10),
- boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.04), blurRadius: 4, offset: const Offset(0, 1))],
- ),
- child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
- Padding(
- padding: const EdgeInsets.fromLTRB(14, 12, 14, 8),
- child: Text(title, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: AppColors.textPrimary)),
- ),
- ...cells,
- ]),
- );
- }
- }
|