From 42d380b13d3bc1eb7232b2b80af56d80c5bf6b6b Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:46:30 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E0=B8=95=E0=B9=88=E0=B8=AD=20=20api=20?= =?UTF-8?q?=20=E0=B8=82=E0=B8=AD=E0=B8=87=20=20tree=20=E0=B9=81=E0=B8=A5?= =?UTF-8?q?=E0=B8=B0=20=20card?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/01_branch-management/MainPage.vue | 147 +++++++++++--------- 1 file changed, 81 insertions(+), 66 deletions(-) diff --git a/src/pages/01_branch-management/MainPage.vue b/src/pages/01_branch-management/MainPage.vue index 0d1fe8df..e2f91bae 100644 --- a/src/pages/01_branch-management/MainPage.vue +++ b/src/pages/01_branch-management/MainPage.vue @@ -11,6 +11,7 @@ import StatCardComponent from 'components/StatCardComponent.vue'; import CardDetailsComponent from 'src/components/01_branch-management/CardDetailsComponent.vue'; import DeatailsBranchDrawerComponent from 'src/components/01_branch-management/DeatailsBranchDrawerComponent.vue'; import FormDialog from 'src/components/FormDialog.vue'; +import TableCardComponent from 'src/components/01_branch-management/TableCardComponent.vue'; import { BranchWithChildren, Branch } from 'src/stores/branch/types'; @@ -19,10 +20,12 @@ const { data: branchData } = storeToRefs(branchStore); const modal = ref(false); -const showCurrentBranch = ref(); +const showCurrentBranch = ref(); const shape = ref(false); const openBranchDrawer = ref(true); +const openCardDetails = ref(false); +const openTableCard = ref(true); const inputSelectBranch = ref('ทั้งหมด'); const inputFilter = ref('คอลัมน์'); @@ -43,14 +46,14 @@ const formData = ref({ tel: '', gender: '', email: '', - addressL: { + addressTitle: { address: '', province: '', district: '', subDistrict: '', zip: '', }, - addressEng: { + addressENTitle: { address: '', province: '', district: '', @@ -72,45 +75,6 @@ const inputEmailHeadOffice = ref(''); const expanded = ref([]); -const rows: { - name: string; - branchName: string; - address: string; - phonNumber: string; - Headquarters: string; - type: string; - status: string; -}[] = [ - { - name: 'HQ0001', - branchName: 'จ็อบเวิร์ทเกอร์เซอร์วิส', - address: '192', - phonNumber: '0639195701', - Headquarters: 'HQ0001', - type: 'สำนักงานใหญ่', - status: 'เปิดใช้งาน', - }, - { - name: 'HQ0002', - branchName: 'จ็อบเวิร์ทเกอร์เซอร์วิส 2', - address: '192', - phonNumber: '0639195701', - Headquarters: 'HQ0001', - type: 'สำนักงานใหญ่', - status: 'เปิดใช้งาน', - }, - - { - name: 'HQ0002', - branchName: 'จ็อบเวิร์ทเกอร์เซอร์วิส 2', - address: '192', - phonNumber: '0639195701', - Headquarters: 'HQ0001', - type: 'สำนักงานใหญ่', - status: 'เปิดใช้งาน', - }, -]; - const branchStat = ref< { amount: number; @@ -142,6 +106,19 @@ const branchStat = ref< const treeData = ref([]); +const subBranch = ref(false); +const rowsBranch = ref< + { + name: string; + branchName: string; + address: string; + telephoneNo: string; + code: string; + type: boolean; + status: string; + }[] +>([]); + function openDialog() { modal.value = true; } @@ -150,26 +127,56 @@ async function getTree() { const result = await branchStore.fetchList({ tree: true, }); - if (result) treeData.value = result.result; + if (result) { + treeData.value = result.result; + rowsBranch.value = treeData.value + .filter((v) => v.isHeadOffice) + .map((v) => ({ + name: v.id, + branchName: v.name, + address: v.address, + telephoneNo: v.telephoneNo, + code: v.code, + type: v.isHeadOffice, + status: v.status.toString(), + })); + + subBranch.value = false; + } } -async function fetchBranch(id: string) { - if (typeof branchStore.fetchById(id) === 'object') { - showCurrentBranch.value = await branchStore.fetchById(id); +async function fetchCard(id: string) { + const result = await branchStore.fetchById(id); + + if (result) { + showCurrentBranch.value = result; + openCardDetails.value = true; + openTableCard.value = false; + } +} +async function fetchSubBranch(id: string) { + const result = await branchStore.fetchById(id, { + includeSubBranch: true, + }); + + if (result) { + rowsBranch.value = result.branch.map((v) => ({ + name: v.id, + branchName: v.name, + address: v.address, + telephoneNo: v.telephoneNo, + code: v.code, + type: v.isHeadOffice, + status: v.status, + })); + subBranch.value = true; + openCardDetails.value = false; + openTableCard.value = true; } } onMounted(async () => { - await getTree(); - - if ( - typeof branchStore.fetchById('bfff119e-079d-4b56-9699-0466ade4b517') === - 'object' - ) { - showCurrentBranch.value = await branchStore.fetchById( - 'bfff119e-079d-4b56-9699-0466ade4b517', - ); - } + getTree(); });