From 372d63f99eb64d1daeeacee1fdb621dea1b29a82 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:26:49 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B8=95=E0=B9=88=E0=B8=AD=20api=20=20?= =?UTF-8?q?=E0=B8=88=E0=B8=B3=E0=B8=99=E0=B8=A7=E0=B8=99=20=E0=B8=82?= =?UTF-8?q?=E0=B8=AD=E0=B8=87=20=20Product?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/04_product-service/MainPage.vue | 10 +++++++++- src/stores/product-service/index.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 9df04619..d3fddabb 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -47,6 +47,7 @@ const { editProductService, deleteProductService, + fetchStatsProduct, fetchListProduct, createProduct, @@ -438,7 +439,11 @@ async function submitProduct() { formDataProduct.value.image = imageProduct.value; } - await createProduct(formDataProduct.value); + const res = await createProduct(formDataProduct.value); + + if (res) { + stat.value[3].count = stat.value[3].count + 1; + } dialogProduct.value = false; await fetchListOfProduct(currentIdType.value); @@ -463,8 +468,11 @@ async function submitGroup() { onMounted(async () => { const resStatsGroup = await fetchStatsProductGroup(); const resStatsType = await fetchStatsProductType(); + const resStatsProduct = await fetchStatsProduct(); + stat.value[0].count = resStatsGroup ?? 0; stat.value[1].count = resStatsType ?? 0; + stat.value[3].count = resStatsProduct ?? 0; await fetchListGroups(); }); diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 42945558..73290434 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -239,6 +239,17 @@ const useProductServiceStore = defineStore('api-product-service', () => { } // Product + + async function fetchStatsProduct() { + const res = await api.get('/product/stats'); + + if (!res) return false; + + if (res.status === 200) { + return res.data; + } + } + async function fetchListProduct( opts?: { query?: string; @@ -500,6 +511,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { editProductService, deleteProductService, + fetchStatsProduct, fetchListProduct, createProduct, fetchListProductById,