From b6e7eb68cd6b82d298be2a1502d132d356cc6be2 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:51:45 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84?= =?UTF-8?q?=E0=B8=82=20=E0=B9=81=E0=B8=A5=E0=B8=B0=20=E0=B8=A5=E0=B8=9A=20?= =?UTF-8?q?=20=E0=B8=82=E0=B8=AD=E0=B8=87=20Product?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/04_product-service/MainPage.vue | 84 ++++++++++++++++++++--- src/stores/product-service/index.ts | 21 ++++-- src/stores/product-service/types.ts | 1 + 3 files changed, 91 insertions(+), 15 deletions(-) diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 304f7d10..ee00133c 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -53,6 +53,8 @@ const { fetchStatsProduct, fetchListProduct, createProduct, + editProduct, + deleteProduct, fetchListService, fetchListServiceById, @@ -87,8 +89,11 @@ const isEdit = ref(false); const dialogInputForm = ref(false); const dialogProduct = ref(false); const dialogService = ref(false); +const dialogProductEdit = ref(false); const statusToggle = ref(false); const profileSubmit = ref(false); +const infoProductEdit = ref(false); + const imageProduct = ref(undefined); const profileUrl = ref(''); @@ -151,6 +156,7 @@ const propertiesDialog = ref(false); const currentId = ref(''); const currentIdType = ref(''); const currentIdService = ref(''); +const currentIdProduct = ref(''); const resultSearchGroup = ref(); const resultSearchType = ref<(ProductGroup & { productGroupId: string })[]>(); @@ -297,6 +303,27 @@ async function deleteServiceById(serviceId?: string) { }); } +async function deleteTypeOfProduct(id?: string) { + dialog({ + color: 'negative', + icon: 'mdi-alert', + title: t('deleteConfirmTitle'), + actionText: t('ok'), + persistent: true, + message: t('deleteConfirmMessage'), + action: async () => { + await deleteProduct(id ?? currentIdProduct.value); + await fetchListOfProduct(currentIdType.value); + + dialogProductEdit.value = false; + + stat.value[3].count = stat.value[3].count - 1; + }, + cancel: () => {}, + }); +} + +// type or group async function deleteProductById(productId?: string) { dialog({ color: 'negative', @@ -413,6 +440,7 @@ function clearFormProduct() { }; dialogProduct.value = false; + dialogProductEdit.value = false; } function clearFormService() { @@ -443,10 +471,16 @@ async function submitProduct() { formDataProduct.value.image = imageProduct.value; } - const res = await createProduct(formDataProduct.value); + if (dialogProduct.value) { + const res = await createProduct(formDataProduct.value); - if (res) { - stat.value[3].count = stat.value[3].count + 1; + if (res) { + stat.value[3].count = stat.value[3].count + 1; + } + } + + if (dialogProductEdit.value) { + await editProduct(currentIdProduct.value, formDataProduct.value); } clearFormProduct(); @@ -528,7 +562,7 @@ watch(currentStatus, async () => { > { :price="i.price" :process="i.process" :id="i.id" - @viewDetail="() => {}" + @menuViewDetail=" + () => { + currentIdProduct = i.id; + assignFormDataProduct(i); + dialogProductEdit = true; + } + " + @menuEdit=" + () => { + currentIdProduct = i.id; + infoProductEdit = true; + assignFormDataProduct(i); + dialogProductEdit = true; + } + " + @viewDetail=" + () => { + currentIdProduct = i.id; + assignFormDataProduct(i); + dialogProductEdit = true; + } + " /> @@ -1089,7 +1144,7 @@ watch(currentStatus, async () => { v-model:modal="dialogProduct" noAddress noAppBox - title="เพิ่มสินค้า" + :title="$t('buttonAddProduct')" :submit=" () => { submitProduct(); @@ -1132,10 +1187,19 @@ watch(currentStatus, async () => { @@ -1159,6 +1223,7 @@ watch(currentStatus, async () => { { separator /> { } } - async function editProduct(productId: string, data: ProductUpdate) { - const { ...payload } = data; + async function editProduct(productId: string, data: ProductCreate) { + const { image, code, ...payload } = data; - const res = await api.put(`/product/${productId}`, { - ...payload, - }); + const res = await api.put( + `/product/${productId}`, + { + ...payload, + }, + ); - if (!res) return false; + image && + (await axios + .put(res.data.imageUploadUrl, image, { + headers: { 'Content-Type': image.type }, + onUploadProgress: (e) => console.log(e), + }) + .catch((e) => console.error(e))); if (res.status === 200) { return res.data; diff --git a/src/stores/product-service/types.ts b/src/stores/product-service/types.ts index 635c8597..8bd9deeb 100644 --- a/src/stores/product-service/types.ts +++ b/src/stores/product-service/types.ts @@ -110,6 +110,7 @@ export interface ProductCreate { } export interface ProductUpdate { + productTypeId: string; remark: string; serviceCharge: number; agentPrice: number;