Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ FCM data 的值一律是字串,App 端 `fleetEventFromPushData()` 會把座標
(該趟車資×%,建單快照)→ 與司機對話 → 司機尋獲後支付處理費 → 歸還結案;
司機端 AppBar「遺失物協尋」工作清單(已找到/已歸還/未尋獲結案)。
處理費% 由 admin 費率設定頁調整(後端 `lost_item_fee_bps`)。
- **我的行程歷史(2026-07-19)**:乘客首頁右上「我的行程」→ 列出過去行程
(狀態/路線/時間/車資);**有司機的行程可事後「聯絡司機」**開對話
(沿用 `RideChatScreen`)。後端 `GET /customer/rides`(只回本人,LEFT JOIN 司機名)。
- **司機端概覽地圖(2026-07-16)**:接單後行程卡內嵌地圖(flutter_map + OSM,免 key)——
自己(綠色計程車)+目標(前往上車點=紅釘/行程中=藍旗)+兩點連線,相機自動框住兩點。
**只做「看位置」,不做導航**——turn-by-turn 仍由「導航」按鈕跳外部 Google Maps/Waze。
Expand Down Expand Up @@ -133,8 +136,6 @@ FCM data 的值一律是字串,App 端 `fleetEventFromPushData()` 會把座標
> 完整規格與待拍板事項見 [`docs/TODO.md`](docs/TODO.md) 與後端
> [line-fleet-dispatch/docs/TODO.md](../line-fleet-dispatch/docs/TODO.md)。

- **留言板入口補遺**:沿用既有 `RideChatScreen`(本來就有 REST 歷史+WS 即時),
補上「歷史行程也能進入對話」的入口,讓乘客事後(例如找遺失物)仍能聯絡司機。
- **待產品拍板**(見 TODO「懸而未決」):O5 admin 車輛審核(會讓司機端三態變四態)、
多停靠點的**建單前車資預估**(需後端新開報價 API)。

