Commit 287dee6a by chenwq1

feat: 增强车检功能与用户体验

- 在 index.html 中引入微信 JSSDK 和 UniApp WebView Bridge,支持小程序通信
- 更新组件类型定义,新增 VanSlider 组件支持
- 在 inspect-report.ts 中添加多个检测模板相关 API 接口,增强数据交互能力
- 优化 car-detail 页面布局,新增评分表单组件以提升用户评分体验
- 更新 home 页面路由参数,确保任务 ID 正确传递
1 parent 3bf5ceae
Pipeline #74 for 287dee6a failed in 0 seconds
......@@ -12,6 +12,10 @@
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<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>
<body>
<div id="app"></div>
......
import { post } from "@utils/request";
import { get, post } from "@utils/request";
export interface InspectReportPageParams {
size: number;
......@@ -100,3 +100,139 @@ export function getInspectReportPage(params: InspectReportPageParams) {
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;
defaultValue?: string;
defaultType?: number;
nodeLevel: number;
sortOrder: number;
status: number;
remark?: string;
createTime?: string;
/** 检测结果(含完成标志) */
inspectionResultVO?: InspectionResultVO;
/** 子节点列表(nodeType=2 的节点下挂 nodeType=3 的叶子节点) */
childrenNodes?: InspectionNode[];
[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,
});
}
/**
* 获取检测模板默认值
* @param taskId 检测工单ID
*/
export function getInspectionTemplateDefault(taskId: string | number) {
return post(`/rest/inspectionTemplate/default`, {
taskId,
});
}
// ===== 检测记录保存 =====
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);
}
......@@ -31,6 +31,7 @@ declare module 'vue' {
VanPullRefresh: typeof import('vant/es')['PullRefresh']
VanSearch: typeof import('vant/es')['Search']
VanSkeleton: typeof import('vant/es')['Skeleton']
VanSlider: typeof import('vant/es')['Slider']
VanSticky: typeof import('vant/es')['Sticky']
VanSwipe: typeof import('vant/es')['Swipe']
VanSwipeItem: typeof import('vant/es')['SwipeItem']
......
......@@ -35,22 +35,33 @@ function stripTokenFromUrl() {
}
function postToUniApp(payload: Record<string, unknown>) {
console.log('pad端postToUniApp', payload);
const w = window as unknown as {
uni?: { postMessage?: (args: { data: unknown }) => void };
parent?: Window;
};
try {
w.uni?.postMessage?.({ data: payload });
} catch {
// ignore
}
const doPost = () => {
try {
w.uni?.postMessage?.({ data: payload });
} catch {
// ignore
}
// 兜底:部分容器没有注入 uni 对象时尝试 parent.postMessage
try {
w.parent?.postMessage?.(payload, "*");
} catch {
// ignore
// 兜底:部分容器没有注入 uni 对象时尝试 parent.postMessage
try {
w.parent?.postMessage?.(payload, "*");
} catch {
// ignore
}
};
if (w.uni) {
// uni 对象已就绪,直接发送
doPost();
} else {
// 等待 UniAppJSBridgeReady 事件后再发送
document.addEventListener('UniAppJSBridgeReady', doPost, { once: true });
}
}
......
<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>
<div class="inspect-page">
<!-- 顶部区:大项切换 + 检测进度,跟随页面背景色 -->
<!-- 顶部区:大项切换 + 检测进度(检测评分页隐藏进度条) -->
<div class="inspect-top">
<!-- 第一行:返回 + 大项切换 + 进度数字 -->
<!-- 第一行:返回 + 大项切换 -->
<div class="inspect-nav">
<van-icon class="nav-back"
name="arrow-left"
......@@ -10,22 +10,23 @@
@click="onBack" />
<div class="nav-module"
@click="onOpenModulePicker">
<span class="nav-module-name">{{ activeBigModule.label }}</span>
<span class="nav-module-name">{{ activeBigModule?.label || "加载中..." }}</span>
<van-icon class="nav-module-arrow"
name="arrow-down"
size="13" />
</div>
</div>
<!-- 第二行:进度条 + 进度文案 -->
<div class="inspect-progress-bar">
<!-- 第二行:进度条(检测评分页不显示) -->
<div v-if="activeBigKey !== SCORE_BIG_KEY"
class="inspect-progress-bar">
<van-progress class="progress-track"
color="#185efe"
:percentage="Math.round((progressDone / progressTotal) * 100)"
:percentage="progressTotal > 0 ? Math.round((progressDone / progressTotal) * 100) : 0"
:show-pivot="false"
stroke-width="8"
track-color="#185efe1f" />
<span class="progress-label">
检测进度
检测进度
<span class="progress-done">{{ progressDone }}</span>/{{ progressTotal }}
</span>
</div>
......@@ -33,27 +34,58 @@
<!-- 内容区:白色圆角卡片,二级tab固定 + 中间内容可滚动 -->
<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="scoreFormRef" />
</div>
</div>
<!-- 普通大项:二级 Tab + 内容区 -->
<div v-else
class="inspect-card">
<!-- 二级项 Tab(固定,不随内容滚动) -->
<div class="subtab-row">
<div v-for="sub in activeBigModule.subTabs"
<div v-for="sub in activeBigModule?.subTabs"
:key="sub.key"
class="subtab-item"
:class="{ active: sub.key === activeSubKey }"
:class="{ active: sub.key === activeSubKey, completed: sub.completedFlag === 1 }"
@click="onSelectSubTab(sub.key)">
{{ sub.label }}
<van-icon v-if="sub.completedFlag === 1"
class="subtab-done-icon"
color="#27CD5A"
name="checked" />
</div>
</div>
<!-- 中间滚动内容区 -->
<div class="inspect-content">
<!-- 二级项内容组件占位 -->
<div class="content-placeholder">
<van-icon color="#c8c9cc"
name="photo-o"
size="48" />
<p class="placeholder-title">
{{ activeBigModule.label }} · {{ activeSubTab.label }}
{{ activeBigModule?.label }} · {{ activeSubTab?.label }}
</p>
<p class="placeholder-desc">
检测内容组件将在此渲染
......@@ -65,21 +97,38 @@
<!-- 底部固定区 -->
<div class="inspect-footer">
<van-button class="btn-save"
plain
round
type="primary"
@click="onSave">
保存
</van-button>
<van-button block
class="btn-next"
color="#477ffe"
round
type="primary"
@click="onNext">
下一页
</van-button>
<!-- 检测评分页:上一步 + 提交评分 -->
<template v-if="activeBigKey === SCORE_BIG_KEY">
<van-button block
class="btn-next"
color="#477ffe"
:loading="submitting"
round
type="primary"
@click="onSubmitScore">
提交评分
</van-button>
</template>
<!-- 普通检测页:上一步 + 下一步/提交检测内容 -->
<template v-else>
<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">
{{ remainingCount === 1 ? "提交检测内容" : "下一步" }}
</van-button>
</template>
</div>
<!-- 大项选择弹窗 -->
......@@ -103,153 +152,364 @@
</template>
<script setup lang="ts">
import { computed, ref } from "vue";
import { useRouter } from "vue-router";
import type { InspectionNode, LeafNodeRecord } from "@api";
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
completeInspection,
getInspectionChildren,
getInspectionRootNodes,
getInspectionTemplateDefault,
saveInspectionRecord,
} from "@api";
import { showToast } from "vant";
// ===== Mock 数据 =====
import ScoreForm from "./components/ScoreForm.vue";
// ===== 常量 =====
/** 检测评分大项的固定 key(非接口返回,手动追加至大项末尾) */
const SCORE_BIG_KEY = "__score_big__";
// ===== 类型定义 =====
interface SubTab {
key: string;
key: number | string;
label: string;
nodeId?: number;
/** 该二级项下的叶子节点列表(nodeType=3) */
leafNodes?: InspectionNode[];
/** 二级项自身的完成标志:0 未完成,1 已完成 */
completedFlag?: 0 | 1;
}
interface BigModule {
key: string;
key: number | string;
label: string;
nodeId?: number;
subTabs: SubTab[];
}
const bigModules: BigModule[] = [
{
key: "exterior",
label: "外观",
subTabs: [
{ key: "exterior-front", label: "车头" },
{ key: "exterior-side", label: "车身侧面" },
{ key: "exterior-rear", label: "车尾" },
{ 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: "娱乐系统" },
],
},
];
/**
* 内容组件需要通过 defineExpose 暴露此接口。
* validate=false 时不校验直接收集数据;
* validate=true 时校验,未填完返回 null。
*/
export interface ContentComponentExpose {
collectData(validate: boolean): Promise<LeafNodeRecord[] | null>;
}
// ===== 状态 =====
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 loading = ref(false);
const submitting = ref(false);
/** 内容区组件实例,由子组件 defineExpose 填充 */
const contentRef = ref<ContentComponentExpose | null>(null);
/** 检测评分表单组件实例 */
const scoreFormRef = ref<InstanceType<typeof ScoreForm> | null>(null);
const activeBigModule = computed(
() => bigModules.find((m) => m.key === activeBigKey.value) ?? bigModules[0]!
() => bigModules.value.find((m) => m.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 allSubTabs = computed(() =>
bigModules.value
.filter((m) => m.key !== SCORE_BIG_KEY)
.flatMap((m) => m.subTabs)
);
/** 检测进度总数 = getInspectionChildren 返回的二级项总数 */
const progressTotal = computed(() => allSubTabs.value.length);
const progressDone = computed(() => {
const bigIdx = bigModules.findIndex((m) => m.key === activeBigKey.value);
const subIdx = activeBigModule.value.subTabs.findIndex(
(s) => s.key === activeSubKey.value
);
let done = 0;
for (let i = 0; i < bigIdx; i++) {
done += bigModules[i]!.subTabs.length;
}
done += subIdx + 1;
return done;
});
/** 已完成的二级项数(completedFlag === 1) */
const progressDone = computed(() =>
allSubTabs.value.filter((sub) => sub.completedFlag === 1).length
);
/** 剩余未完成的二级项数 */
const remainingCount = computed(() => progressTotal.value - progressDone.value);
const activeSubTab = computed(
() =>
activeBigModule.value.subTabs.find((s) => s.key === activeSubKey.value) ??
activeBigModule.value.subTabs[0]!
activeBigModule.value?.subTabs.find((s) => s.key === activeSubKey.value) ??
activeBigModule.value?.subTabs[0]
);
// ===== 初始化数据 =====
async function initializeData() {
try {
loading.value = true;
console.log(route);
// 从路由参数获取 taskId
const routeTaskId = route.query.id || route.params.id;
if (!routeTaskId) {
showToast("缺少检测工单ID");
return;
}
taskId.value = routeTaskId;
console.log("开始加载检测模板,taskId:", taskId.value);
// 第一步:获取大项节点
const rootNodes = await getInspectionRootNodes(taskId.value);
console.log("获取大项节点:", rootNodes);
if (!rootNodes || rootNodes.length === 0) {
showToast("暂无检测模板数据");
return;
}
// 初始化大项列表,末尾追加固定的"检测评分"大项
const modulesData: BigModule[] = [
...rootNodes.map((rootNode) => ({
key: rootNode.id,
label: rootNode.nodeName,
nodeId: rootNode.id,
subTabs: [],
})),
{ key: SCORE_BIG_KEY, label: "检测评分", subTabs: [] },
];
bigModules.value = modulesData;
console.log("大项列表:", bigModules.value);
// 设置初始选中的大项
if (bigModules.value.length > 0) {
activeBigKey.value = bigModules.value[0]!.key;
// 获取第一个大项的二级项
await loadSubTabs(bigModules.value[0]!.key);
}
} catch (error) {
console.error("初始化数据失败:", error);
showToast("加载检测模板失败");
} finally {
loading.value = false;
}
}
// ===== 加载二级项 =====
async function loadSubTabs(bigModuleKey: number | string) {
// 检测评分大项没有二级项,直接跳过
if (bigModuleKey === SCORE_BIG_KEY) return;
try {
const bigModule = bigModules.value.find((m) => m.key === bigModuleKey);
if (!bigModule) return;
// 如果已经加载过,直接返回
if (bigModule.subTabs.length > 0) {
activeSubKey.value = bigModule.subTabs[0]!.key;
return;
}
console.log(`开始加载大项 ${bigModule.label} 的二级项`);
const subNodes = await getInspectionChildren(bigModuleKey, taskId.value);
console.log(`获取大项 ${bigModule.label} 的二级项:`, subNodes);
bigModule.subTabs = (subNodes || []).map((node) => ({
key: node.id,
label: node.nodeName,
nodeId: node.id,
leafNodes: node.childrenNodes ?? [],
completedFlag: node.inspectionResultVO?.completedFlag ?? 0,
}));
if (bigModule.subTabs.length > 0) {
activeSubKey.value = bigModule.subTabs[0]!.key;
// 获取模板默认值
try {
const defaultData = await getInspectionTemplateDefault(taskId.value);
console.log("模板默认值:", defaultData);
} catch (error) {
console.error("获取模板默认值失败:", error);
}
}
} catch (error) {
console.error("加载二级项失败:", error);
showToast("加载二级项失败");
}
}
// ===== 事件处理 =====
function onOpenModulePicker() {
showModulePicker.value = true;
}
function onSelectBigModule(mod: BigModule) {
activeBigKey.value = mod.key;
activeSubKey.value = mod.subTabs[0]!.key;
/** 切换大项前先静默保存当前二级项 */
async function saveCurrentSubTabSilently() {
if (activeBigKey.value === SCORE_BIG_KEY) return;
try {
const leafNodes = (await contentRef.value?.collectData(false)) ?? [];
await saveInspectionRecord(buildSaveParams(leafNodes, false));
} catch {
// 静默失败,不阻断切换
}
}
async function onSelectBigModule(mod: BigModule) {
showModulePicker.value = false;
if (mod.key === activeBigKey.value) return;
await saveCurrentSubTabSilently();
activeBigKey.value = mod.key;
activeSubKey.value = "";
if (mod.key !== SCORE_BIG_KEY) {
loadSubTabs(mod.key);
}
}
function onSelectSubTab(key: string) {
async function onSelectSubTab(key: number | string) {
if (key === activeSubKey.value) return;
await saveCurrentSubTabSilently();
activeSubKey.value = key;
}
function onSave() {
showToast("已保存当前项");
/** 构造保存接口入参基础字段 */
function buildSaveParams(leafNodes: LeafNodeRecord[], nextFlag: boolean) {
return {
taskId: taskId.value,
locationModule: activeBigModule.value?.nodeId ?? 0,
locationSubModule: activeSubTab.value?.nodeId ?? 0,
nextFlag,
leafNodes,
};
}
function onNext() {
/** 跳转到下一个二级项 / 下一大项 / 检测评分大项 */
function goNext() {
if (!activeBigModule.value) return;
const currentSubTabs = activeBigModule.value.subTabs;
const currentSubIdx = currentSubTabs.findIndex(
(s) => s.key === activeSubKey.value
);
const currentSubIdx = currentSubTabs.findIndex((s) => s.key === activeSubKey.value);
if (currentSubIdx < currentSubTabs.length - 1) {
// 同一大项内的下一个二级项
activeSubKey.value = currentSubTabs[currentSubIdx + 1]!.key;
} else {
const bigIdx = bigModules.findIndex((m) => m.key === activeBigKey.value);
if (bigIdx < bigModules.length - 1) {
const nextBig = bigModules[bigIdx + 1]!;
// 寻找下一个大项(排除检测评分大项本身)
const realBigModules = bigModules.value.filter((m) => m.key !== SCORE_BIG_KEY);
const bigIdx = realBigModules.findIndex((m) => m.key === activeBigKey.value);
if (bigIdx < realBigModules.length - 1) {
const nextBig = realBigModules[bigIdx + 1]!;
activeBigKey.value = nextBig.key;
activeSubKey.value = nextBig.subTabs[0]!.key;
loadSubTabs(nextBig.key).then(() => {
activeSubKey.value = nextBig.subTabs[0]?.key ?? "";
});
} else {
showToast("已完成所有检测项");
// 所有普通大项已完成,跳到检测评分大项
activeBigKey.value = SCORE_BIG_KEY;
activeSubKey.value = "";
}
}
}
/** 下一步(先校验,通过后保存并跳转) */
async function onNext() {
if (submitting.value) return;
try {
submitting.value = true;
const leafNodes = await contentRef.value?.collectData(true);
// collectData 校验失败时返回 null,由子组件自行展示错误提示
if (leafNodes === null || leafNodes === undefined) {
return;
}
await saveInspectionRecord(buildSaveParams(leafNodes, true));
goNext();
} catch {
showToast("保存失败,请重试");
} finally {
submitting.value = false;
}
}
function onBack() {
router.back();
}
/** 上一步:保存当前二级项数据,切换到前一个二级项 */
async function onPrev() {
if (submitting.value) return;
try {
submitting.value = true;
if (activeBigKey.value === SCORE_BIG_KEY) {
// 评分页上一步:回到最后一个真实大项的最后一个二级项
const realBigModules = bigModules.value.filter((m) => m.key !== SCORE_BIG_KEY);
const lastBig = realBigModules[realBigModules.length - 1];
if (lastBig) {
activeBigKey.value = lastBig.key;
await loadSubTabs(lastBig.key);
activeSubKey.value = lastBig.subTabs[lastBig.subTabs.length - 1]?.key ?? "";
}
return;
}
// 普通页上一步:先保存当前二级项,再跳到上一个
const leafNodes = (await contentRef.value?.collectData(false)) ?? [];
await saveInspectionRecord(buildSaveParams(leafNodes, false));
const currentSubTabs = activeBigModule.value?.subTabs ?? [];
const currentSubIdx = currentSubTabs.findIndex((s) => s.key === activeSubKey.value);
if (currentSubIdx > 0) {
activeSubKey.value = currentSubTabs[currentSubIdx - 1]!.key;
} else {
// 当前大项第一个二级项,退到上一个大项的最后一个二级项
const realBigModules = bigModules.value.filter((m) => m.key !== SCORE_BIG_KEY);
const bigIdx = realBigModules.findIndex((m) => m.key === activeBigKey.value);
if (bigIdx > 0) {
const prevBig = realBigModules[bigIdx - 1]!;
activeBigKey.value = prevBig.key;
await loadSubTabs(prevBig.key);
activeSubKey.value = prevBig.subTabs[prevBig.subTabs.length - 1]?.key ?? "";
}
}
} catch {
showToast("保存失败,请重试");
} finally {
submitting.value = false;
}
}
/** 提交检测评分 */
async function onSubmitScore() {
if (!scoreFormRef.value?.validate()) return;
if (submitting.value) return;
try {
submitting.value = true;
const formData = scoreFormRef.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(() => {
initializeData();
});
</script>
<style lang="scss" scoped>
......@@ -394,6 +654,12 @@ function onBack() {
border-color: #fff;
box-shadow: 2px 4px 8px 0 rgb(129 163 214 / 35%);
}
.subtab-done-icon {
margin-left: 4px;
vertical-align: middle;
font-size: 14px;
}
}
}
......@@ -423,6 +689,37 @@ function onBack() {
}
}
// ===== 加载状态 =====
.loading-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 300px;
gap: $spacing-md;
.loading-text {
font-size: $font-size-base;
color: $color-text-secondary;
}
}
// ===== 空状态 =====
.empty-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 300px;
gap: $spacing-sm;
.empty-title {
font-size: $font-size-base;
font-weight: 700;
color: $color-text-secondary;
}
}
// ===== 底部固定区 =====
.inspect-footer {
flex-shrink: 0;
......@@ -443,6 +740,22 @@ function onBack() {
}
}
.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;
}
}
// ===== 大项选择弹窗 =====
.module-picker-list {
padding: $spacing-sm 0 calc($spacing-sm + env(safe-area-inset-bottom));
......
......@@ -165,7 +165,7 @@ function startCheck(item: WorkOrderItem) {
function continueCheck(item: WorkOrderItem) {
showToast("继续检测");
void router.push({ name: "CarDetail", params: { id: item.id } });
void router.push({ name: "CarDetail", params: { taskId: 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!