Commit eec22dc5 by yancanhua

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 371a56c4 36f81cbd
Pipeline #77 for eec22dc5 failed in 0 seconds
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
<meta name="apple-mobile-web-app-status-bar-style" content="default" /> <meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<title>二手车</title> <title>二手车</title>
<!-- 微信 JSSDK:小程序 webview 通信必需 -->
<script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
<!-- UniApp WebView Bridge:uniapp 容器通信必需 -->
<script src="https://gitcode.com/dcloud/uni-app/raw/dev/dist/uni.webview.1.5.6.js"></script>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
......
import { post } from "@utils/request"; import { get, post } from "@utils/request";
export interface InspectReportPageParams { export interface InspectReportPageParams {
size: number; size: number;
...@@ -100,3 +100,216 @@ export function getInspectReportPage(params: InspectReportPageParams) { ...@@ -100,3 +100,216 @@ export function getInspectReportPage(params: InspectReportPageParams) {
return post<InspectReportPageResult>("/rest/inspect/report/page", params); return post<InspectReportPageResult>("/rest/inspect/report/page", params);
} }
// 检测模板相关接口
export interface InspectionResultVO {
/** 完成标志:0 未完成,1 已完成 */
completedFlag: 0 | 1;
[key: string]: unknown;
}
export interface InspectionNode {
id: number;
templateId: number;
parentId: number;
nodeCode?: string;
nodeName: string;
nodeType: number;
showNodeName: string;
editPermission?: string;
displayMode?: number;
itemType: number;
interactionType?: string;
dataFormat?: string;
placeholder?: string;
required?: number;
optionsSourceType?: number;
options?: string;
validationRules?: string;
allowNoStructure?: number;
existsDefaultValue?: string | number;
defaultValue?: string;
defaultType?: number;
nodeLevel: number;
sortOrder: number;
status: number;
remark?: string;
createTime?: string;
/** 检测结果(含完成标志) */
inspectionResultVO?: InspectionResultVO;
/** 子节点列表(nodeType=2 的节点下挂 nodeType=3 的叶子节点) */
childrenNodes?: InspectionNode[];
/**
* 前端根据 existsDefaultValue / defaultType 解析后的初始值
* (defaultType=2 时从 getInspectionTemplateDefault 的 data[nodeCode] 映射)
*/
resolvedInitialValue?: string;
[key: string]: unknown;
}
export interface InspectionNodeResponse {
code: string;
data: InspectionNode[];
success: boolean;
message: string;
}
/**
* 获取检测模板根节点(大项)
* @param taskId 检测工单ID
*/
export function getInspectionRootNodes(taskId: string | number) {
return get<InspectionNode[]>(`/rest/inspectionTemplate/${taskId}/rootNodes`);
}
/**
* 获取检测模板子节点(二级项)
* @param rootNodeId 根节点ID
* @param taskId 检测工单ID
*/
export function getInspectionChildren(rootNodeId: string | number, taskId: string | number) {
return get<InspectionNode[]>(`/rest/inspectionNode/${rootNodeId}/children`, {
taskId,
});
}
/** getInspectionTemplateDefault 返回的 data 结构(字段与 nodeCode 对应,可扩展) */
export interface InspectionTemplateDefaultData {
keyCount?: string;
carBrand?: string;
exteriorColor?: string;
compulsoryInsuranceExpiry?: string;
engineNumber?: string;
handoverAddress?: string;
sourceNo?: string;
seat?: string;
licensePlate?: string;
carSeriesId?: string;
productionDate?: string;
annualInspectionExpiry?: string;
registrationDate?: string;
vin?: string;
displacement?: string;
emissionStandard?: string;
carSeriesName?: string;
mileage?: string;
usageType?: string;
[key: string]: unknown;
}
/**
* 获取检测模板默认值(业务层已解包为 data 对象)
* @param taskId 检测工单ID
*/
export function getInspectionTemplateDefault(taskId: string | number) {
return post<InspectionTemplateDefaultData>(`/rest/inspectionTemplate/default`, {
taskId,
});
}
/** 是否存在默认值:1-存在 0-不存在 */
function hasDefaultValueFlag(node: InspectionNode): boolean {
return String(node.existsDefaultValue ?? "") === "1";
}
/**
* 解析单个叶子节点的初始值
* - defaultType 1:固定值,取 defaultValue
* - defaultType 2:接口值,用 nodeCode 从 templateDefaultData 取字段
* - defaultType 3:表达式(暂未约定,返回 undefined)
*/
export function resolveInspectionNodeInitialValue(
node: InspectionNode,
templateDefaultData: InspectionTemplateDefaultData | null | undefined
): string | undefined {
if (!hasDefaultValueFlag(node)) return undefined;
const type = node.defaultType;
if (type === 1) {
return node.defaultValue ?? "";
}
if (type === 2) {
const code = node.nodeCode;
if (!code || !templateDefaultData) return undefined;
const raw = (templateDefaultData as Record<string, unknown>)[code];
if (raw === undefined || raw === null) return undefined;
return String(raw);
}
if (type === 3) {
// 表达式:待后端约定格式后再实现
return undefined;
}
// 未带 defaultType 时兜底用 defaultValue
return node.defaultValue ?? undefined;
}
/** 为二级项下的叶子节点列表写入 resolvedInitialValue */
export function applyResolvedInitialValuesToLeafNodes(
leafNodes: InspectionNode[] | undefined,
templateDefaultData: InspectionTemplateDefaultData | null | undefined
): InspectionNode[] {
if (!leafNodes?.length) return [];
return leafNodes.map((node) => ({
...node,
resolvedInitialValue: resolveInspectionNodeInitialValue(node, templateDefaultData),
}));
}
// ===== 检测记录保存 =====
export interface LeafNodeValue {
id: number;
valueText: string;
valueKey: string;
interactionType: string;
valueSeq: number;
remark: string;
}
export interface LeafNodeRecord {
nodeId: number;
nodeName: string;
resultStatus: number;
remark: string;
data: LeafNodeValue[];
}
export interface InspectionRecordSaveParams {
taskId: number | string;
/** 大项 nodeId */
locationModule: number | string;
/** 二级项 nodeId */
locationSubModule: number | string;
/** true = 保存并跳下一步,false = 仅保存 */
nextFlag: boolean;
leafNodes: LeafNodeRecord[];
}
/**
* 保存/下一步
*/
export function saveInspectionRecord(params: InspectionRecordSaveParams) {
return post<void>("/rest/inspectionRecord/save", params);
}
// ===== 完成检测(检测评分提交)=====
export interface CompleteInspectionParams {
taskId: number | string;
exteriorScore: number;
exteriorComment: string;
skeletonLevel: string;
skeletonComment: string;
interiorLevel: string;
interiorComment: string;
overallScore: number;
overallComment: string;
}
/**
* 完成检测(提交检测评分)
*/
export function completeInspection(params: CompleteInspectionParams) {
return post<void>("/rest/inspectionRecord/completeInspection", params);
}
...@@ -7,11 +7,14 @@ export {} ...@@ -7,11 +7,14 @@ export {}
declare module 'vue' { declare module 'vue' {
export interface GlobalComponents { export interface GlobalComponents {
Index: typeof import('./components/CustomizeForm/Index.vue')['default']
Layouts: typeof import('./layouts/index.vue')['default'] Layouts: typeof import('./layouts/index.vue')['default']
PageTitle: typeof import('./components/PageTitle.vue')['default'] PageTitle: typeof import('./components/PageTitle.vue')['default']
PageTop: typeof import('./components/PageTop.vue')['default'] PageTop: typeof import('./components/PageTop.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink'] RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView'] RouterView: typeof import('vue-router')['RouterView']
SelectDatePicker: typeof import('./components/CustomizeForm/selectDatePicker.vue')['default']
SelectDropdown: typeof import('./components/CustomizeForm/selectDropdown.vue')['default']
VanActionSheet: typeof import('vant/es')['ActionSheet'] VanActionSheet: typeof import('vant/es')['ActionSheet']
VanButton: typeof import('vant/es')['Button'] VanButton: typeof import('vant/es')['Button']
VanCell: typeof import('vant/es')['Cell'] VanCell: typeof import('vant/es')['Cell']
...@@ -31,6 +34,7 @@ declare module 'vue' { ...@@ -31,6 +34,7 @@ declare module 'vue' {
VanPullRefresh: typeof import('vant/es')['PullRefresh'] VanPullRefresh: typeof import('vant/es')['PullRefresh']
VanSearch: typeof import('vant/es')['Search'] VanSearch: typeof import('vant/es')['Search']
VanSkeleton: typeof import('vant/es')['Skeleton'] VanSkeleton: typeof import('vant/es')['Skeleton']
VanSlider: typeof import('vant/es')['Slider']
VanSticky: typeof import('vant/es')['Sticky'] VanSticky: typeof import('vant/es')['Sticky']
VanSwipe: typeof import('vant/es')['Swipe'] VanSwipe: typeof import('vant/es')['Swipe']
VanSwipeItem: typeof import('vant/es')['SwipeItem'] VanSwipeItem: typeof import('vant/es')['SwipeItem']
......
...@@ -35,22 +35,33 @@ function stripTokenFromUrl() { ...@@ -35,22 +35,33 @@ function stripTokenFromUrl() {
} }
function postToUniApp(payload: Record<string, unknown>) { function postToUniApp(payload: Record<string, unknown>) {
console.log('pad端postToUniApp', payload);
const w = window as unknown as { const w = window as unknown as {
uni?: { postMessage?: (args: { data: unknown }) => void }; uni?: { postMessage?: (args: { data: unknown }) => void };
parent?: Window; parent?: Window;
}; };
try { const doPost = () => {
w.uni?.postMessage?.({ data: payload }); try {
} catch { w.uni?.postMessage?.({ data: payload });
// ignore } catch {
} // ignore
}
// 兜底:部分容器没有注入 uni 对象时尝试 parent.postMessage // 兜底:部分容器没有注入 uni 对象时尝试 parent.postMessage
try { try {
w.parent?.postMessage?.(payload, "*"); w.parent?.postMessage?.(payload, "*");
} catch { } catch {
// ignore // ignore
}
};
if (w.uni) {
// uni 对象已就绪,直接发送
doPost();
} else {
// 等待 UniAppJSBridgeReady 事件后再发送
document.addEventListener('UniAppJSBridgeReady', doPost, { once: true });
} }
} }
......
<template>
<div class="inspect-sub-content inspect-sub-content--mock">
<div v-if="!leafNodes?.length"
class="sub-empty">
<van-icon color="#c8c9cc"
name="notes-o"
size="40" />
<p>当前二级项暂无检测项(childrenNodes 为空)</p>
</div>
<template v-else>
<div v-if="bigModuleLabel || subTabLabel"
class="sub-header">
<span v-if="bigModuleLabel">{{ bigModuleLabel }}</span>
<span v-if="bigModuleLabel && subTabLabel"> · </span>
<span v-if="subTabLabel">{{ subTabLabel }}</span>
<span class="sub-header-tag">模拟</span>
</div>
<div v-for="node in leafNodes"
:key="node.id"
class="mock-field-card">
<div class="mock-field-title">
{{ node.nodeName }}
<span v-if="node.required === 1"
class="req">*</span>
</div>
<div class="mock-field-meta">
<span>nodeCode: {{ node.nodeCode || "—" }}</span>
<span>interaction: {{ node.interactionType || "—" }}</span>
</div>
<div v-if="showResolvedDefault(node)"
class="mock-resolved">
解析默认: {{ node.resolvedInitialValue ?? node.defaultValue ?? "—" }}
</div>
<van-field class="mock-input"
:model-value="fieldValues[node.id] ?? ''"
:placeholder="node.placeholder || '模拟输入'"
@update:model-value="(v) => onFieldInput(node.id, v)" />
</div>
</template>
</div>
</template>
<script setup lang="ts">
import type { InspectionNode, LeafNodeRecord } from "@api";
import { ref, watch } from "vue";
import { showToast } from "vant";
const props = withDefaults(
defineProps<{
/** 当前二级项下已处理默认值的 childrenNodes(叶子节点) */
leafNodes?: InspectionNode[];
bigModuleLabel?: string;
subTabLabel?: string;
}>(),
{
leafNodes: () => [],
bigModuleLabel: "",
subTabLabel: "",
}
);
/** 模拟表单值(nodeId -> 文本) */
const fieldValues = ref<Record<number, string>>({});
watch(
() => props.leafNodes,
(nodes: InspectionNode[] | undefined) => {
const next: Record<number, string> = {};
for (const n of nodes ?? []) {
next[n.id] = n.resolvedInitialValue ?? n.defaultValue ?? "";
}
fieldValues.value = next;
},
{ immediate: true, deep: true }
);
function showResolvedDefault(node: InspectionNode) {
return (
node.existsDefaultValue === "1" ||
node.existsDefaultValue === 1 ||
node.resolvedInitialValue !== undefined ||
!!node.defaultValue
);
}
function onFieldInput(nodeId: number, v: string) {
fieldValues.value = { ...fieldValues.value, [nodeId]: v };
}
/**
* 与父页 InspectSubContentExpose 对齐;正式组件实现后替换逻辑即可。
*/
async function collectData(validate: boolean): Promise<LeafNodeRecord[] | null> {
const list = props.leafNodes ?? [];
if (validate) {
for (const n of list) {
if (n.required === 1 && !String(fieldValues.value[n.id] ?? "").trim()) {
showToast(`请填写:${n.nodeName}`);
return null;
}
}
}
return list.map((leaf) => ({
nodeId: leaf.id,
nodeName: leaf.nodeName,
resultStatus: 0,
remark: "",
data: [
{
id: leaf.id,
valueText: String(fieldValues.value[leaf.id] ?? ""),
valueKey: "",
interactionType: leaf.interactionType ?? "",
valueSeq: 0,
remark: "",
},
],
}));
}
defineExpose({ collectData });
</script>
<style lang="scss" scoped>
.inspect-sub-content--mock {
padding-bottom: 8px;
}
.sub-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 220px;
gap: 12px;
padding: 24px;
font-size: 13px;
color: #969799;
text-align: center;
}
.sub-header {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin-bottom: 12px;
font-size: 13px;
font-weight: 600;
color: #323233;
.sub-header-tag {
padding: 0 6px;
font-size: 11px;
font-weight: 500;
color: #185efe;
background: #185efe1a;
border-radius: 4px;
}
}
.mock-field-card {
margin-bottom: 14px;
padding: 12px;
background: #f7f8fa;
border-radius: 8px;
}
.mock-field-title {
margin-bottom: 6px;
font-size: 15px;
font-weight: 600;
color: #323233;
.req {
margin-left: 2px;
color: #ee0a24;
}
}
.mock-field-meta {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 6px;
font-size: 11px;
color: #969799;
}
.mock-resolved {
margin-bottom: 8px;
padding: 6px 8px;
font-size: 12px;
line-height: 1.4;
color: #185efe;
word-break: break-all;
background: #185efe14;
border-radius: 4px;
}
.mock-input {
padding: 8px 10px;
margin-top: 4px;
overflow: hidden;
background: #fff;
border-radius: 6px;
:deep(.van-field__body) {
padding: 0;
}
}
</style>
<template>
<div class="score-form">
<!-- 外观评分 -->
<div class="score-section">
<div class="score-section-header">
<span class="score-label">外观评分<span class="required-mark">*</span></span>
<span class="score-value">{{ form.appearanceScore }} <em>分</em></span>
</div>
<div class="score-slider-wrap">
<van-slider v-model="form.appearanceScore"
active-color="#185efe"
inactive-color="#e8edf5"
:max="100"
:min="0"
:step="1" />
<div class="score-ticks">
<span>0</span>
<span>40</span>
<span>80</span>
</div>
</div>
</div>
<!-- 外观评级 -->
<div class="score-section">
<div class="score-section-header">
<span class="score-label">外观评级<span class="required-mark">*</span></span>
</div>
<div class="rating-btns">
<div v-for="opt in RATING_OPTIONS"
:key="opt"
class="rating-btn"
:class="{ active: form.appearanceRating === opt }"
@click="form.appearanceRating = opt">
{{ opt }}
</div>
</div>
<div class="score-basis-label">
评分依据<span class="required-mark">*</span>
</div>
<van-field v-model="form.appearanceBasis"
autosize
class="score-textarea"
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>
</div>
<div class="rating-btns">
<div v-for="opt in RATING_OPTIONS"
:key="opt"
class="rating-btn"
:class="{ active: form.frameRating === opt }"
@click="form.frameRating = opt">
{{ opt }}
</div>
</div>
<div class="score-basis-label">
评分依据<span class="required-mark">*</span>
</div>
<van-field v-model="form.frameBasis"
autosize
class="score-textarea"
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>
</div>
<div class="rating-btns">
<div v-for="opt in RATING_OPTIONS"
:key="opt"
class="rating-btn"
:class="{ active: form.interiorRating === opt }"
@click="form.interiorRating = opt">
{{ opt }}
</div>
</div>
<div class="score-basis-label">
评分依据<span class="required-mark">*</span>
</div>
<van-field v-model="form.interiorBasis"
autosize
class="score-textarea"
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-value">{{ form.overallScore }} <em>分</em></span>
</div>
<div class="score-slider-wrap">
<van-slider v-model="form.overallScore"
active-color="#185efe"
inactive-color="#e8edf5"
:max="100"
:min="0"
:step="1" />
<div class="score-ticks">
<span>0</span>
<span>20</span>
</div>
</div>
<div class="score-basis-label">
综合评价<span class="required-mark">*</span>
</div>
<van-field v-model="form.overallRating"
autosize
class="score-textarea"
placeholder="请对车辆综合情况进行评价..."
:rows="3"
type="textarea" />
</div>
</div>
</template>
<script setup lang="ts">
import { reactive } from "vue";
import { showToast } from "vant";
const RATING_OPTIONS = ["A", "B", "C", "D"] as const;
type RatingOption = (typeof RATING_OPTIONS)[number];
const form = reactive({
appearanceScore: 0,
appearanceRating: "" as "" | RatingOption,
appearanceBasis: "",
frameRating: "" as "" | RatingOption,
frameBasis: "",
interiorRating: "" as "" | RatingOption,
interiorBasis: "",
overallScore: 0,
overallRating: "",
});
function validate(): boolean {
const {
appearanceRating,
appearanceBasis,
frameRating,
frameBasis,
interiorRating,
interiorBasis,
overallRating,
} = form;
if (!appearanceRating || !appearanceBasis || !frameRating || !frameBasis || !interiorRating || !interiorBasis || !overallRating) {
showToast("请填完需评分必填项");
return false;
}
return true;
}
function getFormData() {
return { ...form };
}
defineExpose({ validate, getFormData });
</script>
<style lang="scss" scoped>
.score-form {
display: flex;
flex-direction: column;
padding-top: 8px;
}
.score-section {
padding: 14px 0;
border-bottom: 1px solid #f2f3f7;
&:last-child {
padding-bottom: 4px;
border-bottom: none;
}
}
.score-section-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.score-label {
font-size: 14px;
font-weight: 600;
color: #1a1a1a;
.required-mark {
margin-left: 2px;
color: #ff4d4f;
}
}
.score-value {
font-size: 20px;
font-weight: 700;
color: #185efe;
em {
font-size: 13px;
font-weight: 400;
font-style: normal;
color: #666;
}
}
.score-ref {
padding: 2px 8px;
font-size: 12px;
color: #185efe;
cursor: pointer;
border: 1px solid #185efe;
border-radius: 4px;
}
.score-slider-wrap {
padding: 0 4px;
:deep(.van-slider) {
margin-bottom: 6px;
}
:deep(.van-slider__button) {
width: 18px;
height: 18px;
border: 2px solid #185efe;
box-shadow: 0 2px 6px rgb(24 94 254 / 30%);
}
}
.score-ticks {
display: flex;
justify-content: space-between;
padding: 0 2px;
font-size: 11px;
color: #999;
}
.rating-btns {
display: flex;
gap: 10px;
margin-bottom: 14px;
}
.rating-btn {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
height: 40px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
color: #999;
background: #f7f8fa;
border: 1.5px solid #e8e8e8;
border-radius: 8px;
transition: all 0.15s ease;
&.active {
color: #fff;
background: #185efe;
border-color: #185efe;
box-shadow: 0 3px 8px rgb(24 94 254 / 30%);
}
}
.score-basis-label {
margin-bottom: 8px;
font-size: 13px;
font-weight: 500;
color: #333;
.required-mark {
margin-left: 2px;
color: #ff4d4f;
}
}
.score-textarea {
padding: 10px 12px;
background: #f7f8fa;
border-radius: 8px;
:deep(.van-field__control) {
font-size: 13px;
color: #333;
}
:deep(.van-field__control::placeholder) {
color: #bbb;
}
}
</style>
<template> <template>
<div class="inspect-page"> <div class="inspect-page">
<!-- 顶部区:大项切换 + 检测进度,跟随页面背景色 --> <!-- 顶部区:大项切换 + 检测进度(检测评分页隐藏进度条) -->
<div class="inspect-top"> <div class="inspect-top">
<!-- 第一行:返回 + 大项切换 + 进度数字 --> <!-- 第一行:返回 + 大项切换 -->
<div class="inspect-nav"> <div class="inspect-nav">
<van-icon class="nav-back" <van-icon class="nav-back"
name="arrow-left" name="arrow-left"
...@@ -10,22 +10,23 @@ ...@@ -10,22 +10,23 @@
@click="onBack" /> @click="onBack" />
<div class="nav-module" <div class="nav-module"
@click="onOpenModulePicker"> @click="onOpenModulePicker">
<span class="nav-module-name">{{ activeBigModule.label }}</span> <span class="nav-module-name">{{ activeBigModule?.label || "加载中..." }}</span>
<van-icon class="nav-module-arrow" <van-icon class="nav-module-arrow"
name="arrow-down" name="arrow-down"
size="13" /> size="13" />
</div> </div>
</div> </div>
<!-- 第二行:进度条 + 进度文案 --> <!-- 第二行:进度条(检测评分页不显示) -->
<div class="inspect-progress-bar"> <div v-if="activeBigKey !== SCORE_BIG_KEY"
class="inspect-progress-bar">
<van-progress class="progress-track" <van-progress class="progress-track"
color="#185efe" color="#185efe"
:percentage="Math.round((progressDone / progressTotal) * 100)" :percentage="progressTotal > 0 ? Math.round((progressDone / progressTotal) * 100) : 0"
:show-pivot="false" :show-pivot="false"
stroke-width="8" stroke-width="8"
track-color="#185efe1f" /> track-color="#185efe1f" />
<span class="progress-label"> <span class="progress-label">
检测进度 检测进度
<span class="progress-done">{{ progressDone }}</span>/{{ progressTotal }} <span class="progress-done">{{ progressDone }}</span>/{{ progressTotal }}
</span> </span>
</div> </div>
...@@ -33,66 +34,107 @@ ...@@ -33,66 +34,107 @@
<!-- 内容区:白色圆角卡片,二级tab固定 + 中间内容可滚动 --> <!-- 内容区:白色圆角卡片,二级tab固定 + 中间内容可滚动 -->
<div class="inspect-body"> <div class="inspect-body">
<div class="inspect-card"> <div v-if="loading"
class="inspect-card loading-card">
<van-loading color="#477ffe"
size="40"
type="spinner" />
<p class="loading-text">
加载检测模板中...
</p>
</div>
<div v-else-if="bigModules.length === 0"
class="inspect-card empty-card">
<van-icon color="#c8c9cc"
name="warning-o"
size="48" />
<p class="empty-title">
暂无检测模板
</p>
</div>
<!-- 检测评分大项:全屏评分表单,无二级 Tab,无进度条 -->
<div v-else-if="activeBigKey === SCORE_BIG_KEY"
class="inspect-card">
<div class="inspect-content">
<ScoreForm ref="inspectionScoreFormRef" />
</div>
</div>
<!-- 普通大项:二级 Tab + 内容区 -->
<div v-else
class="inspect-card">
<!-- 二级项 Tab(固定,不随内容滚动) --> <!-- 二级项 Tab(固定,不随内容滚动) -->
<div class="subtab-row"> <div class="subtab-row">
<div v-for="sub in activeBigModule.subTabs" <div v-for="subTab in activeBigModule?.subTabs"
:key="sub.key" :key="subTab.key"
class="subtab-item" class="subtab-item"
:class="{ active: sub.key === activeSubKey }" :class="{ active: subTab.key === activeSubKey, completed: subTab.completedFlag === 1 }"
@click="onSelectSubTab(sub.key)"> @click="onSelectSubTab(subTab.key)">
{{ sub.label }} {{ subTab.label }}
<van-icon v-if="subTab.completedFlag === 1"
class="subtab-done-icon"
color="#27CD5A"
name="checked" />
</div> </div>
</div> </div>
<!-- 中间滚动内容区 --> <!-- 中间滚动内容区:当前二级项 childrenNodes(已解析默认值) -->
<div class="inspect-content"> <div class="inspect-content">
<!-- 二级项内容组件占位 --> <InspectSubModuleContent ref="inspectSubContentRef"
<div class="content-placeholder"> :big-module-label="activeBigModule?.label"
<van-icon color="#c8c9cc" :leaf-nodes="currentLeafNodes"
name="photo-o" :sub-tab-label="activeSubTab?.label" />
size="48" />
<p class="placeholder-title">
{{ activeBigModule.label }} · {{ activeSubTab.label }}
</p>
<p class="placeholder-desc">
检测内容组件将在此渲染
</p>
</div>
</div> </div>
</div> </div>
</div> </div>
<!-- 底部固定区 --> <!-- 底部固定区 -->
<div class="inspect-footer"> <div class="inspect-footer">
<van-button class="btn-save" <!-- 检测评分页:上一步 + 提交评分 -->
plain <template v-if="activeBigKey === SCORE_BIG_KEY">
round <van-button block
type="primary" class="btn-next"
@click="onSave"> color="#477ffe"
保存 :loading="submitting"
</van-button> round
<van-button block type="primary"
class="btn-next" @click="onSubmitScore">
color="#477ffe" 提交评分
round </van-button>
type="primary" </template>
@click="onNext"> <!-- 普通检测页:上一步 + 下一步/提交检测内容 -->
下一页 <template v-else>
</van-button> <van-button class="btn-save"
:loading="submitting"
plain
round
type="primary"
@click="onPrev">
上一步
</van-button>
<van-button block
class="btn-next"
color="#477ffe"
:loading="submitting"
round
type="primary"
@click="onNext">
{{ remainingSubTabCount === 1 ? "提交检测内容" : "下一步" }}
</van-button>
</template>
</div> </div>
<!-- 大项选择弹窗 --> <!-- 大项选择弹窗 -->
<van-action-sheet v-model:show="showModulePicker" <van-action-sheet v-model:show="showModulePicker"
title="选择检测模块"> title="选择检测模块">
<div class="module-picker-list"> <div class="module-picker-list">
<div v-for="mod in bigModules" <div v-for="bigModule in bigModules"
:key="mod.key" :key="bigModule.key"
class="module-picker-item" class="module-picker-item"
:class="{ selected: mod.key === activeBigKey }" :class="{ selected: bigModule.key === activeBigKey }"
@click="onSelectBigModule(mod)"> @click="onSelectBigModule(bigModule)">
<span class="picker-label">{{ mod.label }}</span> <span class="picker-label">{{ bigModule.label }}</span>
<van-icon v-if="mod.key === activeBigKey" <van-icon v-if="bigModule.key === activeBigKey"
color="#477ffe" color="#477ffe"
name="success" name="success"
size="16" /> size="16" />
...@@ -103,153 +145,354 @@ ...@@ -103,153 +145,354 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from "vue"; import type { InspectionNode, InspectionTemplateDefaultData, LeafNodeRecord } from "@api";
import { useRouter } from "vue-router";
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
applyResolvedInitialValuesToLeafNodes,
completeInspection,
getInspectionChildren,
getInspectionRootNodes,
getInspectionTemplateDefault,
saveInspectionRecord,
} from "@api";
import { showToast } from "vant"; import { showToast } from "vant";
// ===== Mock 数据 ===== import InspectSubModuleContent from "./components/InspectSubModuleContent.vue";
import ScoreForm from "./components/ScoreForm.vue";
// ===== 常量 =====
/** 检测评分大项的固定 key(非接口返回,手动追加至大项末尾) */
const SCORE_BIG_KEY = "__score_big__";
// ===== 类型定义 =====
interface SubTab { interface SubTab {
key: string; key: number | string;
label: string; label: string;
nodeId?: number;
/** 该二级项下的叶子节点列表(nodeType=3) */
leafNodes?: InspectionNode[];
/** 二级项自身的完成标志:0 未完成,1 已完成 */
completedFlag?: 0 | 1;
} }
interface BigModule { interface BigModule {
key: string; key: number | string;
label: string; label: string;
nodeId?: number;
subTabs: SubTab[]; subTabs: SubTab[];
} }
const bigModules: BigModule[] = [ /**
{ * 内容组件需要通过 defineExpose 暴露此接口。
key: "exterior", * validate=false 时不校验直接收集数据;
label: "外观", * validate=true 时校验,未填完返回 null。
subTabs: [ */
{ key: "exterior-front", label: "车头" }, /** 与 `InspectSubModuleContent` 的 defineExpose 对齐 */
{ key: "exterior-side", label: "车身侧面" }, export interface InspectSubContentExpose {
{ key: "exterior-rear", label: "车尾" }, collectData(validate: boolean): Promise<LeafNodeRecord[] | null>;
{ key: "exterior-roof", label: "车顶" }, }
{ key: "exterior-undercarriage", label: "底盘" },
],
},
{
key: "interior",
label: "内饰",
subTabs: [
{ key: "interior-dashboard", label: "仪表台" },
{ key: "interior-seats", label: "座椅" },
{ key: "interior-roof-lining", label: "顶棚" },
{ key: "interior-carpet", label: "地毯脚垫" },
],
},
{
key: "engine",
label: "发动机",
subTabs: [
{ key: "engine-compartment", label: "发动机舱" },
{ key: "engine-oil", label: "机油检查" },
{ key: "engine-cooling", label: "冷却系统" },
{ key: "engine-belt", label: "皮带检查" },
],
},
{
key: "chassis",
label: "底盘",
subTabs: [
{ key: "chassis-suspension", label: "悬挂系统" },
{ key: "chassis-brake", label: "制动系统" },
{ key: "chassis-steering", label: "转向系统" },
],
},
{
key: "electrical",
label: "电气",
subTabs: [
{ key: "electrical-battery", label: "蓄电池" },
{ key: "electrical-lights", label: "灯光系统" },
{ key: "electrical-ac", label: "空调系统" },
{ key: "electrical-entertainment", label: "娱乐系统" },
],
},
];
// ===== 状态 ===== // ===== 状态 =====
const router = useRouter(); const router = useRouter();
const route = useRoute();
const activeBigKey = ref(bigModules[0]!.key); const taskId = ref<number | string>("");
const bigModules = ref<BigModule[]>([]);
const activeBigKey = ref<number | string>("");
const showModulePicker = ref(false); const showModulePicker = ref(false);
const loading = ref(false);
const submitting = ref(false);
/** 二级项检测内容区(叶子节点表单),子组件 defineExpose */
const inspectSubContentRef = ref<InspectSubContentExpose | null>(null);
/** 检测评分表单 */
const inspectionScoreFormRef = ref<InstanceType<typeof ScoreForm> | null>(null);
const activeBigModule = computed( const activeBigModule = computed(
() => bigModules.find((m) => m.key === activeBigKey.value) ?? bigModules[0]! () =>
bigModules.value.find((module) => module.key === activeBigKey.value) ?? bigModules.value[0]
); );
const activeSubKey = ref(activeBigModule.value.subTabs[0]!.key); const activeSubKey = ref<number | string>("");
const allSubTabs = computed(() => bigModules.flatMap((m) => m.subTabs)); /** 不含「检测评分」的大项(接口大项),用于进度与步骤导航 */
const mainInspectionBigModules = computed(() =>
bigModules.value.filter((module) => module.key !== SCORE_BIG_KEY)
);
const progressTotal = computed(() => allSubTabs.value.length); /** 上述大项下所有二级项打平,用于全局进度条 */
const flattenedMainSubTabs = computed(() =>
mainInspectionBigModules.value.flatMap((module) => module.subTabs)
);
const progressDone = computed(() => { const progressTotal = computed(() => flattenedMainSubTabs.value.length);
const bigIdx = bigModules.findIndex((m) => m.key === activeBigKey.value);
const subIdx = activeBigModule.value.subTabs.findIndex( const progressDone = computed(() =>
(s) => s.key === activeSubKey.value flattenedMainSubTabs.value.filter((subTab) => subTab.completedFlag === 1).length
); );
let done = 0;
for (let i = 0; i < bigIdx; i++) { /** 仍未完成的二级项数量(用于底部按钮文案) */
done += bigModules[i]!.subTabs.length; const remainingSubTabCount = computed(() => progressTotal.value - progressDone.value);
}
done += subIdx + 1;
return done;
});
const activeSubTab = computed( const activeSubTab = computed(
() => () =>
activeBigModule.value.subTabs.find((s) => s.key === activeSubKey.value) ?? activeBigModule.value?.subTabs.find((subTab) => subTab.key === activeSubKey.value) ??
activeBigModule.value.subTabs[0]! activeBigModule.value?.subTabs[0]
); );
/** 当前二级项下的叶子节点(loadSubTabsForBigModule 内已合并模板默认值) */
const currentLeafNodes = computed(() => activeSubTab.value?.leafNodes ?? []);
// ===== 初始化 =====
async function initializeInspection() {
try {
loading.value = true;
const routeTaskId = route.query.id || route.params.id;
if (!routeTaskId) {
showToast("缺少检测工单ID");
return;
}
taskId.value = routeTaskId;
const rootNodes = await getInspectionRootNodes(taskId.value);
if (!rootNodes || rootNodes.length === 0) {
showToast("暂无检测模板数据");
return;
}
const assembledBigModules: BigModule[] = [
...rootNodes.map((root) => ({
key: root.id,
label: root.nodeName,
nodeId: root.id,
subTabs: [],
})),
{ key: SCORE_BIG_KEY, label: "检测评分", subTabs: [] },
];
bigModules.value = assembledBigModules;
const firstMain = bigModules.value[0];
if (firstMain) {
activeBigKey.value = firstMain.key;
await loadSubTabsForBigModule(firstMain.key);
}
} catch (error) {
console.error("初始化检测页失败:", error);
showToast("加载检测模板失败");
} finally {
loading.value = false;
}
}
// ===== 加载某大项下的二级项 =====
async function loadSubTabsForBigModule(bigModuleKey: number | string) {
if (bigModuleKey === SCORE_BIG_KEY) return;
try {
const targetBigModule = bigModules.value.find((module) => module.key === bigModuleKey);
if (!targetBigModule) return;
if (targetBigModule.subTabs.length > 0) {
activeSubKey.value = targetBigModule.subTabs[0]!.key;
return;
}
const childLevelNodes = await getInspectionChildren(bigModuleKey, taskId.value);
let templateDefaultData: InspectionTemplateDefaultData | null = null;
try {
templateDefaultData = await getInspectionTemplateDefault(taskId.value);
} catch (error) {
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 (targetBigModule.subTabs.length > 0) {
activeSubKey.value = targetBigModule.subTabs[0]!.key;
}
} catch (error) {
console.error("加载二级项失败:", error);
showToast("加载二级项失败");
}
}
// ===== 事件处理 ===== // ===== 事件处理 =====
function onOpenModulePicker() { function onOpenModulePicker() {
showModulePicker.value = true; showModulePicker.value = true;
} }
function onSelectBigModule(mod: BigModule) { /** 切换大项 / 二级项前静默落库当前叶子数据 */
activeBigKey.value = mod.key; async function persistCurrentSubTabSilently() {
activeSubKey.value = mod.subTabs[0]!.key; if (activeBigKey.value === SCORE_BIG_KEY) return;
try {
const leafNodes = (await inspectSubContentRef.value?.collectData(false)) ?? [];
await saveInspectionRecord(buildInspectionSavePayload(leafNodes, false));
} catch {
// 静默失败,不阻断切换
}
}
async function onSelectBigModule(selectedBigModule: BigModule) {
showModulePicker.value = false; showModulePicker.value = false;
if (selectedBigModule.key === activeBigKey.value) return;
await persistCurrentSubTabSilently();
activeBigKey.value = selectedBigModule.key;
activeSubKey.value = "";
if (selectedBigModule.key !== SCORE_BIG_KEY) {
loadSubTabsForBigModule(selectedBigModule.key);
}
} }
function onSelectSubTab(key: string) { async function onSelectSubTab(subTabKey: number | string) {
activeSubKey.value = key; if (subTabKey === activeSubKey.value) return;
await persistCurrentSubTabSilently();
activeSubKey.value = subTabKey;
} }
function onSave() { /** 构造 `saveInspectionRecord` 请求体 */
showToast("已保存当前项"); function buildInspectionSavePayload(leafNodes: LeafNodeRecord[], nextFlag: boolean) {
return {
taskId: taskId.value,
locationModule: activeBigModule.value?.nodeId ?? 0,
locationSubModule: activeSubTab.value?.nodeId ?? 0,
nextFlag,
leafNodes,
};
} }
function onNext() { /** 进入下一二级项;若当前大项已走完则进入下一个主检测大项,否则进入评分大项 */
const currentSubTabs = activeBigModule.value.subTabs; function advanceInspectionStep() {
const currentSubIdx = currentSubTabs.findIndex( const activeModule = activeBigModule.value;
(s) => s.key === activeSubKey.value if (!activeModule) return;
);
const subTabsOfActive = activeModule.subTabs;
const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value);
if (currentSubIdx < currentSubTabs.length - 1) { if (activeSubIndex < subTabsOfActive.length - 1) {
activeSubKey.value = currentSubTabs[currentSubIdx + 1]!.key; activeSubKey.value = subTabsOfActive[activeSubIndex + 1]!.key;
return;
}
const mains = mainInspectionBigModules.value;
const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value);
if (activeMainIndex < mains.length - 1) {
const nextMain = mains[activeMainIndex + 1]!;
activeBigKey.value = nextMain.key;
loadSubTabsForBigModule(nextMain.key).then(() => {
activeSubKey.value = nextMain.subTabs[0]?.key ?? "";
});
} else { } else {
const bigIdx = bigModules.findIndex((m) => m.key === activeBigKey.value); activeBigKey.value = SCORE_BIG_KEY;
if (bigIdx < bigModules.length - 1) { activeSubKey.value = "";
const nextBig = bigModules[bigIdx + 1]!; }
activeBigKey.value = nextBig.key; }
activeSubKey.value = nextBig.subTabs[0]!.key;
} else {
showToast("已完成所有检测项"); /** 下一步:校验当前叶子 → 保存 → 前进 */
async function onNext() {
if (submitting.value) return;
try {
submitting.value = true;
const leafNodes = await inspectSubContentRef.value?.collectData(true);
if (leafNodes === null || leafNodes === undefined) {
return;
} }
await saveInspectionRecord(buildInspectionSavePayload(leafNodes, true));
advanceInspectionStep();
} catch {
showToast("保存失败,请重试");
} finally {
submitting.value = false;
} }
} }
function onBack() { function onBack() {
router.back(); router.back();
} }
/** 上一步:先保存当前页,再退回上一二级项或上一大项 */
async function onPrev() {
if (submitting.value) return;
try {
submitting.value = true;
if (activeBigKey.value === SCORE_BIG_KEY) {
const mains = mainInspectionBigModules.value;
const lastMain = mains[mains.length - 1];
if (lastMain) {
activeBigKey.value = lastMain.key;
await loadSubTabsForBigModule(lastMain.key);
activeSubKey.value = lastMain.subTabs[lastMain.subTabs.length - 1]?.key ?? "";
}
return;
}
const leafNodes = (await inspectSubContentRef.value?.collectData(false)) ?? [];
await saveInspectionRecord(buildInspectionSavePayload(leafNodes, false));
const subTabsOfActive = activeBigModule.value?.subTabs ?? [];
const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value);
if (activeSubIndex > 0) {
activeSubKey.value = subTabsOfActive[activeSubIndex - 1]!.key;
} else {
const mains = mainInspectionBigModules.value;
const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value);
if (activeMainIndex > 0) {
const previousMain = mains[activeMainIndex - 1]!;
activeBigKey.value = previousMain.key;
await loadSubTabsForBigModule(previousMain.key);
activeSubKey.value =
previousMain.subTabs[previousMain.subTabs.length - 1]?.key ?? "";
}
}
} catch {
showToast("保存失败,请重试");
} finally {
submitting.value = false;
}
}
/** 提交检测评分 */
async function onSubmitScore() {
if (!inspectionScoreFormRef.value?.validate()) return;
if (submitting.value) return;
try {
submitting.value = true;
const formData = inspectionScoreFormRef.value.getFormData();
await completeInspection({
taskId: taskId.value,
exteriorScore: formData.appearanceScore,
exteriorComment: formData.appearanceBasis,
skeletonLevel: formData.frameRating,
skeletonComment: formData.frameBasis,
interiorLevel: formData.interiorRating,
interiorComment: formData.interiorBasis,
overallScore: formData.overallScore,
overallComment: formData.overallRating,
});
showToast("评分已提交");
} catch {
showToast("提交失败,请重试");
} finally {
submitting.value = false;
}
}
onMounted(() => {
initializeInspection();
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
...@@ -394,6 +637,12 @@ function onBack() { ...@@ -394,6 +637,12 @@ function onBack() {
border-color: #fff; border-color: #fff;
box-shadow: 2px 4px 8px 0 rgb(129 163 214 / 35%); box-shadow: 2px 4px 8px 0 rgb(129 163 214 / 35%);
} }
.subtab-done-icon {
margin-left: 4px;
vertical-align: middle;
font-size: 14px;
}
} }
} }
...@@ -402,24 +651,34 @@ function onBack() { ...@@ -402,24 +651,34 @@ function onBack() {
padding: 0 $spacing-base $spacing-base; padding: 0 $spacing-base $spacing-base;
} }
.content-placeholder { // ===== 加载状态 =====
.loading-card {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
min-height: 300px; min-height: 300px;
gap: $spacing-sm; gap: $spacing-md;
padding: $spacing-xl;
.placeholder-title { .loading-text {
font-size: $font-size-base; font-size: $font-size-base;
font-weight: 700;
color: $color-text-secondary; color: $color-text-secondary;
} }
}
// ===== 空状态 =====
.empty-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 300px;
gap: $spacing-sm;
.placeholder-desc { .empty-title {
font-size: $font-size-sm; font-size: $font-size-base;
color: $color-text-disabled; font-weight: 700;
color: $color-text-secondary;
} }
} }
...@@ -443,6 +702,7 @@ function onBack() { ...@@ -443,6 +702,7 @@ function onBack() {
} }
} }
// ===== 大项选择弹窗 ===== // ===== 大项选择弹窗 =====
.module-picker-list { .module-picker-list {
padding: $spacing-sm 0 calc($spacing-sm + env(safe-area-inset-bottom)); padding: $spacing-sm 0 calc($spacing-sm + env(safe-area-inset-bottom));
......
...@@ -165,7 +165,7 @@ function startCheck(item: WorkOrderItem) { ...@@ -165,7 +165,7 @@ function startCheck(item: WorkOrderItem) {
function continueCheck(item: WorkOrderItem) { function continueCheck(item: WorkOrderItem) {
showToast("继续检测"); showToast("继续检测");
void router.push({ name: "CarDetail", params: { id: item.id } }); void router.push({ name: "CarDetail", params: { taskId: item.id } });
} }
function editCheck(item: WorkOrderItem) { 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!