From c46d2f0b9dd93c33110e898ab4ddbac4f7755cd6 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Wed, 18 Sep 2024 16:52:46 +0700 Subject: [PATCH] feat: add more function --- src/pages/05_quotation/MainPage.vue | 89 +++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/src/pages/05_quotation/MainPage.vue b/src/pages/05_quotation/MainPage.vue index 4786554d..9804a4cf 100644 --- a/src/pages/05_quotation/MainPage.vue +++ b/src/pages/05_quotation/MainPage.vue @@ -12,6 +12,8 @@ import { import QuotationForm from './QuotationForm.vue'; import TreeView from 'src/components/shared/TreeView.vue'; +import { AddButton } from 'src/components/button'; +import MainButton from 'src/components/button/MainButton.vue'; const dialog = ref(true); @@ -69,6 +71,14 @@ const productGroup = ref([]); const productList = ref>>({}); const serviceList = ref>>({}); +type Id = string; +const product = ref>({}); +const service = ref>({}); + +const selectedGroup = ref(null); +const selectedGroupSub = ref<'product' | 'service' | null>(null); +const selectedProductServiceId = ref(''); + onMounted(async () => { const ret = await productServiceStore.fetchListProductService({ page: 1, @@ -81,10 +91,12 @@ async function getAllProduct( groupId: string, opts?: { force?: false; page?: number; pageSize?: number }, ) { + selectedGroupSub.value = 'product'; if (!opts?.force && productList.value[groupId] !== undefined) return; const ret = await productServiceStore.fetchListProduct({ page: opts?.page ?? 1, pageSize: opts?.pageSize ?? 9999, + productGroupId: groupId, }); if (ret) productList.value[groupId] = ret.result; } @@ -93,16 +105,93 @@ async function getAllService( groupId: string, opts?: { force?: false; page?: number; pageSize?: number }, ) { + selectedGroupSub.value = 'service'; if (!opts?.force && serviceList.value[groupId] !== undefined) return; const ret = await productServiceStore.fetchListService({ page: opts?.page ?? 1, pageSize: opts?.pageSize ?? 9999, + productGroupId: groupId, }); if (ret) serviceList.value[groupId] = ret.result; } + +async function getProduct(id: string, force = false) { + selectedGroupSub.value = 'product'; + selectedProductServiceId.value = id; + if (!force && product.value[id] !== undefined) return; + const ret = await productServiceStore.fetchListProductById(id); + if (ret) product.value[id] = ret; +} + +async function getService(id: string, force = false) { + selectedGroupSub.value = 'service'; + selectedProductServiceId.value = id; + if (!force && service.value[id] !== undefined) return; + const ret = await productServiceStore.fetchListServiceById(id); + if (ret) service.value[id] = ret; +} + +function convertToTree() { + // TODO: convert product or service into selectable tree + // NOTE: this is meant to be used inside getService() and getProduct() before return and after return +}