From 8030e3cac171b0e31ed20ad915773ee76cba123b Mon Sep 17 00:00:00 2001 From: Net <93821485+somnetsak123@users.noreply.github.com> Date: Fri, 19 Apr 2024 14:09:17 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=A5?= =?UTF-8?q?=E0=B8=B9=E0=B8=81=20=E0=B9=83=E0=B8=99=20=20=E0=B8=A3=E0=B8=B2?= =?UTF-8?q?=E0=B8=A2=E0=B8=A5=E0=B8=B0=E0=B9=80=E0=B8=AD=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=94=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=84=E0=B8=94=E0=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/01_branch-management/MainPage.vue | 43 ++++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/pages/01_branch-management/MainPage.vue b/src/pages/01_branch-management/MainPage.vue index 0e8dc28a..5e3e7879 100644 --- a/src/pages/01_branch-management/MainPage.vue +++ b/src/pages/01_branch-management/MainPage.vue @@ -222,32 +222,45 @@ function clearData() { profileFile.value = undefined; } -function triggerView( +async function triggerView( id: string, typeBranch: 'headOffice' | 'subBranch', code?: string, ) { - fetchBranchById(id); + await fetchBranchById(id); if (id && code && typeBranch === 'headOffice') { + formTypeBranch.value = 'headOffice'; + codeHq.value = { + id: id, + code: code, + }; + } + if (typeBranch === 'subBranch' && id && code) { + formTypeBranch.value = 'subBranch'; codeHq.value = { id: id, code: code, }; } + const currentRecord = branchData.value.result.find((x) => x.id === id); + + if (!currentRecord) return; + + const currentRecordHead = branchData.value.result.find( + (x) => x.id === currentRecord.headOfficeId, + ); + + if (currentRecordHead) { + codeHq.value.code = currentRecordHead.code; + } + formTypeBranch.value = typeBranch; formType.value = 'view'; openDrawer(); } -function drawerEdit() { - formType.value = 'edit'; - prevFormData.value = { - ...formData.value, - }; -} - async function undo() { formType.value = 'view'; formData.value = prevFormData.value; @@ -271,6 +284,13 @@ function triggerCreate(type: string, id?: string, code?: string) { openDialog(); } +function drawerEdit() { + formType.value = 'edit'; + prevFormData.value = { + ...formData.value, + }; +} + async function triggerEdit(type: string, id: string, code?: string) { await fetchBranchById(id); @@ -329,6 +349,7 @@ function triggerDelete(id: string) { async function onSubmit() { if (formType.value === 'edit') { if (modalDrawer.value) { + const { status, ...payload } = formData.value; dialog({ color: 'primary', icon: 'mdi-pencil-outline', @@ -340,7 +361,9 @@ async function onSubmit() { const { status, ...payload } = formData.value; await branchStore.editById( codeHq.value.id, - payload, + { + ...payload, + }, profileFile.value, profileFileImg.value, );