Expand Down
11 changes: 8 additions & 3 deletions docs/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,14 @@ admin 月報表頁 UI 亦渲染相同數字(NT$85.00/NT$12.75/NT$3,012.75
未指定時完成卡不該出現清潔費欄位。
`CompletedRideSummary` 目前只有 `fareAmountCents`,要加 `cleaningFeeCents`。
沿用 `money.dart` 的整數元格式(M 已定案)。
- [ ] **留言板**:沿用既有 `RideChatScreen`(H1,已有 REST 歷史+WS 即時)。
需確認「行程完成很久之後仍能進入對話」的入口——目前入口綁在進行中行程/協尋單上,
歷史行程沒有對話入口(**可能要加**)。
- [x] **留言板入口補遺** ✅ 2026-07-19:加「我的行程」歷史畫面
(`CustomerRideHistoryScreen`,首頁右上 receipt FAB 進入),列出過去行程
(狀態/路線/時間/車資),**有派到司機的行程**給「聯絡司機」開 `RideChatScreen`
(派單前取消的無對象可聯絡)。後端新增 `GET /customer/rides`
(dispatch PR #39:`ListRecentByCustomer`,LEFT JOIN drivers 取司機名,只回本人)。
沿用既有聊天,`RideChatScreen` 已按 `rideId` 過濾,重用 `ctrl.chatStream` 安全。
**模擬器實跑驗過**:完成 ride #9 → 歷史畫面顯示(NT$212/司機名)→ 聯絡司機
→ 發訊右靠綠泡 → 後端持久化、司機端 `GET /rides/9/messages` 讀到 `customer:...`。

### 乘客指定車種(✅ 2026-07-16 拍板採此方案,依賴後端 P1–P5)

Expand Down
18 changes: 18 additions & 0 deletions lib/core/api/customer_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,24 @@ class CustomerApiClient {
}
}

/// 我的行程歷史(新到舊)。供「事後聯絡司機」的入口。
Future<List<CustomerRideSummary>> fetchRideHistory({int limit = 20}) async {
try {
final res = await _dio.get<Map<String, dynamic>>(
'/customer/rides',
queryParameters: {'limit': limit},
);
final raw = res.data?['rides'];
if (raw is! List) return const [];
return raw
.whereType<Map>()
.map((m) => CustomerRideSummary.fromJson(Map<String, dynamic>.from(m)))
.toList();
} on DioException catch (e) {
throw _wrap(e);
}
}

/// 行程內對話歷史(afterId > 0 時做增量補讀,WS 斷線重連後補漏)。
Future<List<RideMessage>> fetchMessages(int rideId, {int afterId = 0}) async {
try {
Expand Down
91 changes: 73 additions & 18 deletions lib/core/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ abstract final class RideStatus {
status == completed || status == cancelled;
}

/// 訂單狀態的中文標籤(乘客端共用)。
String rideStatusLabel(int status) {
switch (status) {
case RideStatus.requested:
return '尋找司機中';
case RideStatus.assigned:
return '派單中';
case RideStatus.accepted:
return '司機前往上車點';
case RideStatus.pickedUp:
return '行程中';
case RideStatus.completed:
return '已完成';
case RideStatus.cancelled:
return '已取消';
default:
return '狀態 $status';
}
}

/// 乘客端當前訂單。狀態碼對齊後端 constants.RideStatus*。
/// 來源可能是下單回應(snake key: ride_id/status)或查詢 model.Ride
/// (無 json tag → PascalCase key: ID/Status),故解析時兩者皆容。
Expand Down Expand Up @@ -302,24 +322,7 @@ class CustomerRide {
return '約 ${(etaPickupSec! / 60).ceil()} 分鐘抵達';
}

String get statusLabel {
switch (status) {
case RideStatus.requested:
return '尋找司機中';
case RideStatus.assigned:
return '派單中';
case RideStatus.accepted:
return '司機前往上車點';
case RideStatus.pickedUp:
return '行程中';
case RideStatus.completed:
return '已完成';
case RideStatus.cancelled:
return '已取消';
default:
return '狀態 $status';
}
}
String get statusLabel => rideStatusLabel(status);

/// 乘客端分階段文案。`driverArrived` 來自 WS `driver.arrived`
///(後端狀態仍為 Accepted,不另存 DB flag)。
Expand Down Expand Up @@ -353,6 +356,58 @@ class CustomerRide {
}
}

/// 乘客端「我的行程」歷史列表的單筆(後端 GET /customer/rides 的 CustomerRideRow)。
/// 夠渲染清單與開對話即可;`driverName` 只在有派到司機時非空 → 決定是否顯示「聯絡司機」。
class CustomerRideSummary {
const CustomerRideSummary({
required this.rideId,
required this.status,
required this.pickupAddress,
this.dropoffAddress,
this.requestedAt,
this.completedAt,
this.fareAmountCents,
this.driverId,
this.driverName,
});

final int rideId;
final int status;
final String pickupAddress;
final String? dropoffAddress;
final DateTime? requestedAt;
final DateTime? completedAt;
final int? fareAmountCents;
final int? driverId;
final String? driverName;

/// 有派到司機才給「聯絡司機」——取消於派單前的行程沒有對象可聯絡。
bool get hasDriver => driverId != null;

String get statusLabel => rideStatusLabel(status);

static DateTime? _parseTime(Object? v) {
if (v is! String || v.isEmpty) return null;
return DateTime.tryParse(v);
}

factory CustomerRideSummary.fromJson(Map<String, dynamic> json) {
return CustomerRideSummary(
rideId: (json['id'] as num).toInt(),
status: (json['status'] as num?)?.toInt() ?? 0,
pickupAddress: json['pickup_address'] as String? ?? '',
dropoffAddress: (json['dropoff_address'] as String?)?.isNotEmpty == true
? json['dropoff_address'] as String
: null,
requestedAt: _parseTime(json['requested_at']),
completedAt: _parseTime(json['completed_at']),
fareAmountCents: (json['fare_amount_cents'] as num?)?.toInt(),
driverId: (json['driver_id'] as num?)?.toInt(),
driverName: json['driver_name'] as String?,
);
}
}

/// 行程內對話訊息(乘客↔司機)。來源:REST 歷史查詢或 WS `chat.message` payload,
/// 兩者欄位相同(後端 rideMessagePayload 與 model JSON 對齊)。
class RideMessage {
Expand Down
26 changes: 26 additions & 0 deletions lib/customer/customer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class CustomerController extends ChangeNotifier {
// 遺失物:未結案協尋單(WS lost_item.* 即時更新)。
List<LostItemRequest> _lostItems = [];

// 歷史行程(我的行程列表;進畫面時才載入)。
List<CustomerRideSummary> _rideHistory = [];
bool _historyLoading = false;
String? _historyError;

CustomerSession? get session => _session;
bool get isLoggedIn => _session != null;
bool get loading => _loading;
Expand Down Expand Up @@ -217,6 +222,27 @@ class CustomerController extends ChangeNotifier {
/// 未結案遺失物協尋單。
List<LostItemRequest> get lostItems => _lostItems;

/// 歷史行程(我的行程列表)。
List<CustomerRideSummary> get rideHistory => List.unmodifiable(_rideHistory);
bool get historyLoading => _historyLoading;
String? get historyError => _historyError;

/// 載入歷史行程(進「我的行程」畫面時呼叫)。
Future<void> loadRideHistory() async {
if (_session == null) return;
_historyLoading = true;
_historyError = null;
notifyListeners();
try {
_rideHistory = await _api.fetchRideHistory();
} on ApiException catch (e) {
_historyError = e.message;
} finally {
_historyLoading = false;
notifyListeners();
}
}

/// 聊天室開啟/關閉;開啟時清未讀並停止累計。
void setChatVisible(bool visible) {
_chatVisible = visible;
Expand Down
25 changes: 21 additions & 4 deletions lib/customer/screens/customer_map_home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '../../core/models/models.dart';
import '../../core/util/map_tiles.dart';
import '../customer_controller.dart';
import '../widgets/ride_phase_content.dart';
import 'ride_history_screen.dart';

/// 地圖為底+Bottom Sheet 主畫面(spec §2.1)。
/// 圖磚走 OpenStreetMap(flutter_map),不需任何 API key。
Expand Down Expand Up @@ -47,10 +48,26 @@ class _CustomerMapHomeScreenState extends State<CustomerMapHomeScreen> {
Positioned(
top: MediaQuery.of(context).padding.top + 12,
right: 16,
child: FloatingActionButton.small(
heroTag: 'logout',
onPressed: ctrl.loading ? null : () => ctrl.logout(),
child: const Icon(Icons.logout),
child: Column(
children: [
FloatingActionButton.small(
heroTag: 'history',
tooltip: '我的行程',
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const CustomerRideHistoryScreen(),
),
),
child: const Icon(Icons.receipt_long),
),
const SizedBox(height: 12),
FloatingActionButton.small(
heroTag: 'logout',
tooltip: '登出',
onPressed: ctrl.loading ? null : () => ctrl.logout(),
child: const Icon(Icons.logout),
),
],
),
),
DraggableScrollableSheet(
Expand Down
Loading
Loading