feat(pl): 加油汇总顶部改为近10/20/30次平均油耗。
按相邻登记的升数与期初公里差计算 L/100km,并恢复汇总页车牌卡片展示。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
90fc25f3fe
commit
c658f78329
12 files changed
+352
-276
No files matched your search
@@ -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