diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 70f79cd2..a2bf0dab 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -636,11 +636,14 @@ const prevService = ref({ productTypeId: '', }); +const currentService = ref(); + async function assignFormDataProductService(id: string) { const res = await fetchListServiceById(id); if (res) { statusToggle.value = res.status === 'INACTIVE' ? false : true; + currentService.value = JSON.parse(JSON.stringify(res)); prevService.value = { code: res.code, @@ -674,7 +677,7 @@ async function assignFormDataProductService(id: string) { product: item.productOnWork.map((productOnWorkItem) => { return { ...productOnWorkItem.product, - nameEn: '', + nameEn: productOnWorkItem.product.name, }; }), }; @@ -945,6 +948,28 @@ async function fetchSearch() { } } +function cloneData() { + if (!currentService.value) return; + formDataProductService.value = { + ...prevService.value, + attributes: JSON.parse(JSON.stringify(currentService.value.attributes)), + }; + + workItems.value = currentService.value.work.map((item) => { + return { + id: item.id, + name: item.name, + attributes: JSON.parse(JSON.stringify(item.attributes)), + product: item.productOnWork.map((productOnWorkItem) => { + return { + ...productOnWorkItem.product, + nameEn: productOnWorkItem.product.name, + }; + }), + }; + }); +} + onMounted(async () => { calculateStats(); await fetchListGroups(); @@ -2160,7 +2185,7 @@ watch(currentPageService, async () => { :undo=" () => { infoServiceEdit = false; - formDataProductService = { ...prevService }; + cloneData(); statusToggle = prevService.status === 'INACTIVE' ? false : true; flowStore.rotate(); }