feat: แก้ไขและลบ บริการ

This commit is contained in:
Net 2024-06-21 14:50:43 +07:00
parent 2034362c6d
commit a774fa1afe

View file

@ -63,6 +63,7 @@ const {
fetchListServiceById, fetchListServiceById,
createService, createService,
deleteService, deleteService,
editService,
} = productServiceStore; } = productServiceStore;
import ItemCard from 'src/components/ItemCard.vue'; import ItemCard from 'src/components/ItemCard.vue';
@ -92,13 +93,17 @@ const searchTotalProduct = ref<string>('');
const drawerInfo = ref<boolean>(false); const drawerInfo = ref<boolean>(false);
const isEdit = ref<boolean>(false); const isEdit = ref<boolean>(false);
const dialogInputForm = ref<boolean>(false); const dialogInputForm = ref<boolean>(false);
const dialogProduct = ref<boolean>(false); const dialogProduct = ref<boolean>(false);
const dialogService = ref<boolean>(false); const dialogService = ref<boolean>(false);
const dialogProductEdit = ref<boolean>(false); const dialogProductEdit = ref<boolean>(false);
const dialogServiceEdit = ref<boolean>(false);
const statusToggle = ref<boolean>(false); const statusToggle = ref<boolean>(false);
const profileSubmit = ref<boolean>(false); const profileSubmit = ref<boolean>(false);
const infoProductEdit = ref<boolean>(false); const infoProductEdit = ref<boolean>(false);
const infoServiceEdit = ref<boolean>(false);
const imageProduct = ref<File | undefined>(undefined); const imageProduct = ref<File | undefined>(undefined);
const profileUrl = ref<string | null>(''); const profileUrl = ref<string | null>('');
@ -332,6 +337,8 @@ async function deleteServiceById(serviceId?: string) {
await deleteService(serviceId ?? currentIdService.value); await deleteService(serviceId ?? currentIdService.value);
await fetchListOfService(); await fetchListOfService();
dialogServiceEdit.value = false;
}, },
cancel: () => {}, cancel: () => {},
}); });
@ -430,6 +437,20 @@ async function assignFormDataProductService(id: string) {
), ),
}); });
}); });
workItems.value = res.work.map((item) => {
return {
id: item.id,
name: item.name,
attributes: item.attributes,
product: item.productOnWork.map((productOnWorkItem) => {
return {
...productOnWorkItem.product,
nameEn: '',
};
}),
};
});
} }
} }
@ -490,11 +511,15 @@ function clearFormService() {
work: [], work: [],
}; };
workItems.value = [];
selectProduct.value = []; selectProduct.value = [];
dialogService.value = false; dialogService.value = false;
dialogServiceEdit.value = false;
} }
function assignFormDataProductServiceCreate() { function assignFormDataProductServiceCreate() {
formDataProductService.value.work = [];
workItems.value.forEach((item) => { workItems.value.forEach((item) => {
formDataProductService.value.work.push({ formDataProductService.value.work.push({
name: item.name, name: item.name,
@ -506,9 +531,22 @@ function assignFormDataProductServiceCreate() {
async function submitService() { async function submitService() {
assignFormDataProductServiceCreate(); assignFormDataProductServiceCreate();
const res = await createService(formDataProductService.value); formDataProductService.value.image = imageProduct.value;
if (res) {
await fetchListOfService(); if (dialogService.value) {
const res = await createService(formDataProductService.value);
if (res) {
await fetchListOfService();
}
}
if (dialogServiceEdit.value) {
const res = await editService(currentIdService.value, {
...formDataProductService.value,
});
if (res) {
await fetchListOfService();
}
} }
clearFormService(); clearFormService();
@ -1126,25 +1164,18 @@ watch(currentStatus, async () => {
:created-at="i.createdAt" :created-at="i.createdAt"
@menuViewDetail=" @menuViewDetail="
() => { () => {
currentIdProduct = i.id; currentIdService = i.id;
infoServiceEdit = false;
assignFormDataProductService(i.id); assignFormDataProductService(i.id);
dialogProductEdit = true; dialogServiceEdit = true;
} }
" "
@menuEdit=" @menuEdit="
() => { () => {
currentIdProduct = i.id; currentIdService = i.id;
infoProductEdit = true; infoServiceEdit = true;
assignFormDataProductService(i.id); assignFormDataProductService(i.id);
dialogProductEdit = true; dialogServiceEdit = true;
}
"
@viewDetail="
() => {
currentIdProduct = i.id;
infoProductEdit = false;
assignFormDataProductService(i.id);
dialogProductEdit = true;
} }
" "
/> />
@ -1289,6 +1320,10 @@ watch(currentStatus, async () => {
:isAddProduct="!!selectProduct.find((v) => v.id === i.id)" :isAddProduct="!!selectProduct.find((v) => v.id === i.id)"
:isSelected="true" :isSelected="true"
:data="i" :data="i"
:code="i.code"
:price="i.price"
:process="i.process"
:id="i.id"
typeProduct="product" typeProduct="product"
:title="i.name" :title="i.name"
:status="i.status === 'INACTIVE' ? true : false" :status="i.status === 'INACTIVE' ? true : false"
@ -1562,6 +1597,84 @@ watch(currentStatus, async () => {
> >
<WorkNameManagement /> <WorkNameManagement />
</FormDialog> </FormDialog>
<!-- edit service -->
<FormDialog
no-address
edit
:isEdit="infoServiceEdit"
:title="$t('service', { msg: formDataProductService.name })"
v-model:modal="dialogServiceEdit"
v-model:tabs-list="serviceTab"
v-model:current-tab="currentServiceTab"
:submit="
() => {
submitService();
}
"
:close="
() => {
clearFormService();
dialogServiceEdit = false;
}
"
:edit-data="
() => {
infoServiceEdit = true;
}
"
:undo="() => (infoServiceEdit = false)"
:delete-data="() => deleteServiceById()"
>
<template #prepend>
<ProfileUpload
isService
v-model:url-profile="profileUrl"
v-model:status-toggle="statusToggle"
v-model:profile-submit="profileSubmit"
@input-file="inputFile.click()"
/>
</template>
<template #information>
<BasicInformation
:readonly="!infoServiceEdit"
v-if="currentServiceTab === 'serviceInformation'"
dense
service
@service-properties="
() => {
tempValueProperties = formDataProductService.attributes;
openPropertiesDialog('service');
}
"
v-model:service-code="formDataProductService.code"
v-model:service-description="formDataProductService.detail"
v-model:service-name-th="formDataProductService.name"
@input-file="inputFile.click()"
/>
<FormServiceWork
:readonly="!infoServiceEdit"
v-model:work-items="workItems"
v-if="currentServiceTab === 'workInformation'"
dense
@addProduct="
(index) => {
currentWorkIndex = index;
dialogTotalProduct = true;
}
"
@manage-work-name="manageWorkNameDialog = true"
@work-properties="
(index) => {
currentWorkIndex = index;
tempValueProperties = workItems[index].attributes;
openPropertiesDialog('work');
}
"
/>
</template>
</FormDialog>
</template> </template>
<style scoped> <style scoped>