feat: cancel edit on service dialog

This commit is contained in:
puriphatt 2024-06-26 08:09:02 +00:00
parent 018edf688b
commit d1bb3d9456

View file

@ -100,7 +100,6 @@ const stat = ref<
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { onMounted } from 'vue'; import { onMounted } from 'vue';
import { time } from 'console';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
const { t } = useI18n(); const { t } = useI18n();
@ -618,12 +617,14 @@ const prevService = ref<ServiceCreate>({
code: '', code: '',
productTypeId: '', productTypeId: '',
}); });
const currentService = ref<ServiceById>();
async function assignFormDataProductService(id: string) { async function assignFormDataProductService(id: string) {
const res = await fetchListServiceById(id); const res = await fetchListServiceById(id);
if (res) { if (res) {
statusToggle.value = res.status === 'INACTIVE' ? false : true; statusToggle.value = res.status === 'INACTIVE' ? false : true;
currentService.value = JSON.parse(JSON.stringify(res));
prevService.value = { prevService.value = {
code: res.code, code: res.code,
@ -657,7 +658,7 @@ async function assignFormDataProductService(id: string) {
product: item.productOnWork.map((productOnWorkItem) => { product: item.productOnWork.map((productOnWorkItem) => {
return { return {
...productOnWorkItem.product, ...productOnWorkItem.product,
nameEn: '', nameEn: productOnWorkItem.product.name,
}; };
}), }),
}; };
@ -918,6 +919,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 () => { onMounted(async () => {
calculateStats(); calculateStats();
await fetchListGroups(); await fetchListGroups();
@ -2116,7 +2139,7 @@ watch(currentPageService, async () => {
:undo=" :undo="
() => { () => {
infoServiceEdit = false; infoServiceEdit = false;
formDataProductService = { ...prevService }; cloneData();
statusToggle = prevService.status === 'INACTIVE' ? false : true; statusToggle = prevService.status === 'INACTIVE' ? false : true;
} }
" "
@ -2142,12 +2165,6 @@ watch(currentPageService, async () => {
v-if="currentServiceTab === 'serviceInformation'" v-if="currentServiceTab === 'serviceInformation'"
dense dense
service service
@service-properties="
() => {
tempValueProperties = formDataProductService.attributes;
openPropertiesDialog('service');
}
"
v-model:service-code="formDataProductService.code" v-model:service-code="formDataProductService.code"
v-model:service-description="formDataProductService.detail" v-model:service-description="formDataProductService.detail"
v-model:service-name-th="formDataProductService.name" v-model:service-name-th="formDataProductService.name"