diff --git a/src/components/04_product-service/BasicInformation.vue b/src/components/04_product-service/BasicInformation.vue index ba6fc5c1..70e58a2b 100644 --- a/src/components/04_product-service/BasicInformation.vue +++ b/src/components/04_product-service/BasicInformation.vue @@ -180,9 +180,11 @@ const detailEditorImageDrop = createEditorImageDrop(detail); > ({ + attributes: v.attributes, + id: v.id, + name: v.name, + product: v.productOnWork.map((p) => ({ + id: p.productId, + installmentNo: p.installmentNo, + stepCount: p.stepCount, + })), + })) + : [], + status: isEdit ? currentService.value?.status : undefined, + productGroupId: isEdit ? currentService.value?.productGroupId : '', + installments: isEdit ? currentService.value?.installments : 1, + selectedImage: isEdit ? currentService.value?.selectedImage : '', + }; + + if ( + deepEquals( + isEdit + ? formService.value + : { + ...formService.value, + selectedImage: '', + detail: formService.value.detail.replace(/<\/?[^>]+(>|$)/g, ''), + }, + defaultFormService, + ) + ) { + return true; + } + return false; +} + function assignFormDataProductServiceCreate() { formService.value.work = []; @@ -3957,13 +4007,21 @@ watch( submitService(); } " - :close=" + :before-close=" () => { - clearFormService(); - dialogService = false; - serviceTreeView = false; - onCreateImageList = { selectedImage: '', list: [] }; - flowStore.rotate(); + if (workItems.length > 0 || !sameFormService()) { + dialogWarningClose($t, { + action: () => { + clearFormService(); + dialogService = false; + serviceTreeView = false; + onCreateImageList = { selectedImage: '', list: [] }; + flowStore.rotate(); + }, + cancel: () => {}, + }); + return true; + } else return false; } " > @@ -4288,12 +4346,21 @@ watch( submitService(); } " - :close=" + :before-close=" () => { - clearFormService(); - flowStore.rotate(); - serviceTreeView = false; - dialogServiceEdit = false; + if (!sameFormService()) { + dialogWarningClose($t, { + action: () => { + clearFormService(); + dialogService = false; + serviceTreeView = false; + onCreateImageList = { selectedImage: '', list: [] }; + flowStore.rotate(); + }, + cancel: () => {}, + }); + return true; + } else return false; } " > diff --git a/src/utils/arr.ts b/src/utils/arr.ts index 091f3cbb..88ff45d4 100644 --- a/src/utils/arr.ts +++ b/src/utils/arr.ts @@ -13,3 +13,46 @@ export function insertAt(arr: T[], idx: number, item: T) { } export default arr; + +export function deepEquals( + obj1: Record, + obj2: Record, +): boolean { + // If both objects are the same reference, they are deeply equal + if (obj1 === obj2) { + return true; + } + + // If either object is not an object or null, they are not deeply equal + if ( + typeof obj1 !== 'object' || + obj1 === null || + typeof obj2 !== 'object' || + obj2 === null + ) { + return false; + } + + // Get the set of keys for both objects + const keys1 = Object.keys(obj1); + const keys2 = Object.keys(obj2); + + // If the number of keys is different, they are not deeply equal + if (keys1.length !== keys2.length) { + return false; + } + + // Check if all keys in obj1 exist in obj2 + for (const key of keys1) { + if (!keys2.includes(key)) { + return false; + } + + // Recursively check if the values for each key are deeply equal + if (!deepEquals(obj1[key], obj2[key])) { + return false; + } + } + + return true; +}