Commit 36f81cbd by chenwq1

feat: 增强检测报告功能与用户交互

- 更新 InspectionNode 接口,支持 existsDefaultValue 为字符串或数字
- 新增 resolvedInitialValue 字段,便于前端解析初始值
- 引入 InspectionTemplateDefaultData 接口,定义检测模板默认值结构
- 实现 resolveInspectionNodeInitialValue 函数,解析叶子节点初始值
- 新增 applyResolvedInitialValuesToLeafNodes 函数,批量处理叶子节点的初始值
- 在 car-detail 页面中引入 InspectSubModuleContent 组件,优化二级项内容展示
- 更新 ScoreForm 组件引用,提升代码可读性
- 调整样式与布局,改善用户体验
1 parent 8122807c
Pipeline #76 for 36f81cbd failed in 0 seconds
...@@ -127,7 +127,7 @@ export interface InspectionNode { ...@@ -127,7 +127,7 @@ export interface InspectionNode {
options?: string; options?: string;
validationRules?: string; validationRules?: string;
allowNoStructure?: number; allowNoStructure?: number;
existsDefaultValue?: string; existsDefaultValue?: string | number;
defaultValue?: string; defaultValue?: string;
defaultType?: number; defaultType?: number;
nodeLevel: number; nodeLevel: number;
...@@ -139,6 +139,11 @@ export interface InspectionNode { ...@@ -139,6 +139,11 @@ export interface InspectionNode {
inspectionResultVO?: InspectionResultVO; inspectionResultVO?: InspectionResultVO;
/** 子节点列表(nodeType=2 的节点下挂 nodeType=3 的叶子节点) */ /** 子节点列表(nodeType=2 的节点下挂 nodeType=3 的叶子节点) */
childrenNodes?: InspectionNode[]; childrenNodes?: InspectionNode[];
/**
* 前端根据 existsDefaultValue / defaultType 解析后的初始值
* (defaultType=2 时从 getInspectionTemplateDefault 的 data[nodeCode] 映射)
*/
resolvedInitialValue?: string;
[key: string]: unknown; [key: string]: unknown;
} }
...@@ -168,16 +173,88 @@ export function getInspectionChildren(rootNodeId: string | number, taskId: strin ...@@ -168,16 +173,88 @@ export function getInspectionChildren(rootNodeId: string | number, taskId: strin
}); });
} }
/** 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 * @param taskId 检测工单ID
*/ */
export function getInspectionTemplateDefault(taskId: string | number) { export function getInspectionTemplateDefault(taskId: string | number) {
return post(`/rest/inspectionTemplate/default`, { return post<InspectionTemplateDefaultData>(`/rest/inspectionTemplate/default`, {
taskId, 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 { export interface LeafNodeValue {
......
<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>
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
<div v-else-if="activeBigKey === SCORE_BIG_KEY" <div v-else-if="activeBigKey === SCORE_BIG_KEY"
class="inspect-card"> class="inspect-card">
<div class="inspect-content"> <div class="inspect-content">
<ScoreForm ref="scoreFormRef" /> <ScoreForm ref="inspectionScoreFormRef" />
</div> </div>
</div> </div>
...@@ -65,32 +65,25 @@ ...@@ -65,32 +65,25 @@
class="inspect-card"> 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, completed: sub.completedFlag === 1 }" :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="sub.completedFlag === 1" <van-icon v-if="subTab.completedFlag === 1"
class="subtab-done-icon" class="subtab-done-icon"
color="#27CD5A" color="#27CD5A"
name="checked" /> name="checked" />
</div> </div>
</div> </div>
<!-- 中间滚动内容区 --> <!-- 中间滚动内容区:当前二级项 childrenNodes(已解析默认值) -->
<div class="inspect-content"> <div class="inspect-content">
<div class="content-placeholder"> <InspectSubModuleContent ref="inspectSubContentRef"
<van-icon color="#c8c9cc" :big-module-label="activeBigModule?.label"
name="photo-o" :leaf-nodes="currentLeafNodes"
size="48" /> :sub-tab-label="activeSubTab?.label" />
<p class="placeholder-title">
{{ activeBigModule?.label }} · {{ activeSubTab?.label }}
</p>
<p class="placeholder-desc">
检测内容组件将在此渲染
</p>
</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -126,7 +119,7 @@ ...@@ -126,7 +119,7 @@
round round
type="primary" type="primary"
@click="onNext"> @click="onNext">
{{ remainingCount === 1 ? "提交检测内容" : "下一步" }} {{ remainingSubTabCount === 1 ? "提交检测内容" : "下一步" }}
</van-button> </van-button>
</template> </template>
</div> </div>
...@@ -135,13 +128,13 @@ ...@@ -135,13 +128,13 @@
<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" />
...@@ -152,12 +145,13 @@ ...@@ -152,12 +145,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import type { InspectionNode, LeafNodeRecord } from "@api"; import type { InspectionNode, InspectionTemplateDefaultData, LeafNodeRecord } from "@api";
import { computed, onMounted, ref } from "vue"; import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router"; import { useRoute, useRouter } from "vue-router";
import { import {
applyResolvedInitialValuesToLeafNodes,
completeInspection, completeInspection,
getInspectionChildren, getInspectionChildren,
getInspectionRootNodes, getInspectionRootNodes,
...@@ -166,6 +160,7 @@ import { ...@@ -166,6 +160,7 @@ import {
} from "@api"; } from "@api";
import { showToast } from "vant"; import { showToast } from "vant";
import InspectSubModuleContent from "./components/InspectSubModuleContent.vue";
import ScoreForm from "./components/ScoreForm.vue"; import ScoreForm from "./components/ScoreForm.vue";
// ===== 常量 ===== // ===== 常量 =====
...@@ -195,7 +190,8 @@ interface BigModule { ...@@ -195,7 +190,8 @@ interface BigModule {
* validate=false 时不校验直接收集数据; * validate=false 时不校验直接收集数据;
* validate=true 时校验,未填完返回 null。 * validate=true 时校验,未填完返回 null。
*/ */
export interface ContentComponentExpose { /** 与 `InspectSubModuleContent` 的 defineExpose 对齐 */
export interface InspectSubContentExpose {
collectData(validate: boolean): Promise<LeafNodeRecord[] | null>; collectData(validate: boolean): Promise<LeafNodeRecord[] | null>;
} }
...@@ -209,47 +205,50 @@ const activeBigKey = ref<number | string>(""); ...@@ -209,47 +205,50 @@ const activeBigKey = ref<number | string>("");
const showModulePicker = ref(false); const showModulePicker = ref(false);
const loading = ref(false); const loading = ref(false);
const submitting = ref(false); const submitting = ref(false);
/** 内容区组件实例,由子组件 defineExpose 填充 */ /** 二级项检测内容区(叶子节点表单),子组件 defineExpose */
const contentRef = ref<ContentComponentExpose | null>(null); const inspectSubContentRef = ref<InspectSubContentExpose | null>(null);
/** 检测评分表单组件实例 */ /** 检测评分表单 */
const scoreFormRef = ref<InstanceType<typeof ScoreForm> | null>(null); const inspectionScoreFormRef = ref<InstanceType<typeof ScoreForm> | null>(null);
const activeBigModule = computed( const activeBigModule = computed(
() => bigModules.value.find((m) => m.key === activeBigKey.value) ?? bigModules.value[0] () =>
bigModules.value.find((module) => module.key === activeBigKey.value) ?? bigModules.value[0]
); );
const activeSubKey = ref<number | string>(""); const activeSubKey = ref<number | string>("");
/** 真实大项的二级项(排除检测评分大项) */ /** 不含「检测评分」的大项(接口大项),用于进度与步骤导航 */
const allSubTabs = computed(() => const mainInspectionBigModules = computed(() =>
bigModules.value bigModules.value.filter((module) => module.key !== SCORE_BIG_KEY)
.filter((m) => m.key !== SCORE_BIG_KEY)
.flatMap((m) => m.subTabs)
); );
/** 检测进度总数 = getInspectionChildren 返回的二级项总数 */ /** 上述大项下所有二级项打平,用于全局进度条 */
const progressTotal = computed(() => allSubTabs.value.length); const flattenedMainSubTabs = computed(() =>
mainInspectionBigModules.value.flatMap((module) => module.subTabs)
);
const progressTotal = computed(() => flattenedMainSubTabs.value.length);
/** 已完成的二级项数(completedFlag === 1) */
const progressDone = computed(() => const progressDone = computed(() =>
allSubTabs.value.filter((sub) => sub.completedFlag === 1).length flattenedMainSubTabs.value.filter((subTab) => subTab.completedFlag === 1).length
); );
/** 剩余未完成的二级项数 */ /** 仍未完成的二级项数量(用于底部按钮文案) */
const remainingCount = computed(() => progressTotal.value - progressDone.value); const remainingSubTabCount = computed(() => progressTotal.value - progressDone.value);
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 内已合并模板默认值) */
async function initializeData() { const currentLeafNodes = computed(() => activeSubTab.value?.leafNodes ?? []);
// ===== 初始化 =====
async function initializeInspection() {
try { try {
loading.value = true; loading.value = true;
console.log(route);
// 从路由参数获取 taskId
const routeTaskId = route.query.id || route.params.id; const routeTaskId = route.query.id || route.params.id;
if (!routeTaskId) { if (!routeTaskId) {
showToast("缺少检测工单ID"); showToast("缺少检测工单ID");
...@@ -257,82 +256,70 @@ async function initializeData() { ...@@ -257,82 +256,70 @@ async function initializeData() {
} }
taskId.value = routeTaskId; taskId.value = routeTaskId;
console.log("开始加载检测模板,taskId:", taskId.value);
// 第一步:获取大项节点
const rootNodes = await getInspectionRootNodes(taskId.value); const rootNodes = await getInspectionRootNodes(taskId.value);
console.log("获取大项节点:", rootNodes);
if (!rootNodes || rootNodes.length === 0) { if (!rootNodes || rootNodes.length === 0) {
showToast("暂无检测模板数据"); showToast("暂无检测模板数据");
return; return;
} }
// 初始化大项列表,末尾追加固定的"检测评分"大项 const assembledBigModules: BigModule[] = [
const modulesData: BigModule[] = [ ...rootNodes.map((root) => ({
...rootNodes.map((rootNode) => ({ key: root.id,
key: rootNode.id, label: root.nodeName,
label: rootNode.nodeName, nodeId: root.id,
nodeId: rootNode.id,
subTabs: [], subTabs: [],
})), })),
{ key: SCORE_BIG_KEY, label: "检测评分", subTabs: [] }, { key: SCORE_BIG_KEY, label: "检测评分", subTabs: [] },
]; ];
bigModules.value = modulesData; bigModules.value = assembledBigModules;
console.log("大项列表:", bigModules.value);
// 设置初始选中的大项 const firstMain = bigModules.value[0];
if (bigModules.value.length > 0) { if (firstMain) {
activeBigKey.value = bigModules.value[0]!.key; activeBigKey.value = firstMain.key;
// 获取第一个大项的二级项 await loadSubTabsForBigModule(firstMain.key);
await loadSubTabs(bigModules.value[0]!.key);
} }
} catch (error) { } catch (error) {
console.error("初始化数据失败:", error); console.error("初始化检测页失败:", error);
showToast("加载检测模板失败"); showToast("加载检测模板失败");
} finally { } finally {
loading.value = false; loading.value = false;
} }
} }
// ===== 加载二级项 ===== // ===== 加载某大项下的二级项 =====
async function loadSubTabs(bigModuleKey: number | string) { async function loadSubTabsForBigModule(bigModuleKey: number | string) {
// 检测评分大项没有二级项,直接跳过
if (bigModuleKey === SCORE_BIG_KEY) return; if (bigModuleKey === SCORE_BIG_KEY) return;
try { try {
const bigModule = bigModules.value.find((m) => m.key === bigModuleKey); const targetBigModule = bigModules.value.find((module) => module.key === bigModuleKey);
if (!bigModule) return; if (!targetBigModule) return;
// 如果已经加载过,直接返回 if (targetBigModule.subTabs.length > 0) {
if (bigModule.subTabs.length > 0) { activeSubKey.value = targetBigModule.subTabs[0]!.key;
activeSubKey.value = bigModule.subTabs[0]!.key;
return; return;
} }
console.log(`开始加载大项 ${bigModule.label} 的二级项`); const childLevelNodes = await getInspectionChildren(bigModuleKey, taskId.value);
const subNodes = await getInspectionChildren(bigModuleKey, taskId.value);
console.log(`获取大项 ${bigModule.label} 的二级项:`, subNodes); let templateDefaultData: InspectionTemplateDefaultData | null = null;
try {
templateDefaultData = await getInspectionTemplateDefault(taskId.value);
} catch (error) {
console.error("获取模板默认值失败:", error);
}
bigModule.subTabs = (subNodes || []).map((node) => ({ targetBigModule.subTabs = (childLevelNodes || []).map((node) => ({
key: node.id, key: node.id,
label: node.nodeName, label: node.nodeName,
nodeId: node.id, nodeId: node.id,
leafNodes: node.childrenNodes ?? [], leafNodes: applyResolvedInitialValuesToLeafNodes(node.childrenNodes, templateDefaultData),
completedFlag: node.inspectionResultVO?.completedFlag ?? 0, completedFlag: node.inspectionResultVO?.completedFlag ?? 0,
})); }));
if (bigModule.subTabs.length > 0) { if (targetBigModule.subTabs.length > 0) {
activeSubKey.value = bigModule.subTabs[0]!.key; activeSubKey.value = targetBigModule.subTabs[0]!.key;
// 获取模板默认值
try {
const defaultData = await getInspectionTemplateDefault(taskId.value);
console.log("模板默认值:", defaultData);
} catch (error) {
console.error("获取模板默认值失败:", error);
}
} }
} catch (error) { } catch (error) {
console.error("加载二级项失败:", error); console.error("加载二级项失败:", error);
...@@ -345,36 +332,36 @@ function onOpenModulePicker() { ...@@ -345,36 +332,36 @@ function onOpenModulePicker() {
showModulePicker.value = true; showModulePicker.value = true;
} }
/** 切换大项前先静默保存当前二级项 */ /** 切换大项 / 二级项前静默落库当前叶子数据 */
async function saveCurrentSubTabSilently() { async function persistCurrentSubTabSilently() {
if (activeBigKey.value === SCORE_BIG_KEY) return; if (activeBigKey.value === SCORE_BIG_KEY) return;
try { try {
const leafNodes = (await contentRef.value?.collectData(false)) ?? []; const leafNodes = (await inspectSubContentRef.value?.collectData(false)) ?? [];
await saveInspectionRecord(buildSaveParams(leafNodes, false)); await saveInspectionRecord(buildInspectionSavePayload(leafNodes, false));
} catch { } catch {
// 静默失败,不阻断切换 // 静默失败,不阻断切换
} }
} }
async function onSelectBigModule(mod: BigModule) { async function onSelectBigModule(selectedBigModule: BigModule) {
showModulePicker.value = false; showModulePicker.value = false;
if (mod.key === activeBigKey.value) return; if (selectedBigModule.key === activeBigKey.value) return;
await saveCurrentSubTabSilently(); await persistCurrentSubTabSilently();
activeBigKey.value = mod.key; activeBigKey.value = selectedBigModule.key;
activeSubKey.value = ""; activeSubKey.value = "";
if (mod.key !== SCORE_BIG_KEY) { if (selectedBigModule.key !== SCORE_BIG_KEY) {
loadSubTabs(mod.key); loadSubTabsForBigModule(selectedBigModule.key);
} }
} }
async function onSelectSubTab(key: number | string) { async function onSelectSubTab(subTabKey: number | string) {
if (key === activeSubKey.value) return; if (subTabKey === activeSubKey.value) return;
await saveCurrentSubTabSilently(); await persistCurrentSubTabSilently();
activeSubKey.value = key; activeSubKey.value = subTabKey;
} }
/** 构造保存接口入参基础字段 */ /** 构造 `saveInspectionRecord` 请求体 */
function buildSaveParams(leafNodes: LeafNodeRecord[], nextFlag: boolean) { function buildInspectionSavePayload(leafNodes: LeafNodeRecord[], nextFlag: boolean) {
return { return {
taskId: taskId.value, taskId: taskId.value,
locationModule: activeBigModule.value?.nodeId ?? 0, locationModule: activeBigModule.value?.nodeId ?? 0,
...@@ -384,46 +371,45 @@ function buildSaveParams(leafNodes: LeafNodeRecord[], nextFlag: boolean) { ...@@ -384,46 +371,45 @@ function buildSaveParams(leafNodes: LeafNodeRecord[], nextFlag: boolean) {
}; };
} }
/** 跳转到下一个二级项 / 下一大项 / 检测评分大项 */ /** 进入下一二级项;若当前大项已走完则进入下一个主检测大项,否则进入评分大项 */
function goNext() { function advanceInspectionStep() {
if (!activeBigModule.value) return; const activeModule = activeBigModule.value;
const currentSubTabs = activeBigModule.value.subTabs; if (!activeModule) return;
const currentSubIdx = currentSubTabs.findIndex((s) => s.key === activeSubKey.value);
if (currentSubIdx < currentSubTabs.length - 1) { const subTabsOfActive = activeModule.subTabs;
// 同一大项内的下一个二级项 const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value);
activeSubKey.value = currentSubTabs[currentSubIdx + 1]!.key;
} else { if (activeSubIndex < subTabsOfActive.length - 1) {
// 寻找下一个大项(排除检测评分大项本身) activeSubKey.value = subTabsOfActive[activeSubIndex + 1]!.key;
const realBigModules = bigModules.value.filter((m) => m.key !== SCORE_BIG_KEY); return;
const bigIdx = realBigModules.findIndex((m) => m.key === activeBigKey.value); }
if (bigIdx < realBigModules.length - 1) {
const nextBig = realBigModules[bigIdx + 1]!; const mains = mainInspectionBigModules.value;
activeBigKey.value = nextBig.key; const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value);
loadSubTabs(nextBig.key).then(() => { if (activeMainIndex < mains.length - 1) {
activeSubKey.value = nextBig.subTabs[0]?.key ?? ""; const nextMain = mains[activeMainIndex + 1]!;
activeBigKey.value = nextMain.key;
loadSubTabsForBigModule(nextMain.key).then(() => {
activeSubKey.value = nextMain.subTabs[0]?.key ?? "";
}); });
} else { } else {
// 所有普通大项已完成,跳到检测评分大项
activeBigKey.value = SCORE_BIG_KEY; activeBigKey.value = SCORE_BIG_KEY;
activeSubKey.value = ""; activeSubKey.value = "";
} }
}
} }
/** 下一步(先校验,通过后保存并跳转) */ /** 下一步:校验当前叶子 → 保存 → 前进 */
async function onNext() { async function onNext() {
if (submitting.value) return; if (submitting.value) return;
try { try {
submitting.value = true; submitting.value = true;
const leafNodes = await contentRef.value?.collectData(true); const leafNodes = await inspectSubContentRef.value?.collectData(true);
// collectData 校验失败时返回 null,由子组件自行展示错误提示
if (leafNodes === null || leafNodes === undefined) { if (leafNodes === null || leafNodes === undefined) {
return; return;
} }
await saveInspectionRecord(buildSaveParams(leafNodes, true)); await saveInspectionRecord(buildInspectionSavePayload(leafNodes, true));
goNext(); advanceInspectionStep();
} catch { } catch {
showToast("保存失败,请重试"); showToast("保存失败,请重试");
} finally { } finally {
...@@ -435,42 +421,40 @@ function onBack() { ...@@ -435,42 +421,40 @@ function onBack() {
router.back(); router.back();
} }
/** 上一步:保存当前二级项数据,切换到前一个二级项 */ /** 上一步:先保存当前页,再退回上一二级项或上一大项 */
async function onPrev() { async function onPrev() {
if (submitting.value) return; if (submitting.value) return;
try { try {
submitting.value = true; submitting.value = true;
if (activeBigKey.value === SCORE_BIG_KEY) { if (activeBigKey.value === SCORE_BIG_KEY) {
// 评分页上一步:回到最后一个真实大项的最后一个二级项 const mains = mainInspectionBigModules.value;
const realBigModules = bigModules.value.filter((m) => m.key !== SCORE_BIG_KEY); const lastMain = mains[mains.length - 1];
const lastBig = realBigModules[realBigModules.length - 1]; if (lastMain) {
if (lastBig) { activeBigKey.value = lastMain.key;
activeBigKey.value = lastBig.key; await loadSubTabsForBigModule(lastMain.key);
await loadSubTabs(lastBig.key); activeSubKey.value = lastMain.subTabs[lastMain.subTabs.length - 1]?.key ?? "";
activeSubKey.value = lastBig.subTabs[lastBig.subTabs.length - 1]?.key ?? "";
} }
return; return;
} }
// 普通页上一步:先保存当前二级项,再跳到上一个 const leafNodes = (await inspectSubContentRef.value?.collectData(false)) ?? [];
const leafNodes = (await contentRef.value?.collectData(false)) ?? []; await saveInspectionRecord(buildInspectionSavePayload(leafNodes, false));
await saveInspectionRecord(buildSaveParams(leafNodes, false));
const currentSubTabs = activeBigModule.value?.subTabs ?? []; const subTabsOfActive = activeBigModule.value?.subTabs ?? [];
const currentSubIdx = currentSubTabs.findIndex((s) => s.key === activeSubKey.value); const activeSubIndex = subTabsOfActive.findIndex((subTab) => subTab.key === activeSubKey.value);
if (currentSubIdx > 0) { if (activeSubIndex > 0) {
activeSubKey.value = currentSubTabs[currentSubIdx - 1]!.key; activeSubKey.value = subTabsOfActive[activeSubIndex - 1]!.key;
} else { } else {
// 当前大项第一个二级项,退到上一个大项的最后一个二级项 const mains = mainInspectionBigModules.value;
const realBigModules = bigModules.value.filter((m) => m.key !== SCORE_BIG_KEY); const activeMainIndex = mains.findIndex((module) => module.key === activeBigKey.value);
const bigIdx = realBigModules.findIndex((m) => m.key === activeBigKey.value); if (activeMainIndex > 0) {
if (bigIdx > 0) { const previousMain = mains[activeMainIndex - 1]!;
const prevBig = realBigModules[bigIdx - 1]!; activeBigKey.value = previousMain.key;
activeBigKey.value = prevBig.key; await loadSubTabsForBigModule(previousMain.key);
await loadSubTabs(prevBig.key); activeSubKey.value =
activeSubKey.value = prevBig.subTabs[prevBig.subTabs.length - 1]?.key ?? ""; previousMain.subTabs[previousMain.subTabs.length - 1]?.key ?? "";
} }
} }
} catch { } catch {
...@@ -482,11 +466,11 @@ async function onPrev() { ...@@ -482,11 +466,11 @@ async function onPrev() {
/** 提交检测评分 */ /** 提交检测评分 */
async function onSubmitScore() { async function onSubmitScore() {
if (!scoreFormRef.value?.validate()) return; if (!inspectionScoreFormRef.value?.validate()) return;
if (submitting.value) return; if (submitting.value) return;
try { try {
submitting.value = true; submitting.value = true;
const formData = scoreFormRef.value.getFormData(); const formData = inspectionScoreFormRef.value.getFormData();
await completeInspection({ await completeInspection({
taskId: taskId.value, taskId: taskId.value,
exteriorScore: formData.appearanceScore, exteriorScore: formData.appearanceScore,
...@@ -506,9 +490,8 @@ async function onSubmitScore() { ...@@ -506,9 +490,8 @@ async function onSubmitScore() {
} }
} }
// ===== 生命周期 =====
onMounted(() => { onMounted(() => {
initializeData(); initializeInspection();
}); });
</script> </script>
...@@ -668,27 +651,6 @@ onMounted(() => { ...@@ -668,27 +651,6 @@ onMounted(() => {
padding: 0 $spacing-base $spacing-base; padding: 0 $spacing-base $spacing-base;
} }
.content-placeholder {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 300px;
gap: $spacing-sm;
padding: $spacing-xl;
.placeholder-title {
font-size: $font-size-base;
font-weight: 700;
color: $color-text-secondary;
}
.placeholder-desc {
font-size: $font-size-sm;
color: $color-text-disabled;
}
}
// ===== 加载状态 ===== // ===== 加载状态 =====
.loading-card { .loading-card {
display: flex; display: flex;
...@@ -741,21 +703,6 @@ onMounted(() => { ...@@ -741,21 +703,6 @@ onMounted(() => {
} }
.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 { .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));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!