From 86099a9573d7576d3fbcc56d7ea995a33cb588bd Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:31:08 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E0=B9=81=E0=B8=81=E0=B9=89=20=E0=B8=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=20=E0=B8=A2=E0=B8=B4=E0=B8=87=20=20api=20=20?= =?UTF-8?q?3=20=E0=B9=80=E0=B8=AA=E0=B9=89=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/04_product-service/MainPage.vue | 284 ++++++++++++++++------ 1 file changed, 216 insertions(+), 68 deletions(-) diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index c4ed96d6..6755949b 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -35,6 +35,7 @@ import { ServiceById, WorkItems, Attributes, + ServiceAndProduct, } from 'src/stores/product-service/types'; const productServiceStore = useProductServiceStore(); @@ -74,6 +75,8 @@ const { fetchListProductByIdWork, fetchListOfWork, + + fetchListProductAndService, } = productServiceStore; const { workNameItems } = storeToRefs(productServiceStore); @@ -131,9 +134,10 @@ const productMode = ref<'group' | 'type' | 'service' | 'product'>('group'); const productGroup = ref(); const productType = ref(); -const product = ref(); +const product = ref<(ProductList & { type: 'product' })[]>(); +const service = ref<(Service & { type: 'service' })[]>(); const resultSearchProduct = ref(); -const service = ref(); +const productAndService = ref([]); const productAndServiceTab = ref('all'); const manageWorkNameDialog = ref(false); @@ -169,6 +173,7 @@ const formDataProductService = ref({ detail: '', name: '', code: '', + productTypeId: '', }); const serviceTab = [ @@ -192,6 +197,10 @@ const selectProduct = ref([]); const currentWorkIndex = ref(0); +const totalProduct = ref(0); +const totalService = ref(0); +const totalProductAndService = ref(0); + const currentId = ref(''); const currentIdType = ref(''); const currentIdService = ref(''); @@ -242,6 +251,20 @@ async function searchProduct() { } } +async function featchStatsService() { + const resStatsService = await fetchStatsService(); + + totalService.value = resStatsService; +} + +async function featchStatsProduct() { + const resStatsProduct = await fetchStatsProduct({ + productTypeId: currentIdType.value, + }); + + totalProduct.value = resStatsProduct; +} + async function fetchListType() { const res = await fetchListProductServiceType({ productGroupId: currentId.value, @@ -274,18 +297,44 @@ async function fetchListGroups() { } async function fetchListOfProduct(productTypeId: string) { - const res = await fetchListProduct({ productTypeId }); + const res = await fetchListProduct({ + status: + currentStatus.value === 'INACTIVE' + ? 'INACTIVE' + : currentStatus.value === 'ACTIVE' + ? 'ACTIVE' + : undefined, + productTypeId, + }); if (res) { - product.value = res.result; + product.value = res.result.map((v) => { + return { + ...v, + type: 'product', + }; + }); } } async function fetchListOfService() { - const res = await fetchListService({ productTypeId: currentIdType.value }); + const res = await fetchListService({ + status: + currentStatus.value === 'INACTIVE' + ? 'INACTIVE' + : currentStatus.value === 'ACTIVE' + ? 'ACTIVE' + : undefined, + productTypeId: currentIdType.value, + }); if (res) { - service.value = res.result; + service.value = res.result.map((v) => { + return { + ...v, + type: 'service', + }; + }); } } @@ -366,6 +415,25 @@ async function toggleStatusGroup(id: string, status: Status) { await fetchListGroups(); } +async function fetchListOfProductAndService() { + const res = await fetchListProductAndService({ + status: + currentStatus.value === 'INACTIVE' + ? 'INACTIVE' + : currentStatus.value === 'ACTIVE' + ? 'ACTIVE' + : undefined, + productTypeId: currentIdType.value, + }); + + if (res) { + if (currentStatus.value === 'All') { + totalProductAndService.value = res.total; + } + productAndService.value = res.result; + } +} + async function deleteServiceById(serviceId?: string) { dialog({ color: 'negative', @@ -375,11 +443,15 @@ async function deleteServiceById(serviceId?: string) { persistent: true, message: t('deleteConfirmMessage'), action: async () => { - await deleteService(serviceId ?? currentIdService.value); + const res = await deleteService(serviceId ?? currentIdService.value); await fetchListOfService(); dialogServiceEdit.value = false; + + if (res) { + totalService.value = totalService.value - 1; + } calculateStats(); }, cancel: () => {}, @@ -395,11 +467,14 @@ async function deleteTypeOfProduct(id?: string) { persistent: true, message: t('deleteConfirmMessage'), action: async () => { - await deleteProduct(id ?? currentIdProduct.value); + const res = await deleteProduct(id ?? currentIdProduct.value); await fetchListOfProduct(currentIdType.value); dialogProductEdit.value = false; + if (res) { + totalProduct.value = totalProduct.value - 1; + } calculateStats(); }, cancel: () => {}, @@ -464,6 +539,7 @@ const prevService = ref({ detail: '', name: '', code: '', + productTypeId: '', }); async function assignFormDataProductService(id: string) { @@ -479,6 +555,7 @@ async function assignFormDataProductService(id: string) { attributes: res.attributes, work: [], status: res.status, + productTypeId: res.productTypeId, }; formDataProductService.value = { ...prevService.value }; @@ -567,6 +644,7 @@ function clearFormService() { }, work: [], status: undefined, + productTypeId: '', }; workItems.value = []; @@ -590,6 +668,7 @@ function assignFormDataProductServiceCreate() { async function submitService() { assignFormDataProductServiceCreate(); formDataProductService.value.image = imageProduct.value; + formDataProductService.value.productTypeId = currentIdType.value; if (dialogService.value) { const res = await createService(formDataProductService.value); @@ -609,7 +688,7 @@ async function submitService() { await fetchListOfService(); } } - + totalService.value = totalService.value + 1; clearFormService(); } @@ -633,7 +712,7 @@ async function submitProduct() { status: statusToggle.value ? 'ACTIVE' : 'INACTIVE', }); } - + totalProduct.value = totalProduct.value + 1; clearFormProduct(); await fetchListOfProduct(currentIdType.value); } @@ -714,6 +793,19 @@ async function calculateStats() { stat.value[3].count = resStatsProduct ?? 0; } +async function fetchStatus() { + if (productAndServiceTab.value === 'all') { + await fetchListOfProductAndService(); + } + if (productAndServiceTab.value === 'product') { + await fetchListOfProduct(currentIdType.value); + } + + if (productAndServiceTab.value === 'service') { + await fetchListOfService(); + } +} + onMounted(async () => { calculateStats(); await fetchListGroups(); @@ -937,21 +1029,33 @@ watch(currentStatus, async () => { {{ $t('all') }} {{ $t('statusACTIVE') }} {{ $t('statusINACTIVE') }} @@ -1013,8 +1117,12 @@ watch(currentStatus, async () => { pathTypeName = v.name; currentIdType = v.id; productMode = 'service'; - await fetchListOfProduct(currentIdType); - await fetchListOfService(); + // await fetchListOfProduct(currentIdType); + // await fetchListOfService(); + + await featchStatsService(); + await featchStatsProduct(); + await fetchListOfProductAndService(); } " /> @@ -1079,7 +1187,15 @@ watch(currentStatus, async () => {
- +
- +
- +
@@ -1175,21 +1307,36 @@ watch(currentStatus, async () => { {{ $t('all') }} {{ $t('statusACTIVE') }} {{ $t('statusINACTIVE') }} @@ -1200,7 +1347,7 @@ watch(currentStatus, async () => {
@@ -1208,64 +1355,68 @@ watch(currentStatus, async () => {
-
- + -
{ } " /> -
+
-->
@@ -1553,12 +1704,7 @@ watch(currentStatus, async () => { :index="selectProduct.findIndex((v) => v.id === i.id)" :isAddProduct="!!selectProduct.find((v) => v.id === i.id)" :isSelected="true" - :data="i" - :code="i.code" - :price="i.price" - :process="i.process" - :id="i.id" - typeProduct="product" + :data="{ ...i, type: 'product' }" :title="i.name" :status="i.status === 'INACTIVE' ? true : false" @menuViewDetail=" @@ -1759,7 +1905,8 @@ watch(currentStatus, async () => { v-if="currentServiceTab === 'workInformation'" dense @addProduct=" - (index) => { + async (index) => { + await fetchListOfProduct(currentIdType); currentWorkIndex = index; dialogTotalProduct = true; } @@ -1901,7 +2048,8 @@ watch(currentStatus, async () => { v-if="currentServiceTab === 'workInformation'" dense @addProduct=" - (index) => { + async (index) => { + await fetchListOfProduct(currentIdType); currentWorkIndex = index; dialogTotalProduct = true; }