From 7dc01a301df111c8543f217a0da144f46e91e387 Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Mon, 15 Jul 2024 14:12:53 +0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=E0=B9=81=E0=B8=AA=E0=B8=94?= =?UTF-8?q?=E0=B8=87=20=20tree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/04_product-service/MainPage.vue | 478 +++++++++++++++------- 1 file changed, 328 insertions(+), 150 deletions(-) diff --git a/src/pages/04_product-service/MainPage.vue b/src/pages/04_product-service/MainPage.vue index 5a1f00f9..c2ae6b57 100644 --- a/src/pages/04_product-service/MainPage.vue +++ b/src/pages/04_product-service/MainPage.vue @@ -55,6 +55,7 @@ import { Attributes, ServiceAndProduct, } from 'src/stores/product-service/types'; +import { computed } from 'vue'; const flowStore = useFlowStore(); const utilsStore = useUtilsStore(); @@ -94,7 +95,8 @@ const { fetchListProductAndService, } = productServiceStore; -const { workNameItems } = storeToRefs(productServiceStore); +const { workNameItems, recordTreeProductType } = + storeToRefs(productServiceStore); const stat = ref< { @@ -138,6 +140,30 @@ const stat = ref< const { t } = useI18n(); const baseUrl = ref(import.meta.env.VITE_API_BASE_URL); +const expandedTree = ref([]); +const editByTree = ref<'group' | 'type' | undefined>(); +const treeProductTypeAndGroup = computed(() => { + const tempValue = + productGroup.value?.map((item) => { + return { + ...item, + type: 'group', + children: + item.id === currentId.value + ? recordTreeProductType.value[currentId.value]?.map((item) => ({ + ...item, + type: 'type', + })) ?? [] + : recordTreeProductType.value[item.id]?.map((item) => ({ + ...item, + type: 'type', + })) ?? [], + }; + }) ?? []; + + return tempValue; +}); + const inputSearch = ref(''); const inputSearchProductAndService = ref(''); @@ -747,21 +773,42 @@ async function deleteProductById(productId?: string) { persistent: true, message: t('deleteConfirmMessage'), action: async () => { - if (productMode.value === 'type') { - // Product Type - await deleteProductServiceType(productId ?? currentIdType.value); - await fetchListType(); - } - if (productMode.value === 'group') { - // Product Group - const res = await deleteProductService(productId ?? currentId.value); - if (res) { + if (editByTree !== undefined) { + if (editByTree.value === 'type') { + // Product Type + await deleteProductServiceType(productId ?? currentIdType.value); + await fetchListType(); } - await fetchListGroups(); + if (editByTree.value === 'group') { + // Product Group + const res = await deleteProductService(productId ?? currentId.value); + if (res) { + } + await fetchListGroups(); + } + + flowStore.rotate(); + calculateStats(); + editByTree.value = undefined; + drawerInfo.value = false; + } else { + if (productMode.value === 'type') { + // Product Type + await deleteProductServiceType(productId ?? currentIdType.value); + await fetchListType(); + } + if (productMode.value === 'group') { + // Product Group + const res = await deleteProductService(productId ?? currentId.value); + if (res) { + } + await fetchListGroups(); + } + + flowStore.rotate(); + calculateStats(); + drawerInfo.value = false; } - flowStore.rotate(); - calculateStats(); - drawerInfo.value = false; }, cancel: () => {}, }); @@ -1163,6 +1210,10 @@ onMounted(async () => { calculateStats(); await fetchListGroups(); + + console.log(treeProductTypeAndGroup.value); + + console.log('ddd'); flowStore.rotate(); }); @@ -1341,153 +1392,248 @@ watch(inputSearchProductAndService, async () => {
-
- + if (node.type === 'group') { + toggleStatusGroup( + node.id, + node.status, + ); + } + } + " + :model-value="node.status !== 'INACTIVE'" + /> +
+ + + + + +
+ + +
+
{{ node.code }}
+
+ + + @@ -2978,14 +3124,46 @@ watch(inputSearchProductAndService, async () => { ref="formDialogRef" v-model:drawerOpen="drawerInfo" :title=" - $t(productMode === 'group' ? 'productGroup' : 'productType', { - name: formDataGroup.code, - }) + $t( + editByTree !== undefined + ? editByTree === 'group' + ? 'productGroup' + : editByTree === 'type' + ? 'productType' + : undefined + : productMode === 'group' + ? 'productGroup' + : productMode === 'type' + ? 'productType' + : undefined, + { + name: formDataGroup.code, + }, + ) " :undo="() => undoProductGroup()" :isEdit="isEdit" :editData="() => (isEdit = true)" - :submit="() => (productMode === 'type' ? submitType() : submitGroup())" + :submit=" + () => { + if (editByTree !== undefined) { + if (editByTree === 'group') { + submitGroup(); + } + if (editByTree === 'type') { + submitType(); + } + editByTree = undefined; + } else { + if (productMode === 'group') { + submitGroup(); + } + if (productMode === 'type') { + submitType(); + } + } + } + " :delete-data="() => deleteProductById()" :close="() => (drawerInfo = false)" >