Commit bac48d50 by wangzhihui

Merge branch 'release/venus-usedcar-h5/1.0.0' of http://192.168.3.233:8090/monor…

…epo/venus into release/venus-usedcar-h5/1.0.0
2 parents 95d26196 21e9265f
Pipeline #100 for bac48d50 failed in 0 seconds
......@@ -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,
});
}
......@@ -230,6 +257,29 @@ function hasDefaultValueFlag(node: InspectionNode): boolean {
return String(node.existsDefaultValue ?? "") === "1";
}
const KEYED_SELECT_INTERACTION_TYPES = new Set([
"dropdown",
"button_select",
"radio_button_select",
]);
function isKeyedSelectInteractionType(interactionType: string | undefined): boolean {
if (!interactionType) return false;
return KEYED_SELECT_INTERACTION_TYPES.has(interactionType);
}
/** 将模板默认值如 `2-私户` 按首个 `-` 拆成 key / 展示文案 */
function parseKeyedSelectDefault(raw: string): { valueKey: string; valueText: string } {
const i = raw.indexOf("-");
if (i === -1) {
return { valueKey: "", valueText: raw };
}
return {
valueKey: raw.slice(0, i),
valueText: raw.slice(i + 1),
};
}
/**
* 解析叶子节点默认值对应的文案列表(可多值,与 inspectionValueList 一一对应)
* - defaultType 1:固定值,取 defaultValue
......@@ -266,15 +316,21 @@ export function resolveInspectionNodeInitialValueTexts(
}
function buildInspectionResultVOFromDefaults(node: InspectionNode, valueTexts: string[]): InspectionResultVO {
const inspectionValueList: InspectionValueItem[] = valueTexts.map((valueText, index) => ({
id: 0,
resultId: 0,
valueKey: "",
valueText,
interactionType: node.interactionType ?? "",
valueSeq: index,
remark: "",
}));
const keyed = isKeyedSelectInteractionType(node.interactionType);
const inspectionValueList: InspectionValueItem[] = valueTexts.map((raw, index) => {
const { valueKey, valueText } = keyed
? parseKeyedSelectDefault(raw)
: { valueKey: "", valueText: raw };
return {
id: 0,
resultId: 0,
valueKey,
valueText,
interactionType: node.interactionType ?? "",
valueSeq: index,
remark: "",
};
});
return {
id: 0,
recordId: 0,
......@@ -318,18 +374,48 @@ export function applyResolvedInitialValuesToLeafNodes(
return { ...node };
}
const resolvedInitialValue = valueTexts.length === 1 ? valueTexts[0] : valueTexts.join(", ");
return {
const inspectionResultVO = buildInspectionResultVOFromDefaults(node, valueTexts);
const list = inspectionResultVO.inspectionValueList ?? [];
const merged: InspectionNode = {
...node,
resolvedInitialValue,
inspectionResultVO: buildInspectionResultVOFromDefaults(node, valueTexts),
inspectionResultVO,
};
if (!isKeyedSelectInteractionType(node.interactionType) || list.length === 0) {
return merged;
}
const first = list[0]!;
const it = node.interactionType ?? "";
const valueKey = first.valueKey ?? "";
const valueText = first.valueText ?? "";
if (it === "dropdown" || it === "radio_button_select") {
return {
...merged,
valueKey,
valueText,
value: valueKey,
};
}
if (it === "button_select") {
return {
...merged,
valueKey,
valueText,
value: JSON.stringify(
list.map((row) => ({
valueKey: row.valueKey ?? "",
valueText: row.valueText ?? "",
}))
),
};
}
return merged;
});
}
// ===== 检测记录保存 =====
export interface LeafNodeValue {
id: number;
valueText: string;
valueKey: string;
interactionType: string;
......@@ -349,8 +435,8 @@ export interface InspectionRecordSaveParams {
taskId: number | string;
/** 大项 nodeId */
locationModule: number | string;
/** 二级项 nodeId */
locationSubModule: number | string;
/** 二级项 nodeId;无二级分组时为 null */
locationSubModule: number | string | null;
/** true = 保存并跳下一步,false = 仅保存 */
nextFlag: boolean;
leafNodes: LeafNodeRecord[];
......@@ -392,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);
}
......@@ -9,7 +9,6 @@ import buttonSelect from "@/components/customizeForm/buttonSelect.vue";
import radioSelect from "@/components/customizeForm/radioSelect.vue";
import customizeUploadFile from "@/components/customizeForm/customizeUploadFile.vue";
// 获取父组件传递数据
const props = withDefaults(
defineProps<{
......@@ -37,100 +36,70 @@ watch(() => props.leafNodes, (nodes) => {
// 提交数据
function setSubmitData() {
let dataList: never[] = [];
let returnData: never[] = [];
columnsList.value.forEach((item: any) => {
let itemData: any = {};
let dataList: never[] = [];
const inputList = ['text_input', 'textarea_input', 'number_input', 'date_picker'];
const dropdownList = ['dropdown', 'radio_button_select'];
if (inputList.includes(item.interactionType)) {
itemData = {
if (inputList.includes(item.interactionType) && item.value != null && item.value !== "") {
const pushData = {
id: item.id,
valueText: item.value || '',
valueKey: item.value || '',
valueKey: '',
interactionType: item.interactionType,
remark: item.remark || '',
}
} else if (dropdownList.includes(item.interactionType)) {
itemData = {
dataList.push(pushData);
} else if (dropdownList.includes(item.interactionType) && item.valueKey) {
const pushData = {
id: item.id,
valueText: item.valueText || '',
valueKey: item.valueKey || '',
interactionType: item.interactionType,
remark: item.remark || '',
}
dataList.push(pushData);
} else if (item.interactionType == 'button_select') {
const valueList = JSON.parse(item.value || '[]');
if (valueList && valueList.length > 0) {
for (let i = 0; i < valueList.length; i++) {
const foritemData = {
const pushData = {
id: item.id,
valueText: valueList[i].valueText || '',
valueKey: valueList[i].valueKey || '',
interactionType: item.interactionType,
remark: item.remark || '',
valueSeq: i + 1,
}
dataList.push(foritemData);
}
} else {
itemData = {
id: item.id,
valueText: item.valueText || '',
valueKey: item.valueKey || '',
interactionType: item.interactionType,
remark: item.remark || '',
dataList.push(pushData);
}
dataList.push(itemData);
}
} else if (item.interactionType == 'image_upload' || item.interactionType == 'video_upload') {
const valueList = JSON.parse(item.value || '[]');
if (valueList && valueList.length > 0) {
for (let i = 0; i < valueList.length; i++) {
const foritemData = {
const pushData = {
id: item.id,
valueText: valueList[i] || '',
valueKey: valueList[i] || '',
valueKey: '',
interactionType: item.interactionType,
remark: item.remark || '',
valueSeq: i + 1,
}
dataList.push(foritemData);
}
} else {
itemData = {
id: item.id,
valueText: item.valueText || '',
valueKey: item.valueKey || '',
interactionType: item.interactionType,
remark: item.remark || '',
dataList.push(pushData);
}
dataList.push(itemData);
}
} else {
itemData = {
id: item.id,
valueText: item.valueText || '',
valueKey: item.valueKey || '',
interactionType: item.interactionType,
remark: item.remark || '',
}
}
if (item.interactionType != 'button_select' && item.interactionType != 'image_upload' && item.interactionType != 'video_upload') {
dataList.push(itemData);
}
// 每项都入列,便于大项/二级切换时静默保存仍能带上当前 Tab 全部叶子(未填则为空 data,仍会走保存接口)
returnData.push({
nodeId: item.id,
nodeName: item.nodeName,
resultStatus: resultStatus.value ? 3 : 1,
remark: "",
data: dataList,
});
});
return {
nodeId: columnsList.value[0].parentId || '', //节点 ID(inspection_node_version.nodeId,叶子节点)
nodeName: props.subTabLabel,//节点名称(快照)
resultStatus: resultStatus.value ? 3 : 1,//结果状态:1-正常,2-故障,3-无此结构
remark: '',//备注
data: dataList,
};
return returnData;
}
async function validate(): Promise<CustomizeFormValidateResult> {
const nodesData = setSubmitData();
console.log('validate', nodesData);
let success = true;
let message = '';
columnsList.value.forEach((item: any) => {
......@@ -149,7 +118,6 @@ async function validate(): Promise<CustomizeFormValidateResult> {
/** 与 `validate` 相同返回结构,不校验必填,用于静默保存 / 上一步等场景 */
async function saveData(): Promise<CustomizeFormValidateResult> {
const nodesData = setSubmitData();
console.log('saveData', nodesData);
return {
data: nodesData,
message: "操作成功",
......@@ -172,7 +140,7 @@ defineExpose({
<div>
<van-form ref="customizeFormRef" :model="form" :rules="rules">
<div class="formTitle">
<div>{{ subTabLabel }}</div>
<!-- <div>{{ subTabLabel }}</div> -->
<div v-if="allowNoStructure" class="formRadio" @click="resultStatus = !resultStatus">
<van-icon v-if="!resultStatus" name="circle" size="14" color="#666666" />
<van-icon v-if="resultStatus" name="checked" size="14" color="#185EFE" />
......
......@@ -18,6 +18,8 @@ export interface BigModule {
key: number | string;
label: string;
nodeId?: number;
/** 是否存在二级分组 Tab;false 表示子节点直接为叶子(nodeType=3),不展示二级 Tab */
hasSecondaryTabs?: boolean;
subTabs: SubTab[];
}
......@@ -30,22 +32,28 @@ export interface InspectSubContentExpose {
collectData(validate: boolean): Promise<LeafNodeRecord[] | null>;
}
/** 中间表单 validate 返回体 */
/** 中间表单 validate / saveData 单列;`id` 为模板字段,仅作前端对齐,提交 saveInspectionRecord 时在 car-detail 映射中省略 */
export interface CustomizeFormValidateFieldItem {
id?: number;
interactionType?: string;
remark?: string;
valueKey?: string;
valueSeq?: number;
valueText?: string;
}
/** 中间表单 validate / saveData 下单个叶子节点(与 `setSubmitData` 一项一致) */
export interface CustomizeFormValidateNode {
nodeId: number | string;
nodeName: string;
resultStatus: number;
remark: string;
data: CustomizeFormValidateFieldItem[];
}
/** 中间表单 validate / saveData 返回体;`data` 为当前二级下多列叶子节点数组 */
export interface CustomizeFormValidateResult {
success: boolean;
message?: string;
data?: {
data: Array<{
id: number;
interactionType?: string;
remark?: string;
valueKey?: string;
valueSeq?: number;
valueText?: string;
}>;
nodeId: number | string;
nodeName: string;
remark: string;
resultStatus: number;
};
data?: CustomizeFormValidateNode[];
}
<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: ["座椅破损或塌陷", "顶棚严重下垂", "大面积烧烫或水渍", "有明显异味"],
},
],
};
......@@ -16,8 +16,8 @@
size="13" />
</div>
</div>
<!-- 第二行:进度条(检测评分页不显示) -->
<div v-if="activeBigKey !== SCORE_BIG_KEY"
<!-- 第二行:进度条(检测评分页、无二级大项不显示) -->
<div v-if="showInspectionProgressBar"
class="inspect-progress-bar">
<van-progress class="progress-track"
color="#185efe"
......@@ -55,24 +55,26 @@
</div>
<!-- 检测评分大项:全屏评分表单,无二级 Tab,无进度条 -->
<div v-else-if="activeBigKey === SCORE_BIG_KEY"
class="inspect-card">
<div class="inspect-content">
<ScoreForm ref="inspectionScoreFormRef" />
class="inspect-card inspect-card--score">
<div class="inspect-content inspect-content--score">
<ScoreForm ref="inspectionScoreFormRef"
:task-id="taskId" />
</div>
</div>
<!-- 普通大项:二级 Tab + 内容区 -->
<!-- 普通大项:可选二级 Tab + 内容区 -->
<div v-else
class="inspect-card inspect-card--subtabs">
<!-- 二级项 Tab(相对表单区固定:表单在 .inspect-subtab-scroll 内滚动) -->
<div class="subtab-row">
<!-- 二级项 Tab:仅当子节点为分组(nodeType=2)等多级结构时展示;叶子直挂大项时不展示 -->
<div v-if="activeBigModule?.hasSecondaryTabs === true"
class="subtab-row">
<div v-for="subTab in activeBigModule?.subTabs"
:key="subTab.key"
class="subtab-item"
:class="{ active: subTab.key === activeSubKey, completed: subTab.completedFlag === 1 }"
:class="{ active: subTab.key === activeSubKey, completed: isCompletedFlagFieldDone(subTab.completedFlag) }"
@click="onSelectSubTab(subTab.key)">
{{ subTab.label }}
<van-icon v-if="subTab.completedFlag === 1"
<van-icon v-if="isCompletedFlagFieldDone(subTab.completedFlag)"
class="subtab-done-icon"
color="#27CD5A"
name="checked" />
......@@ -84,7 +86,7 @@
:active-sub-tab="activeBigModule"
:big-module-label="activeBigModule?.label"
:leaf-nodes="currentLeafNodes"
:sub-tab-label="activeSubTab?.label" />
:sub-tab-label="activeSubTab?.label" />
</div>
</div>
</div>
......@@ -103,9 +105,10 @@
提交评分
</van-button>
</template>
<!-- 普通检测页:上一步 + 下一步/提交检测内容 -->
<!-- 普通检测页:有二级时上一步 + 下一步;无二级时仅完成检测(全宽) -->
<template v-else>
<van-button class="btn-save"
<van-button v-if="activeBigModule?.hasSecondaryTabs !== false"
class="btn-save"
:loading="submitting"
plain
round
......@@ -120,7 +123,13 @@
round
type="primary"
@click="onNext">
{{ remainingSubTabCount === 1 ? "提交检测内容" : "下一步" }}
{{
activeBigModule?.hasSecondaryTabs === false
? "完成检测"
: remainingSubTabCount === 1
? "提交检测内容"
: "下一步"
}}
</van-button>
</template>
</div>
......@@ -146,8 +155,17 @@
</template>
<script setup lang="ts">
import type { BigModule, CustomizeFormValidateResult } from "@/types/views/car-detail";
import type { InspectionTemplateDefaultData, LeafNodeRecord } from "@api";
import type {
BigModule,
CustomizeFormValidateNode,
CustomizeFormValidateResult,
} from "@/types/views/car-detail";
import type {
CompleteInspectionResultData,
InspectionResultVO,
InspectionTemplateDefaultData,
LeafNodeRecord,
} from "@api";
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
......@@ -170,6 +188,16 @@ import ScoreForm from "./components/ScoreForm.vue";
/** 检测评分大项的固定 key(非接口返回,手动追加至大项末尾) */
const SCORE_BIG_KEY = "__score_big__";
/** 与接口一致:0 / "0" 未完成,1 / "1" 已完成 */
function isInspectionVoCompleted(vo: InspectionResultVO | undefined): boolean {
return vo?.completedFlag === 1 || String(vo?.completedFlag ?? "") === "1";
}
/** `completedFlag` 字段可能是数字或字符串,进度与 Tab 勾选统一用此判断 */
function isCompletedFlagFieldDone(flag: unknown): boolean {
return flag === 1 || String(flag ?? "") === "1";
}
// ===== 状态 =====
const router = useRouter();
const route = useRoute();
......@@ -194,6 +222,13 @@ const isSubtabInspectionView = computed(
() => !loading.value && bigModules.value.length > 0 && activeBigKey.value !== SCORE_BIG_KEY
);
/** 无二级大项不展示「检测进度」条(与检测评分页一致仅隐藏条,不改动其它逻辑) */
const showInspectionProgressBar = computed(
() =>
activeBigKey.value !== SCORE_BIG_KEY &&
activeBigModule.value?.hasSecondaryTabs !== false,
);
const activeSubKey = ref<number | string>("");
/** 不含「检测评分」的大项(接口大项),用于进度与步骤导航 */
......@@ -209,7 +244,7 @@ const flattenedMainSubTabs = computed(() =>
const progressTotal = computed(() => flattenedMainSubTabs.value.length);
const progressDone = computed(() =>
flattenedMainSubTabs.value.filter((subTab) => subTab.completedFlag === 1).length
flattenedMainSubTabs.value.filter((subTab) => isCompletedFlagFieldDone(subTab.completedFlag)).length
);
/** 仍未完成的二级项数量(用于底部按钮文案) */
......@@ -224,6 +259,8 @@ const activeSubTab = computed(
/** 当前二级项下的叶子节点(loadSubTabsForBigModule 内已合并模板默认值) */
const currentLeafNodes = computed(() => activeSubTab.value?.leafNodes ?? []);
// ===== 初始化 =====
async function initializeInspection() {
try {
......@@ -268,7 +305,11 @@ async function initializeInspection() {
}
// ===== 加载某大项下的二级项 =====
async function loadSubTabsForBigModule(bigModuleKey: number | string) {
/**
* @param bigModuleKey 大项 id
* @param syncSelection 为 false 时只拉取/填充 subTabs,不改当前 activeSubKey(用于后台匹配节点)
*/
async function loadSubTabsForBigModule(bigModuleKey: number | string, syncSelection = true) {
if (bigModuleKey === SCORE_BIG_KEY) return;
try {
......@@ -276,11 +317,17 @@ async function loadSubTabsForBigModule(bigModuleKey: number | string) {
if (!targetBigModule) return;
if (targetBigModule.subTabs.length > 0) {
activeSubKey.value = targetBigModule.subTabs[0]!.key;
if (syncSelection) {
activeSubKey.value = targetBigModule.subTabs[0]!.key;
}
return;
}
const childLevelNodes = await getInspectionChildren(bigModuleKey, taskId.value);
const list = Array.isArray(childLevelNodes) ? childLevelNodes : [];
const firstChild = list[0];
/** 1-模块 2-分组 3-叶子:首项为叶子时表示无二级分组,子节点直挂大项 */
const isDirectLeafChildren = firstChild !== undefined && firstChild.nodeType === 3;
let templateDefaultData: InspectionTemplateDefaultData | null = null;
try {
......@@ -289,15 +336,32 @@ async function loadSubTabsForBigModule(bigModuleKey: number | string) {
console.error("获取模板默认值失败:", error);
}
targetBigModule.subTabs = (childLevelNodes || []).map((node) => ({
key: node.id,
label: node.nodeName,
nodeId: node.id,
leafNodes: applyResolvedInitialValuesToLeafNodes(node.childrenNodes, templateDefaultData),
completedFlag: node.inspectionResultVO?.completedFlag ?? 0,
}));
if (isDirectLeafChildren) {
targetBigModule.hasSecondaryTabs = false;
const leafNodes = applyResolvedInitialValuesToLeafNodes(list, templateDefaultData);
const allDone = list.every((n) => isInspectionVoCompleted(n.inspectionResultVO));
targetBigModule.subTabs = [
{
key: "__flat_leaf__",
label: targetBigModule.label,
nodeId: targetBigModule.nodeId,
leafNodes,
completedFlag: allDone ? 1 : 0,
},
];
} else {
targetBigModule.hasSecondaryTabs = true;
/** 进度与 Tab 完成态:按同级二级节点自身 `inspectionResultVO.completedFlag`,与叶子 VO 无关 */
targetBigModule.subTabs = list.map((node) => ({
key: node.id,
label: node.nodeName,
nodeId: node.id,
leafNodes: applyResolvedInitialValuesToLeafNodes(node.childrenNodes, templateDefaultData),
completedFlag: isInspectionVoCompleted(node.inspectionResultVO) ? 1 : 0,
}));
}
if (targetBigModule.subTabs.length > 0) {
if (targetBigModule.subTabs.length > 0 && syncSelection) {
activeSubKey.value = targetBigModule.subTabs[0]!.key;
}
} catch (error) {
......@@ -306,6 +370,46 @@ async function loadSubTabsForBigModule(bigModuleKey: number | string) {
}
}
/** 提交评分返回里是否仍有未完成项(`firstUncompletedNodeId` 有有效值) */
function hasCompleteInspectionUncompletedHint(data: CompleteInspectionResultData | undefined): boolean {
if (!data) return false;
const id = data.firstUncompletedNodeId;
if (id === undefined || id === null) return false;
if (typeof id === "string" && id.trim() === "") return false;
return true;
}
/**
* 根据未完成节点 ID 切换大项(优先匹配 root);匹配不到则尝试已加载的二级项 nodeId。
*/
async function switchToUncompletedInspectionNode(nodeId: number | string): Promise<boolean> {
const idStr = String(nodeId);
const mains = mainInspectionBigModules.value;
const rootHit = mains.find(
(m) => String(m.key) === idStr || String(m.nodeId ?? "") === idStr,
);
if (rootHit) {
activeBigKey.value = rootHit.key;
await loadSubTabsForBigModule(rootHit.key);
activeSubKey.value = rootHit.subTabs[0]?.key ?? "";
return true;
}
for (const m of mains) {
await loadSubTabsForBigModule(m.key, false);
const sub = m.subTabs.find(
(s) => String(s.key) === idStr || String(s.nodeId ?? "") === idStr,
);
if (sub) {
activeBigKey.value = m.key;
activeSubKey.value = sub.key;
return true;
}
}
return false;
}
// ===== 事件处理 =====
function onOpenModulePicker() {
showModulePicker.value = true;
......@@ -313,10 +417,12 @@ function onOpenModulePicker() {
/** 构造 `saveInspectionRecord` 请求体 */
function buildInspectionSavePayload(leafNodes: LeafNodeRecord[], nextFlag: boolean) {
const hasSecondaryTabs = activeBigModule.value?.hasSecondaryTabs === true;
return {
taskId: taskId.value,
locationModule: activeBigModule.value?.nodeId ?? 0,
locationSubModule: activeSubTab.value?.nodeId ?? 0,
/** 叶子直挂大项(无二级分组)时后端约定传 null,不用与大项重复的 nodeId */
locationSubModule: hasSecondaryTabs ? (activeSubTab.value?.nodeId ?? 0) : null,
nextFlag,
leafNodes,
};
......@@ -349,11 +455,9 @@ function advanceInspectionStep() {
}
}
function leafRecordFromValidateData(raw: CustomizeFormValidateResult["data"]): LeafNodeRecord | null {
if (!raw) return null;
function leafRecordFromValidateNode(raw: CustomizeFormValidateNode): LeafNodeRecord {
return {
data: (raw.data ?? []).map((item) => ({
id: item.id,
interactionType: item.interactionType ?? "",
remark: item.remark ?? "",
valueKey: item.valueKey ?? "",
......@@ -370,9 +474,11 @@ function leafRecordFromValidateData(raw: CustomizeFormValidateResult["data"]): L
/** `saveData` → 转叶子记录 → `saveInspectionRecord`;无有效数据时不请求接口 */
async function saveCurrentLeafInspectionRecord(nextFlag: boolean): Promise<boolean> {
const saved = (await customizeFormRef.value?.saveData?.()) as CustomizeFormValidateResult | undefined;
const record = saved?.data ? leafRecordFromValidateData(saved.data) : null;
if (!record) return false;
await saveInspectionRecord(buildInspectionSavePayload([record], nextFlag));
const rows = saved?.data;
console.log("saveCurrentLeafInspectionRecord", rows);
if (!rows?.length) return false;
const leafNodes = rows.map((row) => leafRecordFromValidateNode(row));
await saveInspectionRecord(buildInspectionSavePayload(leafNodes, nextFlag));
return true;
}
......@@ -482,9 +588,21 @@ async function onSubmitScore() {
if (submitting.value) return;
try {
submitting.value = true;
await completeInspection(
const result = await completeInspection(
inspectionScoreFormRef.value.getCompleteInspectionPayload(taskId.value),
);
if (result && hasCompleteInspectionUncompletedHint(result)) {
const name = result.firstUncompletedNodeName;
const nid = result.firstUncompletedNodeId;
showToast(
name ? `检测未完成,请先完成「${name}」` : "检测未完成,请先完成未填项",
);
const switched = nid !== undefined && nid !== null && (await switchToUncompletedInspectionNode(nid));
if (!switched) {
showToast("未找到对应检测模块,请手动切换大项");
}
return;
}
showToast("评分已提交");
} catch (error) {
if (!isRequestFailureAlreadyHandled(error)) {
......@@ -615,6 +733,18 @@ onMounted(() => {
border-radius: 12px;
}
// 检测评分:内层为多块白卡片,外层透出页面灰底以形成模块间距
.inspect-card--score {
background: transparent;
border-color: transparent;
border-radius: 0;
box-shadow: none;
}
.inspect-content--score {
padding-top: 10px;
}
// 与二级 Tab + 表单配套:占满 .inspect-body 剩余高度,便于内层滚动
.inspect-card--subtabs {
flex: 1;
......
<script setup lang="ts">
import type { CardAction, WorkOrderItem } from "@/types/views/home";
import type { AuditStatus, WorkOrderStatus } from "@/types/views/work-order-common";
import { computed, ref, watch } from "vue";
import { useRouter } from "vue-router";
import { getWorkOrderCountByStatus, getWorkOrderPage } from "@/api/modules/work-order";
import PageTop from "@/components/PageTop.vue";
import WorkOrderStatusTags from "@/components/WorkOrderStatusTags.vue";
import type { CardAction, WorkOrderItem } from "@/types/views/home";
import type { AuditStatus, WorkOrderStatus } from "@/types/views/work-order-common";
import { showToast } from "vant";
const keyword = ref("");
......@@ -135,7 +136,7 @@ function startCheck(item: WorkOrderItem) {
}
function continueCheck(item: WorkOrderItem) {
void router.push({ name: "CarDetail", params: { taskId: item.id } });
void router.push({ name: "CarDetail", params: { id: item.id } });
}
function editCheck(item: WorkOrderItem) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!