From b977f86de96cd46c3a335f5cdc45cceb758907b9 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Wed, 16 Jul 2025 14:39:28 +0700 Subject: [PATCH] feat: institution attachment --- .../FormBasicInfoAgencies.vue | 91 +++++++++++++++++++ src/i18n/eng.ts | 1 + src/i18n/tha.ts | 1 + .../07_agencies-management/AgenciesDialog.vue | 8 ++ src/pages/07_agencies-management/MainPage.vue | 77 +++++++++++++++- src/stores/institution/index.ts | 3 + 6 files changed, 179 insertions(+), 2 deletions(-) diff --git a/src/components/07_agencies-management/FormBasicInfoAgencies.vue b/src/components/07_agencies-management/FormBasicInfoAgencies.vue index 1d80f5c3..50ce3320 100644 --- a/src/components/07_agencies-management/FormBasicInfoAgencies.vue +++ b/src/components/07_agencies-management/FormBasicInfoAgencies.vue @@ -1,6 +1,10 @@ + + + + + + +
+ + + +
+
+ {{ item.name }} +
+ +
+
+
+
+
diff --git a/src/i18n/eng.ts b/src/i18n/eng.ts index f9b505f9..39da457e 100644 --- a/src/i18n/eng.ts +++ b/src/i18n/eng.ts @@ -928,6 +928,7 @@ export default { contactName: 'Contact Person', contactTel: 'Contact Number', bankInfo: 'Bank Information', + attachment: 'Attachment', }, requestList: { diff --git a/src/i18n/tha.ts b/src/i18n/tha.ts index 80fb6f34..7fea5cac 100644 --- a/src/i18n/tha.ts +++ b/src/i18n/tha.ts @@ -925,6 +925,7 @@ export default { contactName: 'ชื่อผู้ติดต่อ', contactTel: 'เบอร์โทรผู้ติดต่อ', bankInfo: 'ข้อมูลธนาคาร', + attachment: 'เอกสารเพิ่มเติม', }, requestList: { diff --git a/src/pages/07_agencies-management/AgenciesDialog.vue b/src/pages/07_agencies-management/AgenciesDialog.vue index e1597b03..cda5b733 100644 --- a/src/pages/07_agencies-management/AgenciesDialog.vue +++ b/src/pages/07_agencies-management/AgenciesDialog.vue @@ -82,6 +82,7 @@ const emit = defineEmits<{ (e: 'addImage'): void; (e: 'removeImage'): void; (e: 'submitImage', name: string): void; + (e: 'deleteAttachment', name: string): void; }>(); const data = defineModel('data', { @@ -121,6 +122,9 @@ const formBankBook = defineModel('formBankBook', { }, ], }); +const attachment = defineModel('attachment'); +const attachmentList = + defineModel<{ name: string; url: string }[]>('attachmentList'); function viewImage() { imageState.imageDialog = true; @@ -348,6 +352,7 @@ watch( v-model:contact-name="data.contactName" v-model:email="data.contactEmail" v-model:contact-tel="data.contactTel" + v-model:attachment="attachment" /> ([]); +const attachmentList = ref<{ name: string; url: string }[]>([]); const statusFilter = ref<'all' | 'statusACTIVE' | 'statusINACTIVE'>('all'); const refAgenciesDialog = ref(); const formData = ref(structuredClone(blankFormData)); @@ -145,6 +147,8 @@ function resetForm() { pageState.addModal = false; pageState.viewDrawer = false; currAgenciesData.value = undefined; + attachment.value = []; + attachmentList.value = []; formData.value = structuredClone(blankFormData); } @@ -154,7 +158,7 @@ function undo() { pageState.isDrawerEdit = false; } -function assignFormData(data: Institution) { +async function assignFormData(data: Institution) { currAgenciesData.value = data; formData.value = { group: data.group, @@ -187,6 +191,8 @@ function assignFormData(data: Institution) { bankUrl: `${baseUrl}/institution/${data.id}/bank-qr/${v.id}?ts=${Date.now()}`, })), }; + + await fetchAttachment(); } async function submit(opt?: { selectedImage: string }) { @@ -228,18 +234,29 @@ async function submit(opt?: { selectedImage: string }) { ); if (ret) { + attachment.value.forEach(async (file) => { + await institutionStore.putAttachment({ + parentId: ret.id || '', + name: file.name, + file: file, + }); + }); pageState.isDrawerEdit = false; currAgenciesData.value = ret; formData.value.selectedImage = ret.selectedImage; await fetchData($q.screen.xs); + attachment.value = []; if (refAgenciesDialog.value && opt?.selectedImage) { refAgenciesDialog.value.clearImageState(); } + setTimeout(async () => { + await fetchAttachment(); + }, 300); return; } } else { - await institutionStore.createInstitution( + const res = await institutionStore.createInstitution( { ...payload, code: formData.value.group || '', @@ -247,6 +264,16 @@ async function submit(opt?: { selectedImage: string }) { imageListOnCreate.value, ); + if (!res) return; + + attachment.value.forEach(async (file) => { + await institutionStore.putAttachment({ + parentId: res.id || '', + name: file.name, + file: file, + }); + }); + await fetchData($q.screen.xs); pageState.addModal = false; return; @@ -346,6 +373,49 @@ async function changeStatus(id?: string) { } } +async function deleteAttachment(attachmentName: string) { + dialog({ + color: 'negative', + icon: 'mdi-trash-can-outline', + title: t('dialog.title.confirmDelete', { + msg: t('personnel.form.attachment'), + }), + actionText: t('general.delete'), + persistent: true, + message: t('dialog.message.confirmDelete'), + action: async () => { + if (!currAgenciesData.value?.id) return; + institutionStore.delAttachment({ + parentId: currAgenciesData.value?.id, + name: attachmentName, + }); + setTimeout(async () => { + await fetchAttachment(); + }, 300); + }, + cancel: () => {}, + }); +} + +async function fetchAttachment() { + const resAttachment = await institutionStore.listAttachment({ + parentId: currAgenciesData.value.id, + }); + + if (!resAttachment) return; + + attachmentList.value = await Promise.all( + resAttachment.map(async (f) => ({ + name: f, + url: await institutionStore.getAttachment({ + parentId: currAgenciesData.value.id, + name: f, + download: false, + }), + })), + ); +} + onMounted(async () => { navigatorStore.current.title = 'agencies.title'; navigatorStore.current.path = [{ text: 'agencies.caption', i18n: true }]; @@ -976,6 +1046,7 @@ watch( } " @change-status="triggerChangeStatus" + @delete-attachment="deleteAttachment" :readonly="!pageState.isDrawerEdit" :isEdit="pageState.isDrawerEdit" :hide-action="!canAccess('agencies', 'edit')" @@ -985,6 +1056,8 @@ watch( v-model:form-bank-book="formData.bank" v-model:image-list-on-create="imageListOnCreate" v-model:deletes-status-qr-code-bank-imag="deletesStatusQrCodeBankImag" + v-model:attachment="attachment" + :attachment-list="attachmentList" />