feat: institution attachment
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 5s
Some checks failed
Spell Check / Spell Check with Typos (push) Failing after 5s
This commit is contained in:
parent
da52bfbcbd
commit
b977f86de9
6 changed files with 179 additions and 2 deletions
|
|
@ -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<InstitutionPayload>('data', {
|
||||
|
|
@ -121,6 +122,9 @@ const formBankBook = defineModel<BankBook[]>('formBankBook', {
|
|||
},
|
||||
],
|
||||
});
|
||||
const attachment = defineModel<File[]>('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"
|
||||
/>
|
||||
<AddressForm
|
||||
id="agencies-form-address-info"
|
||||
|
|
@ -550,6 +555,9 @@ watch(
|
|||
v-model:contact-name="data.contactName"
|
||||
v-model:email="data.contactEmail"
|
||||
v-model:contact-tel="data.contactTel"
|
||||
v-model:attachment="attachment"
|
||||
:attachment-list="attachmentList"
|
||||
@delete-attachment="(name) => $emit('deleteAttachment', name)"
|
||||
/>
|
||||
<AddressForm
|
||||
id="agencies-address-info"
|
||||
|
|
|
|||
|
|
@ -115,6 +115,8 @@ const blankFormData: InstitutionPayload = {
|
|||
],
|
||||
};
|
||||
|
||||
const attachment = ref<File[]>([]);
|
||||
const attachmentList = ref<{ name: string; url: string }[]>([]);
|
||||
const statusFilter = ref<'all' | 'statusACTIVE' | 'statusINACTIVE'>('all');
|
||||
const refAgenciesDialog = ref();
|
||||
const formData = ref<InstitutionPayload>(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"
|
||||
/>
|
||||
</template>
|
||||
<style scoped>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue