Merge branch 'codex/issue-48-fuel-avg-rate-42852718d883' into V3.0
加油汇总顶部近10/20/30次平均油耗(#48),待用户测试。
This commit is contained in:
commit
a4d747aece
12 files changed
+352
-276
No files matched your search
@@ -130,6 +130,21 @@ class VehicleFuelPlateMonthItem(BaseModel):
|
||||
alias="last3MonthsRateL100",
|
||||
description="近三个月百公里油耗 L/100km,不足则为 null",
|
||||
)
|
||||
avg_rate_last10_l100: Optional[Decimal] = Field(
|
||||
default=None,
|
||||
alias="avgRateLast10L100",
|
||||
description="近10次有效加油段平均百公里油耗 L/100km,不足则为 null",
|
||||
)
|
||||
avg_rate_last20_l100: Optional[Decimal] = Field(
|
||||
default=None,
|
||||
alias="avgRateLast20L100",
|
||||
description="近20次有效加油段平均百公里油耗 L/100km,不足则为 null",
|
||||
)
|
||||
avg_rate_last30_l100: Optional[Decimal] = Field(
|
||||
default=None,
|
||||
alias="avgRateLast30L100",
|
||||
description="近30次有效加油段平均百公里油耗 L/100km,不足则为 null",
|
||||
)
|
||||
|
||||
model_config = {"populate_by_name": True}
|
||||
|
||||
|
||||
@@ -479,6 +479,41 @@ def rate_l100(liters: Decimal, run_km: Optional[Decimal]) -> Optional[Decimal]:
|
||||
)
|
||||
|
||||
|
||||
def trip_rate_l100(
|
||||
prev_liters: Optional[Decimal],
|
||||
prev_odometer: Optional[Decimal],
|
||||
curr_odometer: Optional[Decimal],
|
||||
) -> Optional[Decimal]:
|
||||
"""相邻两次登记的单次油耗:上次升数 × 100 / (本次期初 − 上次期初)。"""
|
||||
if prev_liters is None or prev_odometer is None or curr_odometer is None:
|
||||
return None
|
||||
liters = Decimal(prev_liters)
|
||||
if liters <= 0:
|
||||
return None
|
||||
return rate_l100(liters, Decimal(curr_odometer) - Decimal(prev_odometer))
|
||||
|
||||
|
||||
def avg_recent_trip_rates_l100(
|
||||
rows: Sequence[Tuple[Optional[Decimal], Optional[Decimal]]],
|
||||
n: int,
|
||||
) -> Optional[Decimal]:
|
||||
"""rows 为按时间升序的 (期初公里, 加油升数);取最近 n 个有效单次油耗算术平均。"""
|
||||
if n <= 0:
|
||||
return None
|
||||
rates: list[Decimal] = []
|
||||
for i in range(1, len(rows)):
|
||||
prev_odo, prev_liters = rows[i - 1]
|
||||
curr_odo, _ = rows[i]
|
||||
rate = trip_rate_l100(prev_liters, prev_odo, curr_odo)
|
||||
if rate is not None:
|
||||
rates.append(rate)
|
||||
if not rates:
|
||||
return None
|
||||
selected = rates[-n:]
|
||||
total = sum(selected, Decimal("0"))
|
||||
return (total / Decimal(len(selected))).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
|
||||
|
||||
|
||||
def _odo_pairs(
|
||||
rows: Sequence[PlVehicleFuelRegister],
|
||||
) -> list[Tuple[date, Optional[Decimal]]]:
|
||||
@@ -526,8 +561,6 @@ def list_plate_month_summary(
|
||||
q_start, q_end = quarter_bounds(anchor)
|
||||
prev_q_start, _ = _ym_bounds(ym_shift(f"{q_start:%Y-%m}", -3))
|
||||
_, next_q_end = quarter_bounds(q_end)
|
||||
range_start = min(prev_q_start, last3_start, prev_start)
|
||||
range_end = max(next_end, next_q_end)
|
||||
|
||||
vehicle_query = (
|
||||
db.query(PlVehicle)
|
||||
@@ -547,12 +580,11 @@ def list_plate_month_summary(
|
||||
vehicles = apply_pl_scope(vehicle_query, PlVehicle, user, db, tenant_no).all()
|
||||
personnel_summaries = load_vehicle_personnel_summaries(db, tenant_no, [v.id for v in vehicles])
|
||||
|
||||
# 近 N 次平均需要完整历史;月/季指标仍从同批记录按区间切片。
|
||||
query = db.query(PlVehicleFuelRegister).filter(
|
||||
PlVehicleFuelRegister.tenant_no == tenant_no,
|
||||
PlVehicleFuelRegister.del_flag == 0,
|
||||
PlVehicleFuelRegister.status == "normal",
|
||||
PlVehicleFuelRegister.register_date >= range_start,
|
||||
PlVehicleFuelRegister.register_date < range_end,
|
||||
)
|
||||
query = apply_pl_scope(query, PlVehicleFuelRegister, user, db, tenant_no)
|
||||
registers = query.order_by(
|
||||
@@ -575,6 +607,7 @@ def list_plate_month_summary(
|
||||
next_q_rows = [r for r in rows if q_end <= r.register_date < next_q_end]
|
||||
prev_q_rows = [r for r in rows if prev_q_start <= r.register_date < q_start]
|
||||
last3_rows = [r for r in rows if last3_start <= r.register_date < cur_end]
|
||||
odo_liter_rows = [(r.odometer_km, r.fuel_liters) for r in rows]
|
||||
|
||||
month_km, month_status = period_run_km(_odo_pairs(cur_rows), _odo_pairs(next_rows))
|
||||
prev_month_km, prev_month_status = period_run_km(_odo_pairs(prev_rows), _odo_pairs(cur_rows))
|
||||
@@ -606,6 +639,9 @@ def list_plate_month_summary(
|
||||
prevQuarterRateL100=prev_quarter_rate,
|
||||
prevMonthRateL100=prev_month_rate,
|
||||
last3MonthsRateL100=last3_rate,
|
||||
avgRateLast10L100=avg_recent_trip_rates_l100(odo_liter_rows, 10),
|
||||
avgRateLast20L100=avg_recent_trip_rates_l100(odo_liter_rows, 20),
|
||||
avgRateLast30L100=avg_recent_trip_rates_l100(odo_liter_rows, 30),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
"""近 N 次加油段平均百公里油耗(L/100km)算法。"""
|
||||
from decimal import Decimal
|
||||
|
||||
from app.services.pl_vehicle_fuel_service import avg_recent_trip_rates_l100, trip_rate_l100
|
||||
|
||||
|
||||
def test_trip_rate_uses_previous_liters_over_odometer_delta():
|
||||
# (本次期初 - 上次期初) = 200km,上次加油 50L → 25 L/100km
|
||||
assert trip_rate_l100(
|
||||
prev_liters=Decimal("50"),
|
||||
prev_odometer=Decimal("1000"),
|
||||
curr_odometer=Decimal("1200"),
|
||||
) == Decimal("25.00")
|
||||
|
||||
|
||||
def test_trip_rate_rejects_non_positive_delta_or_liters():
|
||||
assert trip_rate_l100(Decimal("50"), Decimal("1200"), Decimal("1000")) is None
|
||||
assert trip_rate_l100(Decimal("0"), Decimal("1000"), Decimal("1200")) is None
|
||||
assert trip_rate_l100(Decimal("-1"), Decimal("1000"), Decimal("1200")) is None
|
||||
assert trip_rate_l100(Decimal("50"), None, Decimal("1200")) is None
|
||||
assert trip_rate_l100(Decimal("50"), Decimal("1000"), None) is None
|
||||
|
||||
|
||||
def test_avg_recent_takes_last_n_valid_segments_only():
|
||||
# 段1: 1000→1100 / 40L = 40
|
||||
# 段2: 1100→1300 / 50L = 25
|
||||
# 段3: 无效(里程倒退)
|
||||
# 段4: 1200→1500 / 60L = 20
|
||||
rows = [
|
||||
(Decimal("1000"), Decimal("40")),
|
||||
(Decimal("1100"), Decimal("50")),
|
||||
(Decimal("1300"), Decimal("30")),
|
||||
(Decimal("1200"), Decimal("60")), # 倒退后的上一笔,下一段用其升数
|
||||
(Decimal("1500"), Decimal("10")),
|
||||
]
|
||||
assert avg_recent_trip_rates_l100(rows, 2) == Decimal("22.50") # (25+20)/2
|
||||
assert avg_recent_trip_rates_l100(rows, 10) == Decimal("28.33") # (40+25+20)/3
|
||||
assert avg_recent_trip_rates_l100(rows[:1], 10) is None
|
||||
assert avg_recent_trip_rates_l100([], 10) is None
|
||||
@@ -73,6 +73,10 @@ def test_summary_includes_html_metrics_and_previous_quarter_across_year(summary_
|
||||
assert item["quarterRateL100"] == Decimal("50")
|
||||
assert item["prevMonthRateL100"] == Decimal("50")
|
||||
assert item["prevQuarterRateL100"] == Decimal("21.05")
|
||||
# 五段有效:2、20、10、50、20 → 平均 20.40
|
||||
assert item["avgRateLast10L100"] == Decimal("20.40")
|
||||
assert item["avgRateLast20L100"] == Decimal("20.40")
|
||||
assert item["avgRateLast30L100"] == Decimal("20.40")
|
||||
|
||||
|
||||
def test_summary_follows_requested_month_instead_of_today(summary_db):
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
schema: spec-driven
|
||||
created: 2026-11-19
|
||||
issue: 48
|
||||
@@ -0,0 +1,14 @@
|
||||
## Context
|
||||
|
||||
汇总页与本人登记页共用 `FuelRegisterListPage`;仅 `mode=summary` 显示顶部卡片。原月度指标 API 仍保留字段,前端改为展示近 N 次平均。
|
||||
|
||||
## Decision
|
||||
|
||||
1. **计算放后端**:租户隔离、数据范围与作废过滤与列表一致;前端只展示。
|
||||
2. **复用 `plate-month-summary`**:增加 `avgRateLast10/20/30L100`,拉取该车全部正常未删登记再切片,避免新路由。
|
||||
3. **单位 L/100km**:与既有 `rate_l100` 一致;升数≤0 或里程差≤0 的段不计入平均。
|
||||
4. **UI**:去掉月份条;三项指标;点击车牌仍写列头车牌过滤。
|
||||
|
||||
## Risks
|
||||
|
||||
- 全量历史登记加载:自有车加油量通常可控;若日后变大再按车牌限窗。
|
||||
@@ -0,0 +1,26 @@
|
||||
## Why
|
||||
|
||||
加油登记汇总页顶部曾改为「待开发」。业务需要按车牌展示近 10/20/30 次平均油耗(L/100km),替代原按月加油量/里程/月季油耗卡片内容。
|
||||
|
||||
## What Changes
|
||||
|
||||
- 恢复汇总页顶部车牌卡片(复用既有卡片布局,去掉月份选择)
|
||||
- `plate-month-summary` 增加近 10/20/30 次平均百公里油耗字段
|
||||
- 单次油耗:`(上次加油升数 × 100) / (本次期初公里 − 上次期初公里)`
|
||||
- 近 N 次:同一车牌时间升序中,最近 N 个有效单次的算术平均;无效段跳过
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
- (无)
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `pl-vehicle-fuel-summary`: 汇总顶部统计口径改为近 N 次平均 L/100km
|
||||
|
||||
## Impact
|
||||
|
||||
- 后端 `pl_vehicle_fuel_service` / `vehicle_fuel` schema
|
||||
- Web `FuelPlateMonthCards`、`FuelRegisterListPage`、API 类型
|
||||
- 工单:https://gitea.aichengyan.com/cykj/shanxia2.0/issues/48
|
||||
@@ -0,0 +1,25 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: 近 N 次平均百公里油耗
|
||||
|
||||
系统 SHALL 在加油登记汇总顶部按自有车牌展示近 10、20、30 次平均油耗,单位为 L/100km。
|
||||
|
||||
#### Scenario: 单次油耗计算
|
||||
|
||||
- **WHEN** 同一车牌存在相邻两次正常未删除登记,且上次加油升数 > 0、本次期初公里 > 上次期初公里
|
||||
- **THEN** 该段油耗为 `上次加油升数 × 100 / (本次期初公里 − 上次期初公里)`,保留两位小数
|
||||
|
||||
#### Scenario: 近 N 次平均
|
||||
|
||||
- **WHEN** 某车牌存在至少一段有效单次油耗
|
||||
- **THEN** 近 N 次平均为时间升序下最近 min(N, 有效段数) 个单次油耗的算术平均;无效段(缺期初、升数≤0、里程未增加)不计入
|
||||
|
||||
#### Scenario: 数据不足
|
||||
|
||||
- **WHEN** 某车牌没有有效单次油耗段
|
||||
- **THEN** 对应近 N 次平均字段为 null,界面显示 —
|
||||
|
||||
#### Scenario: 点击筛选
|
||||
|
||||
- **WHEN** 用户点击某车牌卡片
|
||||
- **THEN** 下方列表按该车牌过滤;再次点击同一车牌取消过滤
|
||||
@@ -0,0 +1,15 @@
|
||||
## 1. 后端
|
||||
|
||||
- [x] 单次/近 N 次平均算法与单测
|
||||
- [x] schema 增加 avgRateLast10/20/30L100
|
||||
- [x] `list_plate_month_summary` 填充新字段;汇总回归断言
|
||||
|
||||
## 2. Web
|
||||
|
||||
- [x] 恢复汇总顶部卡片,展示近 10/20/30 次平均
|
||||
- [x] API 类型字段对齐
|
||||
|
||||
## 3. 验证
|
||||
|
||||
- [x] `pytest` 加油汇总相关:21 passed
|
||||
- [ ] 本机打开汇总页目视验收(需在任务 worktree 启前后端)
|
||||
@@ -2262,6 +2262,10 @@ export interface VehicleFuelPlateMonthItem {
|
||||
prevMonthRateL100?: number | string | null
|
||||
/** 近三个月百公里油耗 L/100km;里程不足时为 null */
|
||||
last3MonthsRateL100?: number | string | null
|
||||
/** 近 10/20/30 次有效加油段平均百公里油耗 L/100km */
|
||||
avgRateLast10L100?: number | string | null
|
||||
avgRateLast20L100?: number | string | null
|
||||
avgRateLast30L100?: number | string | null
|
||||
}
|
||||
|
||||
export interface VehicleFuelPlateMonthSummaryResponse {
|
||||
|
||||
@@ -1,89 +1,41 @@
|
||||
<!-- 自有车辆加油量、里程、月度/季度油耗,与 index(7).html 对齐 -->
|
||||
<!-- 自有车辆近 10/20/30 次平均油耗(L/100km) -->
|
||||
<template>
|
||||
<div class="fuel-plate-cards-wrap">
|
||||
<div class="fuel-month-bar">
|
||||
<span class="fuel-month-label">统计月份</span>
|
||||
<div class="fuel-month-control">
|
||||
<el-button
|
||||
class="fuel-month-step"
|
||||
:disabled="month <= '1900-01'"
|
||||
aria-label="上个月"
|
||||
@click="shiftMonth(-1)"
|
||||
>
|
||||
<el-icon><ArrowLeft /></el-icon>
|
||||
</el-button>
|
||||
<el-date-picker
|
||||
:model-value="month"
|
||||
type="month"
|
||||
value-format="YYYY-MM"
|
||||
format="YYYY年MM月"
|
||||
:clearable="false"
|
||||
aria-label="统计月份"
|
||||
@update:model-value="handleMonthChange"
|
||||
/>
|
||||
<el-button
|
||||
class="fuel-month-step"
|
||||
:disabled="month >= '2100-12'"
|
||||
aria-label="下个月"
|
||||
@click="shiftMonth(1)"
|
||||
>
|
||||
<el-icon><ArrowRight /></el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-loading="loading" class="fuel-plate-body">
|
||||
<div v-if="error" class="fuel-plate-error">{{ error }}</div>
|
||||
<div v-else-if="!loading && !items.length" class="fuel-plate-empty">暂无自有车辆</div>
|
||||
<div v-else class="fuel-plate-grid">
|
||||
<article
|
||||
v-for="item in cards"
|
||||
:key="`${item.licensePlate}-${item.trailerNo || ''}`"
|
||||
class="fuel-plate-card"
|
||||
:class="{ 'is-selected': selectedPlate === item.licensePlate }"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-pressed="selectedPlate === item.licensePlate"
|
||||
:aria-label="`筛选 ${item.licensePlate} 的加油记录`"
|
||||
@click="handleClick(item.licensePlate)"
|
||||
@keydown.enter.prevent="handleClick(item.licensePlate)"
|
||||
@keydown.space.prevent="handleClick(item.licensePlate)"
|
||||
>
|
||||
<div class="plate" :title="formatPlVehiclePlateDisplay(item.licensePlate, item.trailerNo)">
|
||||
{{ formatPlVehiclePlateDisplay(item.licensePlate, item.trailerNo) }}
|
||||
</div>
|
||||
<div class="meta">
|
||||
<span>{{ item.defaultDriverName || '—' }}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<el-tag :type="vehicleStatus(item.vehicleStatus).type" size="small">
|
||||
{{ vehicleStatus(item.vehicleStatus).label }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="nums">
|
||||
<div v-for="metric in item.metrics" :key="metric.label">
|
||||
<b>{{ metric.value }}</b>
|
||||
<span class="label" :title="metric.description">{{ metric.label }}</span>
|
||||
<div v-if="metric.notices.length" class="metric-notices">
|
||||
<el-tag
|
||||
v-for="notice in metric.notices"
|
||||
:key="notice.text"
|
||||
:type="notice.type"
|
||||
size="small"
|
||||
>
|
||||
{{ notice.text }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<em
|
||||
v-for="comparison in metric.comparisons"
|
||||
:key="comparison.text"
|
||||
class="mom"
|
||||
:class="comparison.trend"
|
||||
>
|
||||
{{ comparison.text }}
|
||||
</em>
|
||||
<div v-if="error" class="fuel-plate-error">{{ error }}</div>
|
||||
<div v-else-if="!loading && !items.length" class="fuel-plate-empty">暂无自有车辆</div>
|
||||
<div v-else class="fuel-plate-grid">
|
||||
<article
|
||||
v-for="item in cards"
|
||||
:key="`${item.licensePlate}-${item.trailerNo || ''}`"
|
||||
class="fuel-plate-card"
|
||||
:class="{ 'is-selected': selectedPlate === item.licensePlate }"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:aria-pressed="selectedPlate === item.licensePlate"
|
||||
:aria-label="`筛选 ${item.licensePlate} 的加油记录`"
|
||||
@click="handleClick(item.licensePlate)"
|
||||
@keydown.enter.prevent="handleClick(item.licensePlate)"
|
||||
@keydown.space.prevent="handleClick(item.licensePlate)"
|
||||
>
|
||||
<div class="plate" :title="formatPlVehiclePlateDisplay(item.licensePlate, item.trailerNo)">
|
||||
{{ formatPlVehiclePlateDisplay(item.licensePlate, item.trailerNo) }}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div class="meta">
|
||||
<span>{{ item.defaultDriverName || '—' }}</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<el-tag :type="vehicleStatus(item.vehicleStatus).type" size="small">
|
||||
{{ vehicleStatus(item.vehicleStatus).label }}
|
||||
</el-tag>
|
||||
</div>
|
||||
<div class="nums">
|
||||
<div v-for="metric in item.metrics" :key="metric.label">
|
||||
<b>{{ metric.value }}</b>
|
||||
<span class="label" :title="metric.description">{{ metric.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -91,20 +43,13 @@
|
||||
<script setup lang="ts">
|
||||
import type { VehicleFuelPlateMonthItem } from '@/api/pl'
|
||||
import { formatPlVehiclePlateDisplay } from '@/utils/pl-display'
|
||||
import { ArrowLeft, ArrowRight } from '@element-plus/icons-vue'
|
||||
import {
|
||||
fuelComparison,
|
||||
formatFuelRate,
|
||||
formatFuelLiters,
|
||||
fuelMileageNotice
|
||||
} from '@/utils/pl-fuel-summary'
|
||||
import { formatFuelRate } from '@/utils/pl-fuel-summary'
|
||||
|
||||
defineOptions({ name: 'FuelPlateMonthCards' })
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
items: VehicleFuelPlateMonthItem[]
|
||||
month: string
|
||||
loading?: boolean
|
||||
error?: string
|
||||
selectedPlate?: string
|
||||
@@ -114,65 +59,34 @@
|
||||
|
||||
const emit = defineEmits<{
|
||||
select: [plate: string | null]
|
||||
'update:month': [month: string]
|
||||
}>()
|
||||
|
||||
function handleMonthChange(value: string | null) {
|
||||
if (!value || value === props.month) return
|
||||
emit('update:month', value)
|
||||
}
|
||||
|
||||
function shiftMonth(offset: number) {
|
||||
const match = /^(\d{4})-(\d{2})$/.exec(props.month)
|
||||
if (!match) return
|
||||
const index = Number(match[1]) * 12 + (Number(match[2]) - 1) + offset
|
||||
const year = Math.floor(index / 12)
|
||||
const month = index - year * 12 + 1
|
||||
if (year < 1900 || year > 2100) return
|
||||
handleMonthChange(`${year}-${String(month).padStart(2, '0')}`)
|
||||
}
|
||||
const RATE_DESC =
|
||||
'单次:上次加油升数 × 100 ÷(本次期初公里 − 上次期初公里)。近 N 次为最近 N 个有效单次油耗的算术平均;缺里程、升数≤0 或里程未增加时跳过该段。'
|
||||
|
||||
const cards = computed(() =>
|
||||
props.items.map((item) => ({
|
||||
...item,
|
||||
metrics: [
|
||||
{
|
||||
value: formatFuelLiters(item.liters),
|
||||
label: '当月加油量/升',
|
||||
description: '按登记日期汇总当月正常、未删除且有权限查看的加油记录。',
|
||||
notices: [],
|
||||
comparisons: [fuelComparison(item.liters, item.prevLiters)]
|
||||
value: formatFuelRate(item.avgRateLast10L100),
|
||||
label: '近10次平均(L/100km)',
|
||||
description: RATE_DESC
|
||||
},
|
||||
{
|
||||
value: formatNumber(item.runKm, 0),
|
||||
label: '当月里程数',
|
||||
description: '下月首笔有效里程减本月首笔;下月无读数时,使用本月最新读数减首笔暂估。',
|
||||
notices: [fuelMileageNotice(item.monthMileageStatus)].filter((notice) => notice !== null),
|
||||
comparisons: [fuelComparison(item.runKm, item.prevRunKm)]
|
||||
value: formatFuelRate(item.avgRateLast20L100),
|
||||
label: '近20次平均(L/100km)',
|
||||
description: RATE_DESC
|
||||
},
|
||||
{
|
||||
value: `${formatFuelRate(item.monthRateL100)} / ${formatFuelRate(item.quarterRateL100)}`,
|
||||
label: '当月/季度油耗(L/100km)',
|
||||
description:
|
||||
'参考估算:本周期加油量 ÷ 本周期里程 × 100。季度里程为下季首笔减本季首笔;尚无下季读数时使用本季首末差暂估。加油量不等同于实际耗油量。',
|
||||
notices: [
|
||||
fuelMileageNotice(item.monthMileageStatus, '当月'),
|
||||
fuelMileageNotice(item.quarterMileageStatus, '季度')
|
||||
].filter((notice) => notice !== null),
|
||||
comparisons: [
|
||||
fuelComparison(item.monthRateL100, item.prevMonthRateL100),
|
||||
fuelComparison(item.quarterRateL100, item.prevQuarterRateL100, '环比上个季度')
|
||||
]
|
||||
value: formatFuelRate(item.avgRateLast30L100),
|
||||
label: '近30次平均(L/100km)',
|
||||
description: RATE_DESC
|
||||
}
|
||||
]
|
||||
}))
|
||||
)
|
||||
|
||||
function formatNumber(value: number | string | null | undefined, digits: number) {
|
||||
if (value == null || value === '' || !Number.isFinite(Number(value))) return '—'
|
||||
return Number(value).toLocaleString('zh-CN', { maximumFractionDigits: digits })
|
||||
}
|
||||
|
||||
function vehicleStatus(status: string): {
|
||||
label: string
|
||||
type: 'success' | 'warning' | 'danger' | 'info'
|
||||
@@ -195,37 +109,6 @@
|
||||
margin: 16px 16px 16px;
|
||||
}
|
||||
|
||||
.fuel-month-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.fuel-month-label {
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
color: var(--el-text-color-regular);
|
||||
}
|
||||
|
||||
.fuel-month-control {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.fuel-month-step {
|
||||
width: 36px;
|
||||
min-width: 36px;
|
||||
height: 36px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.fuel-month-bar :deep(.el-date-editor) {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.fuel-plate-body {
|
||||
min-height: 48px;
|
||||
}
|
||||
@@ -247,111 +130,88 @@
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.fuel-plate-card {
|
||||
min-width: 0;
|
||||
padding: 14px 16px;
|
||||
cursor: pointer;
|
||||
background: var(--el-bg-color, #fff);
|
||||
border: 1px solid var(--el-border-color, #e2e8f0);
|
||||
border-radius: 12px;
|
||||
box-shadow:
|
||||
0 1px 2px rgb(28 36 48 / 4%),
|
||||
0 8px 24px rgb(28 36 48 / 4%);
|
||||
|
||||
&.is-selected {
|
||||
background: var(--el-color-primary-light-9, #ecfdf5);
|
||||
border-color: var(--el-color-primary, #10b981);
|
||||
}
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
border-color: var(--el-color-primary, #10b981);
|
||||
}
|
||||
|
||||
&:focus-visible {
|
||||
outline: 2px solid var(--el-color-primary, #10b981);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.plate {
|
||||
overflow: hidden;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: var(--el-text-color-primary);
|
||||
text-overflow: ellipsis;
|
||||
letter-spacing: 0.01em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
margin: 6px 0 10px;
|
||||
font-size: 12px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.nums {
|
||||
display: grid;
|
||||
@media (max-width: 1400px) {
|
||||
.fuel-plate-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
|
||||
b {
|
||||
display: block;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.03em;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.label {
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.mom {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-size: 11px;
|
||||
font-style: normal;
|
||||
font-weight: 650;
|
||||
overflow-wrap: anywhere;
|
||||
|
||||
&.up {
|
||||
color: #c2410c;
|
||||
}
|
||||
|
||||
&.down {
|
||||
color: var(--primary-dark, #059669);
|
||||
}
|
||||
|
||||
&.flat {
|
||||
font-weight: 500;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.metric-notices {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 1200px) {
|
||||
@media (max-width: 1100px) {
|
||||
.fuel-plate-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 640px) {
|
||||
@media (max-width: 720px) {
|
||||
.fuel-plate-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.fuel-plate-card {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--mint-border, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
border-color 0.15s ease,
|
||||
box-shadow 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: #a7f3d0;
|
||||
}
|
||||
|
||||
&.is-selected {
|
||||
border-color: #10b981;
|
||||
box-shadow: 0 0 0 1px #10b981;
|
||||
}
|
||||
}
|
||||
|
||||
.plate {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 24px;
|
||||
color: var(--mint-text, #0f172a);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin-top: 4px;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
}
|
||||
|
||||
.nums {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
|
||||
> div {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
b {
|
||||
display: block;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
line-height: 26px;
|
||||
color: var(--mint-text, #0f172a);
|
||||
}
|
||||
|
||||
.label {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-size: 11px;
|
||||
line-height: 16px;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,7 +2,14 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<section class="panel">
|
||||
<div v-if="!isMineMode" class="fuel-summary-pending">待开发</div>
|
||||
<FuelPlateMonthCards
|
||||
v-if="!isMineMode"
|
||||
:items="plateSummaryItems"
|
||||
:loading="plateSummaryLoading"
|
||||
:error="plateSummaryError"
|
||||
:selected-plate="selectedPlateFromFilter"
|
||||
@select="handlePlateCardSelect"
|
||||
/>
|
||||
|
||||
<div class="list-toolbar">
|
||||
<div class="list-toolbar-row">
|
||||
@@ -527,8 +534,10 @@ import {
|
||||
vehicleFuelRegisterApi,
|
||||
type PlanDocumentAttachmentItem,
|
||||
type Vehicle,
|
||||
type VehicleFuelPlateMonthItem,
|
||||
type VehicleFuelRegister
|
||||
} from '@/api/pl'
|
||||
import FuelPlateMonthCards from '@/views/pl/vehicle-fuel-register/FuelPlateMonthCards.vue'
|
||||
import { pickBxData, pickBxPageResult } from '@/utils/http/bx'
|
||||
import { fetchAllPagedRecords } from '@/utils/fetch-paged-list'
|
||||
import { fetchUserOptions } from '@/api/admin'
|
||||
@@ -663,6 +672,42 @@ const vehicleOptions = ref<Vehicle[]>([])
|
||||
const vehicleTrailerLookup = computed(() => buildVehicleTrailerLookup(vehicleOptions.value))
|
||||
const quickSearchKeyword = ref('')
|
||||
|
||||
const plateSummaryItems = ref<VehicleFuelPlateMonthItem[]>([])
|
||||
const plateSummaryLoading = ref(false)
|
||||
const plateSummaryError = ref('')
|
||||
|
||||
const selectedPlateFromFilter = computed(() => {
|
||||
const s = filters.licensePlate as { text?: string } | undefined
|
||||
return String(s?.text || '').trim()
|
||||
})
|
||||
|
||||
async function fetchPlateSummary() {
|
||||
if (isMineMode.value) return
|
||||
plateSummaryLoading.value = true
|
||||
plateSummaryError.value = ''
|
||||
try {
|
||||
const res = await vehicleFuelRegisterApi.plateMonthSummary()
|
||||
const data = (res as { data?: { items?: VehicleFuelPlateMonthItem[] } }).data ?? res
|
||||
plateSummaryItems.value = (data as { items?: VehicleFuelPlateMonthItem[] }).items || []
|
||||
} catch (e: unknown) {
|
||||
plateSummaryItems.value = []
|
||||
plateSummaryError.value =
|
||||
e && typeof e === 'object' && 'message' in e
|
||||
? String((e as { message?: string }).message || '加载车辆汇总失败')
|
||||
: '加载车辆汇总失败'
|
||||
} finally {
|
||||
plateSummaryLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function handlePlateCardSelect(plate: string | null) {
|
||||
if (!plate) {
|
||||
setFilterState('licensePlate', null)
|
||||
return
|
||||
}
|
||||
setFilterState('licensePlate', { text: plate, selected: [] })
|
||||
}
|
||||
|
||||
const fuelTableWrapRef = ref<HTMLElement | null>(null)
|
||||
const fuelBelowRef = ref<HTMLElement | null>(null)
|
||||
const fuelTableRef = ref<any>(null)
|
||||
@@ -1089,6 +1134,7 @@ async function handleSubmit() {
|
||||
}
|
||||
dialogVisible.value = false
|
||||
await fetchData()
|
||||
await fetchPlateSummary()
|
||||
if (editing) await refreshViewIfOpen(formData.id)
|
||||
await promptCopyAfterSave(saved, editing)
|
||||
} finally {
|
||||
@@ -1112,6 +1158,7 @@ async function handleCancel(row: VehicleFuelRegister) {
|
||||
)
|
||||
ElMessage.success('已作废')
|
||||
fetchData()
|
||||
fetchPlateSummary()
|
||||
} finally {
|
||||
cancelLoadingMap[row.id] = false
|
||||
}
|
||||
@@ -1149,6 +1196,7 @@ async function handleRestoreMany(rows: VehicleFuelRegister[]) {
|
||||
ElMessage.warning(`成功恢复 ${successCount} 条,${failedCount} 条失败`)
|
||||
}
|
||||
await fetchData()
|
||||
await fetchPlateSummary()
|
||||
} finally {
|
||||
restoreLoading.value = false
|
||||
for (const row of targets) restoreLoadingMap[row.id] = false
|
||||
@@ -1158,19 +1206,6 @@ async function handleRestoreMany(rows: VehicleFuelRegister[]) {
|
||||
onMounted(async () => {
|
||||
await Promise.all([loadVehicleOptions(), loadUserOptions()])
|
||||
fetchData()
|
||||
fetchPlateSummary()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.fuel-summary-pending {
|
||||
margin: 16px 16px 0;
|
||||
padding: 28px 16px;
|
||||
border: 1px dashed var(--mint-border, #e2e8f0);
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
color: var(--mint-text-muted, #64748b);
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user