Commit 5eb46cf9 by chenwq1

fix: 版本更新

1 parent cfad23a6
......@@ -15,10 +15,10 @@
</div>
</div>
<div class="customizeFormBox" v-if="activeNodeId != -1">
<CustomizeForm ref="customizeFormRef" @submitSuccess="getTemplateData('0')" />
<CustomizeForm ref="customizeFormRef" @submitSuccess="onFormSubmitSuccess" />
</div>
<div class="customizeFormBox" v-if="activeNodeId == -1">
<TestingScore ref="testingScoreRef" @submitSuccess="getTemplateData('0')" />
<TestingScore ref="testingScoreRef" @submitSuccess="onFormSubmitSuccess" />
</div>
</div>
</template>
......@@ -48,6 +48,8 @@ export default class DetectionOrderEdit extends PaginationComponent<Vehicle> {
nodeList: any = [];
activeNodeId: number = null;
/** 本次编辑会话内已成功保存过的一级类目 */
savedNodeIds = new Set<number>();
carTypeList: any = [];
inspectionNodeList: any = [];
......@@ -170,8 +172,49 @@ export default class DetectionOrderEdit extends PaginationComponent<Vehicle> {
});
}
onFormSubmitSuccess() {
if (this.activeNodeId != null) {
this.savedNodeIds.add(Number(this.activeNodeId));
}
this.getTemplateData('0');
}
getActiveFormRef(): any {
if (Number(this.activeNodeId) === -1) {
return this.$refs.testingScoreRef;
}
return this.$refs.customizeFormRef;
}
hasUnsavedChanges(): boolean {
const form = this.getActiveFormRef();
return !!form?.hasUnsavedChanges?.();
}
isCurrentTabSaved(): boolean {
const nodeId = Number(this.activeNodeId);
if (this.savedNodeIds.has(nodeId)) {
return true;
}
const node = (this.nodeList || []).find(
(n) => Number(n.id) === nodeId,
);
return node?.completedFlag == '1';
}
needsConfirmLeave(): boolean {
if (this.isCurrentTabSaved() && !this.hasUnsavedChanges()) {
return false;
}
return this.hasUnsavedChanges() || !this.isCurrentTabSaved();
}
handleNodeList(item: any) {
if (item.id == this.activeNodeId) return;
if (!this.needsConfirmLeave()) {
this.switchNode(item);
return;
}
Modal.confirm({
title: '提示',
content: '当前一级类目下,存在必填检测项未完成,强制离开将丢失数据,请完成检查后切换tab或离开标签页。',
......
......@@ -354,6 +354,10 @@ export default class CustomizeForm extends Vue {
this.leafIdToName = nameMap;
}
hasUnsavedChanges(): boolean {
return this.collectModifiedFieldNames().length > 0;
}
collectModifiedFieldNames(): string[] {
const current: Record<string, any> = {};
const walk = (nodes: any[] = []) => {
......
......@@ -403,6 +403,10 @@ export default class TestingScore extends Vue {
this.initialPostData = snap;
}
hasUnsavedChanges(): boolean {
return this.collectModifiedFieldNames().length > 0;
}
collectModifiedFieldNames(): string[] {
const current: Record<string, any> = {};
Object.keys(this.postData).forEach((k) => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!