import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:tdesign_flutter/tdesign_flutter.dart'; import '../../core/theme/app_colors.dart'; import '../../core/utils/date_utils.dart' as du; import '../../shared/widgets/app_card.dart'; import 'outing_log_model.dart'; import 'outing_log_list_controller.dart'; class OutingLogDetailPage extends ConsumerWidget { final String id; const OutingLogDetailPage({super.key, required this.id}); @override Widget build(BuildContext context, WidgetRef ref) { final log = mockOutingLogs.firstWhere((e) => e.id == id, orElse: () => mockOutingLogs.first); return Scaffold( appBar: TDNavBar( title: '外出日志详情', titleColor: Colors.white, backgroundColor: const Color(0xFF00ABF3), centerTitle: false, ), body: SingleChildScrollView( padding: const EdgeInsets.all(12), child: Column( children: [ _buildStatusHeader(log), const SizedBox(height: 12), _buildInfoSection(log), const SizedBox(height: 12), _buildContentSection(log), ], ), ), ); } Widget _buildStatusHeader(OutingLogModel log) { final (icon, color, text) = switch (log.status) { '已完成' => (Icons.check_circle, AppColors.success, '已完成'), '待审核' => (Icons.schedule, AppColors.warning, '待审核'), _ => (Icons.info_outline, AppColors.textHint, log.status), }; 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), Text(text, style: TextStyle( fontSize: 18, fontWeight: FontWeight.w600, color: color)), ], ), ); } Widget _buildInfoSection(OutingLogModel log) { return _buildDetailCard('基本信息', [ TDCell(title: '拜访编号', note: log.visitNo, showBottomBorder: true), TDCell(title: '业务员', note: '${log.salespersonName} · ${log.deptName}', showBottomBorder: true), TDCell(title: '客户名称', note: log.customerName, showBottomBorder: true), TDCell(title: '联系人', note: '${log.contactName.isNotEmpty ? log.contactName : '-'}${log.contactPhone.isNotEmpty ? ' · ${log.contactPhone}' : ''}', showBottomBorder: true), TDCell(title: '拜访类型', note: log.visitType, showBottomBorder: true), TDCell(title: '拜访目的', note: log.visitPurpose.isNotEmpty ? log.visitPurpose : '-', showBottomBorder: true), TDCell(title: '拜访时间', note: '${du.DateUtils.formatDate(log.visitDate)} ${du.DateUtils.formatTime(log.visitStartTime)} - ${du.DateUtils.formatTime(log.visitEndTime)}', showBottomBorder: true), TDCell(title: '拜访地点', note: log.visitLocation.isNotEmpty ? log.visitLocation : '-', showBottomBorder: false), ]); } Widget _buildDetailCard(String title, List 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, ]), ); } Widget _buildContentSection(OutingLogModel log) { return AppCard( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text('拜访详情', style: TextStyle( fontSize: 13, fontWeight: FontWeight.w600, color: AppColors.textPrimary)), const SizedBox(height: 10), _contentBlock('拜访总结', log.visitSummary), if (log.customerFeedback.isNotEmpty) _contentBlock('客户反馈', log.customerFeedback), if (log.competitorInfo.isNotEmpty) _contentBlock('竞品信息', log.competitorInfo), _contentBlock('下次拜访', '${du.DateUtils.formatDate(log.nextVisitTime)}${log.nextVisitContent.isNotEmpty ? ' · ${log.nextVisitContent}' : ''}'), ], ), ); } Widget _contentBlock(String label, String value) { return Padding( padding: const EdgeInsets.only(bottom: 12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(label, style: const TextStyle( fontSize: 12, color: AppColors.textSecondary)), const SizedBox(height: 4), Text(value.isNotEmpty ? value : '-', style: const TextStyle( fontSize: 13, color: AppColors.textPrimary, height: 1.5)), ], ), ); } }