Commit 21e9265f by chenwq1

refactor: 更新检查报告接口与表单逻辑

- 修改 `locationSubModule` 字段类型,支持 null 值以处理无二级分组的情况。
- 优化 `setSubmitData` 函数,确保在数据提交时包含所有叶子节点。
- 移除不必要的深度观察器,简化 `car-detail` 组件的逻辑。
1 parent c54f3162
Pipeline #99 for 21e9265f failed in 0 seconds
......@@ -435,8 +435,8 @@ export interface InspectionRecordSaveParams {
taskId: number | string;
/** 大项 nodeId */
locationModule: number | string;
/** 二级项 nodeId */
locationSubModule: number | string;
/** 二级项 nodeId;无二级分组时为 null */
locationSubModule: number | string | null;
/** true = 保存并跳下一步,false = 仅保存 */
nextFlag: boolean;
leafNodes: LeafNodeRecord[];
......
......@@ -41,7 +41,7 @@ function setSubmitData() {
let dataList: never[] = [];
const inputList = ['text_input', 'textarea_input', 'number_input', 'date_picker'];
const dropdownList = ['dropdown', 'radio_button_select'];
if (inputList.includes(item.interactionType) && item.value) {
if (inputList.includes(item.interactionType) && item.value != null && item.value !== "") {
const pushData = {
id: item.id,
valueText: item.value || '',
......@@ -86,9 +86,14 @@ function setSubmitData() {
}
}
}
if (dataList && dataList.length > 0) {
returnData.push({ nodeId: item.id, nodeName: item.nodeName, resultStatus: resultStatus.value ? 3 : 1, remark: '', data: dataList });
}
// 每项都入列,便于大项/二级切换时静默保存仍能带上当前 Tab 全部叶子(未填则为空 data,仍会走保存接口)
returnData.push({
nodeId: item.id,
nodeName: item.nodeName,
resultStatus: resultStatus.value ? 3 : 1,
remark: "",
data: dataList,
});
});
return returnData;
}
......
......@@ -162,13 +162,12 @@ import type {
} from "@/types/views/car-detail";
import type {
CompleteInspectionResultData,
InspectionNode,
InspectionResultVO,
InspectionTemplateDefaultData,
LeafNodeRecord,
} from "@api";
import { computed, onMounted, ref, watch } from "vue";
import { computed, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import customizeForm from "@/components/customizeForm/Index.vue";
......@@ -260,23 +259,7 @@ const activeSubTab = computed(
/** 当前二级项下的叶子节点(loadSubTabsForBigModule 内已合并模板默认值) */
const currentLeafNodes = computed(() => activeSubTab.value?.leafNodes ?? []);
watch(
() => ({
activeSubTabProp: activeBigModule.value,
bigModuleLabel: activeBigModule.value?.label,
leafNodes: currentLeafNodes.value,
subTabLabel: activeSubTab.value?.label,
}),
(payload: {
activeSubTabProp: BigModule | undefined;
bigModuleLabel?: string;
leafNodes: InspectionNode[];
subTabLabel?: string;
}) => {
console.log("[car-detail → CustomizeForm]", payload);
},
{ deep: true, immediate: true },
);
// ===== 初始化 =====
async function initializeInspection() {
......@@ -434,10 +417,12 @@ function onOpenModulePicker() {
/** 构造 `saveInspectionRecord` 请求体 */
function buildInspectionSavePayload(leafNodes: LeafNodeRecord[], nextFlag: boolean) {
const hasSecondaryTabs = activeBigModule.value?.hasSecondaryTabs === true;
return {
taskId: taskId.value,
locationModule: activeBigModule.value?.nodeId ?? 0,
locationSubModule: activeSubTab.value?.nodeId ?? 0,
/** 叶子直挂大项(无二级分组)时后端约定传 null,不用与大项重复的 nodeId */
locationSubModule: hasSecondaryTabs ? (activeSubTab.value?.nodeId ?? 0) : null,
nextFlag,
leafNodes,
};
......@@ -490,6 +475,7 @@ function leafRecordFromValidateNode(raw: CustomizeFormValidateNode): LeafNodeRec
async function saveCurrentLeafInspectionRecord(nextFlag: boolean): Promise<boolean> {
const saved = (await customizeFormRef.value?.saveData?.()) as CustomizeFormValidateResult | undefined;
const rows = saved?.data;
console.log("saveCurrentLeafInspectionRecord", rows);
if (!rows?.length) return false;
const leafNodes = rows.map((row) => leafRecordFromValidateNode(row));
await saveInspectionRecord(buildInspectionSavePayload(leafNodes, nextFlag));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!