",
auto_close=True,
)
def _segment_vehicle(leg: dict[str, Any] | None) -> str:
"""每段车型用 TMS 的 vehicleType 原文。没有台数,空值显示 -。"""
src = dict(leg or {})
raw = str(
src.get("vehicleType") or src.get("vehicle_type") or src.get("truckType") or ""
).strip()
if raw.lower() in {"none", "null"}:
raw = ""
return raw or "-"
def _route_card(index: int, route: dict[str, Any], quote: dict[str, Any] | None = None) -> str:
"""一张线路:航线、各段路段、车型、TMS 费目、合计。"""
line = html.escape(route_line(route))
blocks = land_leg_fee_blocks_for_route(quote, route)
shown_legs = [
leg
for leg in list(route.get("legs") or [])
if str(leg.get("origin") or "").strip() or str(leg.get("destination") or "").strip()
]
etas = {i: d for i, (_, d) in enumerate(option_eta_bits(route), 1)}
fee_bits: list[str] = []
items = ""
if blocks:
for i, (title, fees, eta) in enumerate(blocks, 1):
vehicle = _segment_vehicle(shown_legs[i - 1] if i - 1 < len(shown_legs) else None)
items += (
f"
{html.escape(title)}"
"
"
)
items += (
f"
车型 {html.escape(vehicle)}"
"
"
)
for fee in fees:
amount = _money(fee.get("amount"), str(fee.get("currency") or "").strip())
name = str(fee.get("name") or "").strip()
if not name or not amount:
continue
items += (
f"
{html.escape(name)}"
f"{html.escape(amount)}
"
)
days = eta or etas.get(i) or ""
if days:
items += (
f"
时效 {html.escape(days)}"
"
"
)
if items:
fee_bits.append(f"
{items}
")
else:
fee_bits.append("
本线路未返回分段成本
")
total = html.escape(option_total(route))
legs = list(route.get("legs") or [])
tag = "中转" if len(legs) > 1 else "直达"
tag_cls = "pill via" if len(legs) > 1 else "pill"
return (
""
)