Commit c97cb7ca by chenwq1

feat: 增强车辆检测评分功能与界面

- 新增评分回显接口类型定义,支持外观、骨架和内饰评分的详细信息。
- 更新 `getInspectionChildren` 和 `completeInspection` 函数,优化评分数据的处理与返回类型。
- 在 `car-detail` 组件中添加评分指引弹窗,提供评分标准与示例。
- 优化评分表单的交互逻辑,支持动态显示评分依据与参考信息。
- 增加对二级分组的支持,优化进度条显示逻辑。
1 parent 928d4a85
......@@ -181,12 +181,39 @@ export function getInspectionRootNodes(taskId: string | number) {
}
/**
* 检测评分回显(与 `completeInspection` 字段对应,接口可能省略部分字段)
*/
export interface InspectionScoreVO {
exteriorScore?: number | string | null;
exteriorComment?: string | null;
skeletonLevel?: string | null;
skeletonComment?: string | null;
interiorLevel?: string | null;
interiorComment?: string | null;
overallScore?: number | string | null;
overallComment?: string | null;
[key: string]: unknown;
}
/**
* `getInspectionChildren` 响应:
* - 普通节点:节点数组;
* - `rootNodeId === -1`(评分回显):多为 **单元素数组**,元素上挂 `inspectionScoreVO`;少数实现也可能返回顶层带 `inspectionScoreVO` 的对象
*/
export type InspectionChildrenData =
| InspectionNode[]
| {
inspectionScoreVO?: InspectionScoreVO | null;
[key: string]: unknown;
};
/**
* 获取检测模板子节点(二级项)
* @param rootNodeId 根节点ID
* @param rootNodeId 根节点ID;传 `-1` 时可拉取检测评分回显(`inspectionScoreVO`)
* @param taskId 检测工单ID
*/
export function getInspectionChildren(rootNodeId: string | number, taskId: string | number) {
return get<InspectionNode[]>(`/rest/inspectionNode/${rootNodeId}/children`, {
return get<InspectionChildrenData>(`/rest/inspectionNode/${rootNodeId}/children`, {
taskId,
});
}
......@@ -451,10 +478,16 @@ export interface CompleteInspectionParams {
overallComment: string;
}
/** `completeInspection` 成功时 `data`:有未完成项时带首项节点信息(多为大项 rootNodeId) */
export interface CompleteInspectionResultData {
firstUncompletedNodeId?: null | number | string;
firstUncompletedNodeName?: null | string;
}
/**
* 完成检测(提交检测评分)
*/
export function completeInspection(params: CompleteInspectionParams) {
return post<void>("/rest/inspectionRecord/completeInspection", params);
return post<CompleteInspectionResultData>("/rest/inspectionRecord/completeInspection", params);
}
......@@ -18,6 +18,8 @@ export interface BigModule {
key: number | string;
label: string;
nodeId?: number;
/** 是否存在二级分组 Tab;false 表示子节点直接为叶子(nodeType=3),不展示二级 Tab */
hasSecondaryTabs?: boolean;
subTabs: SubTab[];
}
......
<template>
<van-popup class="rating-guide-popup"
:close-on-click-overlay="true"
position="center"
round
:show="show"
@update:show="emit('update:show', $event)">
<div class="rating-guide">
<div class="rating-guide__header">
<span class="rating-guide__title">{{ config.title }}</span>
<van-icon class="rating-guide__close"
name="cross"
@click="emit('update:show', false)" />
</div>
<div class="rating-guide__scroll">
<div v-for="level in config.levels"
:key="level.grade"
class="rating-card">
<div class="rating-card__top">
<div class="rating-card__badge"
:style="{ background: gradeColor(level.grade) }">
{{ level.grade }}
</div>
<div class="rating-card__headline">
{{ level.grade }}级:{{ level.subtitle }}
</div>
</div>
<p class="rating-card__desc">
{{ level.description }}
</p>
<div class="rating-card__examples-label">
示例:
</div>
<ul class="rating-card__list">
<li v-for="(line, i) in level.examples"
:key="i"
class="rating-card__item">
{{ line }}
</li>
</ul>
</div>
</div>
</div>
</van-popup>
</template>
<script setup lang="ts">
import type { RatingGuideConfig, RatingGuideGrade } from "./rating-guide-content";
import { RATING_GUIDE_GRADE_COLORS } from "./rating-guide-content";
defineProps<{
config: RatingGuideConfig;
show: boolean;
}>();
const emit = defineEmits<{
"update:show": [value: boolean];
}>();
function gradeColor(grade: RatingGuideGrade): string {
return RATING_GUIDE_GRADE_COLORS[grade];
}
</script>
<style lang="scss" scoped>
.rating-guide-popup {
box-sizing: border-box;
width: calc(100vw - 48px);
max-width: 360px;
padding: 0;
overflow: hidden;
background: transparent;
}
.rating-guide {
display: flex;
flex-direction: column;
max-height: min(72vh, 560px);
padding: 20px 16px 16px;
background: #fff;
border-radius: 20px;
}
.rating-guide__header {
position: relative;
flex-shrink: 0;
padding: 0 28px 14px;
text-align: center;
}
.rating-guide__title {
font-size: 17px;
font-weight: 700;
color: #1a1a1a;
}
.rating-guide__close {
position: absolute;
top: 0;
right: 0;
padding: 4px;
font-size: 20px;
color: #969799;
cursor: pointer;
}
.rating-guide__scroll {
flex: 1;
min-height: 0;
padding-right: 4px;
margin-right: -4px;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
&::-webkit-scrollbar {
width: 4px;
}
&::-webkit-scrollbar-thumb {
background: rgb(0 0 0 / 15%);
border-radius: 4px;
}
}
.rating-card {
padding: 14px 12px;
margin-bottom: 12px;
background: #f2f2f7;
border-radius: 12px;
&:last-child {
margin-bottom: 0;
}
}
.rating-card__top {
display: flex;
gap: 10px;
align-items: flex-start;
margin-bottom: 8px;
}
.rating-card__badge {
display: flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
font-size: 15px;
font-weight: 700;
color: #fff;
border-radius: 6px;
}
.rating-card__headline {
flex: 1;
padding-top: 2px;
font-size: 16px;
font-weight: 700;
line-height: 1.35;
color: #1a1a1a;
}
.rating-card__desc {
margin: 0 0 10px;
font-size: 13px;
line-height: 1.5;
color: #333;
}
.rating-card__examples-label {
margin-bottom: 6px;
font-size: 12px;
font-weight: 500;
color: #666;
}
.rating-card__list {
padding: 0;
margin: 0;
list-style: none;
}
.rating-card__item {
position: relative;
padding-left: 12px;
margin-bottom: 6px;
font-size: 12px;
line-height: 1.45;
color: #666;
&:last-child {
margin-bottom: 0;
}
&::before {
position: absolute;
top: 6px;
left: 0;
width: 4px;
height: 4px;
content: "";
background: #c8c9cc;
border-radius: 50%;
}
}
</style>
......@@ -14,7 +14,7 @@
<span class="score-unit">分</span>
</div>
</div>
<div class="score-slider-wrap">
<div class="score-slider-wrap mb-[14px]">
<van-slider v-model="form.appearanceScore"
active-color="#185efe"
inactive-color="#e8edf5"
......@@ -23,14 +23,15 @@
:step="1" />
<div class="score-ticks">
<span>0</span>
<span>20</span>
<span>40</span>
<span>60</span>
<span>80</span>
<span>100</span>
</div>
</div>
</div>
<!-- 外观评级 -->
<div class="score-section">
<!-- 外观评级 -->
<div class="score-basis-label">
评分依据<span class="required-mark">*</span>
</div>
......@@ -40,13 +41,22 @@
placeholder="请查验外观主要划分级别。如:全车多处刮痕,右后侧碰撞有修复痕迹..."
:rows="3"
type="textarea" />
</div>
<!-- 骨架评级 -->
<div class="score-section">
<div class="score-section-header">
<span class="score-label">骨架评级<span class="required-mark">*</span></span>
<span class="score-ref">参考</span>
<span class="score-ref"
role="button"
tabindex="0"
@click="openRatingGuide('frame')"
@keydown.enter.prevent="openRatingGuide('frame')"
@keydown.space.prevent="openRatingGuide('frame')">
参考
</span>
</div>
<div class="rating-btns">
<div v-for="opt in RATING_OPTIONS"
......@@ -54,6 +64,11 @@
class="rating-btn"
:class="{ active: form.frameRating === opt }"
@click="form.frameRating = opt">
<span v-if="form.frameRating === opt"
aria-hidden="true"
class="rating-btn-check">
☑️
</span>
{{ opt }}
</div>
</div>
......@@ -72,7 +87,14 @@
<div class="score-section">
<div class="score-section-header">
<span class="score-label">内饰评级<span class="required-mark">*</span></span>
<span class="score-ref">参考</span>
<span class="score-ref"
role="button"
tabindex="0"
@click="openRatingGuide('interior')"
@keydown.enter.prevent="openRatingGuide('interior')"
@keydown.space.prevent="openRatingGuide('interior')">
参考
</span>
</div>
<div class="rating-btns">
<div v-for="opt in RATING_OPTIONS"
......@@ -80,6 +102,11 @@
class="rating-btn"
:class="{ active: form.interiorRating === opt }"
@click="form.interiorRating = opt">
<span v-if="form.interiorRating === opt"
aria-hidden="true"
class="rating-btn-check">
☑️
</span>
{{ opt }}
</div>
</div>
......@@ -108,7 +135,7 @@
<span class="score-unit">分</span>
</div>
</div>
<div class="score-slider-wrap">
<div class="score-slider-wrap mb-[14px]">
<van-slider v-model="form.overallScore"
active-color="#185efe"
inactive-color="#e8edf5"
......@@ -118,6 +145,10 @@
<div class="score-ticks">
<span>0</span>
<span>20</span>
<span>40</span>
<span>60</span>
<span>80</span>
<span>100</span>
</div>
</div>
<div class="score-basis-label">
......@@ -130,17 +161,40 @@
:rows="3"
type="textarea" />
</div>
<RatingGuideModal :config="ratingGuideConfig"
:show="ratingGuideOpen"
@update:show="onRatingGuideShow" />
</div>
</template>
<script setup lang="ts">
import type { CompleteInspectionParams } from "@api";
import type { ScoreRatingOption } from "@/types/views/car-detail";
import type {
CompleteInspectionParams,
InspectionChildrenData,
InspectionScoreVO,
} from "@api";
import type { RatingGuideConfig } from "./rating-guide-content";
import { reactive } from "vue";
import { reactive, ref, watch } from "vue";
import { SCORE_RATING_OPTIONS as RATING_OPTIONS, type ScoreRatingOption } from "@/types/views/car-detail";
import { SCORE_RATING_OPTIONS as RATING_OPTIONS } from "@/types/views/car-detail";
import { getInspectionChildren } from "@api";
import { isRequestFailureAlreadyHandled } from "@utils/request";
import { showToast } from "vant";
import { FRAME_RATING_GUIDE, INTERIOR_RATING_GUIDE } from "./rating-guide-content";
import RatingGuideModal from "./RatingGuideModal.vue";
const props = defineProps<{
/** 检测工单 ID,用于 `getInspectionChildren(-1)` 回显评分 */
taskId?: number | string;
}>();
const RATING_SET = new Set<string>(RATING_OPTIONS);
const form = reactive({
appearanceScore: 0,
appearanceBasis: "",
......@@ -152,6 +206,99 @@ const form = reactive({
overallRating: "",
});
const ratingGuideOpen = ref(false);
const ratingGuideConfig = ref<RatingGuideConfig>(FRAME_RATING_GUIDE);
function openRatingGuide(kind: "frame" | "interior") {
ratingGuideConfig.value = kind === "frame" ? FRAME_RATING_GUIDE : INTERIOR_RATING_GUIDE;
ratingGuideOpen.value = true;
}
function onRatingGuideShow(v: boolean) {
ratingGuideOpen.value = v;
}
function extractInspectionScoreVO(raw: InspectionChildrenData): InspectionScoreVO | null {
if (!raw || typeof raw !== "object") {
return null;
}
/** `rootNodeId === -1` 时接口常返回 `[{ id: -1, inspectionScoreVO: {...}, ... }]`,与单对象两种形态 */
if (Array.isArray(raw)) {
for (const item of raw) {
if (!item || typeof item !== "object") continue;
const vo = (item as { inspectionScoreVO?: unknown }).inspectionScoreVO;
if (vo && typeof vo === "object") {
return vo as InspectionScoreVO;
}
}
return null;
}
const vo = raw.inspectionScoreVO;
if (!vo || typeof vo !== "object") {
return null;
}
return vo;
}
function scoreFieldToNumber(value: unknown, fallback = 0): number {
if (value === null || value === undefined || value === "") {
return fallback;
}
const n = Number(value);
if (Number.isNaN(n)) {
return fallback;
}
return Math.min(100, Math.max(0, n));
}
function normalizeRatingLevel(value: unknown): "" | ScoreRatingOption {
const s = String(value ?? "")
.trim()
.toUpperCase();
if (RATING_SET.has(s)) {
return s as ScoreRatingOption;
}
return "";
}
function applyInspectionScoreVO(vo: InspectionScoreVO) {
form.appearanceScore = scoreFieldToNumber(vo.exteriorScore);
form.appearanceBasis = String(vo.exteriorComment ?? "").trim();
form.frameRating = normalizeRatingLevel(vo.skeletonLevel);
form.frameBasis = String(vo.skeletonComment ?? "").trim();
form.interiorRating = normalizeRatingLevel(vo.interiorLevel);
form.interiorBasis = String(vo.interiorComment ?? "").trim();
form.overallScore = scoreFieldToNumber(vo.overallScore);
form.overallRating = String(vo.overallComment ?? "").trim();
}
async function loadSavedInspectionScore() {
const tid = props.taskId;
if (tid === undefined || tid === null || tid === "") {
return;
}
try {
const raw = await getInspectionChildren(-1, tid);
const vo = extractInspectionScoreVO(raw);
if (vo) {
applyInspectionScoreVO(vo);
}
} catch (error) {
console.error("加载检测评分回显失败:", error);
if (!isRequestFailureAlreadyHandled(error)) {
showToast("加载历史评分失败");
}
}
}
watch(
() => props.taskId,
() => {
void loadSavedInspectionScore();
},
{ immediate: true },
);
function clampScoreFromInput(raw: string): number {
const digits = (raw.match(/\d/g) ?? []).join("");
if (digits === "") {
......@@ -210,17 +357,16 @@ defineExpose({ validate, getCompleteInspectionPayload });
.score-form {
display: flex;
flex-direction: column;
padding-top: 8px;
gap: 10px;
padding-bottom: 4px;
}
.score-section {
padding: 14px 0;
border-bottom: 1px solid #f2f3f7;
&:last-child {
padding-bottom: 4px;
border-bottom: none;
}
box-sizing: border-box;
padding: 14px 16px;
background: #ffffff;
border-radius: 8px;
opacity: 1;
}
.score-section-header {
......@@ -314,6 +460,7 @@ defineExpose({ validate, getCompleteInspectionPayload });
}
.rating-btn {
position: relative;
display: flex;
flex: 1;
align-items: center;
......@@ -324,15 +471,23 @@ defineExpose({ validate, getCompleteInspectionPayload });
cursor: pointer;
color: #999;
background: #f7f8fa;
border: 1.5px solid #e8e8e8;
border: 1px solid #e8e8e8;
border-radius: 8px;
transition: all 0.15s ease;
transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
&.active {
color: #fff;
background: #185efe;
border-color: #185efe;
box-shadow: 0 3px 8px rgb(24 94 254 / 30%);
color: #185efe;
background: #f7f8fa;
border: 1px solid #185efe;
}
.rating-btn-check {
position: absolute;
top: 2px;
right: 2px;
font-size: 10px;
line-height: 1;
pointer-events: none;
}
}
......
/** 检测评分:骨架 / 内饰评级指引文案(弹窗展示) */
export type RatingGuideGrade = "A" | "B" | "C" | "D";
export interface RatingGuideLevel {
grade: RatingGuideGrade;
/** 标题中「级」后的说明,如「无损伤」→ 展示为「A级:无损伤」 */
subtitle: string;
description: string;
examples: string[];
}
export interface RatingGuideConfig {
title: string;
levels: RatingGuideLevel[];
}
/** 各级徽章背景色(与设计稿一致) */
export const RATING_GUIDE_GRADE_COLORS: Record<RatingGuideGrade, string> = {
A: "#4CD964",
B: "#FFCC00",
C: "#FF9500",
D: "#FF3B30",
};
export const FRAME_RATING_GUIDE: RatingGuideConfig = {
title: "骨架评级指引",
levels: [
{
grade: "A",
subtitle: "无损伤",
description: "全车骨架无任何损伤、变形、切割或修复痕迹",
examples: ["所有结构件完整无缺", "无钣金修复痕迹", "无胶体异常", "无漆面异常"],
},
{
grade: "B",
subtitle: "轻微损伤",
description: "非关键部位有轻微变形或修复,主体结构完好",
examples: [
"翼子板骨架轻微变形",
"门板内侧小范围钣金修复",
"减震器支座轻微胶体异常",
"不影响安全性的小修复",
],
},
{
grade: "C",
subtitle: "中度损伤",
description: "关键部位有明显修复痕迹,但未伤及主体框架",
examples: [
"纵梁头部有钣金修复",
"A/B/C柱有喷漆痕迹",
"防火墙有变形修复",
"减震器支座有明显修复",
],
},
{
grade: "D",
subtitle: "重度损伤",
description: "主要结构件有切割、焊接、严重变形等重大修复",
examples: [
"纵梁切割或更换",
"A/B/C柱切割或严重变形",
"防火墙严重变形或切割",
"车身骨架整体修复",
],
},
],
};
export const INTERIOR_RATING_GUIDE: RatingGuideConfig = {
title: "内饰评级指引",
levels: [
{
grade: "A",
subtitle: "优秀",
description: "内饰整体状况优秀,无明显瑕疵",
examples: ["座椅、地毯、顶棚无污渍", "中控、仪表台无破损", "功能件全部正常", "无异味"],
},
{
grade: "B",
subtitle: "良好",
description: "内饰整体良好,有轻微使用痕迹",
examples: ["座椅有轻微磨损", "地毯有小范围污渍", "方向盘有轻微磨损", "无破损,功能正常"],
},
{
grade: "C",
subtitle: "一般",
description: "内饰有明显使用痕迹或局部破损",
examples: [
"座椅有明显磨损或污渍",
"顶棚有下垂或水渍",
"中控有破损或部件缺失",
"有轻微异味",
],
},
{
grade: "D",
subtitle: "较差",
description: "内饰状况较差,有严重破损或污损",
examples: ["座椅破损或塌陷", "顶棚严重下垂", "大面积烧烫或水渍", "有明显异味"],
},
],
};
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!