feat(SupplierAccount): add autoBic when change bankEntity

This commit is contained in:
Alex Moreno 2024-11-29 09:38:58 +01:00
parent 4f8bf00786
commit d364e30cf0
3 changed files with 50 additions and 8 deletions

View File

@ -176,8 +176,8 @@ async function saveChanges(data) {
const changes = data || getChanges(); const changes = data || getChanges();
try { try {
await axios.post($props.saveUrl || $props.url + '/crud', changes); await axios.post($props.saveUrl || $props.url + '/crud', changes);
} catch (e) { } finally {
return (isLoading.value = false); isLoading.value = false;
} }
originalData.value = JSON.parse(JSON.stringify(formData.value)); originalData.value = JSON.parse(JSON.stringify(formData.value));
if (changes.creates?.length) await vnPaginateRef.value.fetch(); if (changes.creates?.length) await vnPaginateRef.value.fetch();

View File

@ -284,9 +284,9 @@ async function onScroll({ to, direction, from, index }) {
:loading="isLoading" :loading="isLoading"
@virtual-scroll="onScroll" @virtual-scroll="onScroll"
> >
<template v-if="isClearable" #append> <template #append>
<QIcon <QIcon
v-show="value" v-show="isClearable && value"
name="close" name="close"
@click.stop=" @click.stop="
() => { () => {
@ -299,7 +299,22 @@ async function onScroll({ to, direction, from, index }) {
/> />
</template> </template>
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName"> <template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
<slot :name="slotName" v-bind="slotData ?? {}" :key="slotName" /> <div v-if="slotName == 'append'">
<QIcon
v-show="isClearable && value"
name="close"
@click.stop="
() => {
value = null;
emit('remove');
}
"
class="cursor-pointer"
size="xs"
/>
<slot name="append" v-if="$slots.append" v-bind="slotData ?? {}" />
</div>
<slot v-else :name="slotName" v-bind="slotData ?? {}" :key="slotName" />
</template> </template>
</QSelect> </QSelect>
</template> </template>

View File

@ -24,13 +24,14 @@ const supplier = ref(null);
const supplierAccountRef = ref(null); const supplierAccountRef = ref(null);
const wireTransferFk = ref(null); const wireTransferFk = ref(null);
const bankEntitiesOptions = ref([]); const bankEntitiesOptions = ref([]);
const filteredBankEntitiesOptions = ref([]);
const onBankEntityCreated = async (dataSaved, rowData) => { const onBankEntityCreated = async (dataSaved, rowData) => {
await bankEntitiesRef.value.fetch(); await bankEntitiesRef.value.fetch();
rowData.bankEntityFk = dataSaved.id; rowData.bankEntityFk = dataSaved.id;
}; };
const onChangesSaved = () => { const onChangesSaved = async () => {
if (supplier.value.payMethodFk !== wireTransferFk.value) if (supplier.value.payMethodFk !== wireTransferFk.value)
quasar quasar
.dialog({ .dialog({
@ -55,12 +56,35 @@ const setWireTransfer = async () => {
await axios.patch(`Suppliers/${route.params.id}`, params); await axios.patch(`Suppliers/${route.params.id}`, params);
notify('globals.dataSaved', 'positive'); notify('globals.dataSaved', 'positive');
}; };
function findBankFk(value, row) {
row.bankEntityFk = null;
if (!value) return;
const bankEntityFk = bankEntitiesOptions.value.find((b) => b.id == value.slice(4, 8));
if (bankEntityFk) row.bankEntityFk = bankEntityFk.id;
}
function bankEntityFilter(val, update) {
update(() => {
const needle = val.toLowerCase();
filteredBankEntitiesOptions.value = bankEntitiesOptions.value.filter(
(bank) =>
bank.bic.toLowerCase().startsWith(needle) ||
bank.name.toLowerCase().includes(needle)
);
});
}
</script> </script>
<template> <template>
<FetchData <FetchData
ref="bankEntitiesRef" ref="bankEntitiesRef"
url="BankEntities" url="BankEntities"
@on-fetch="(data) => (bankEntitiesOptions = data)" @on-fetch="
(data) => {
(bankEntitiesOptions = data), (filteredBankEntitiesOptions = data);
}
"
auto-load auto-load
/> />
<FetchData <FetchData
@ -98,6 +122,7 @@ const setWireTransfer = async () => {
<VnInput <VnInput
:label="t('supplier.accounts.iban')" :label="t('supplier.accounts.iban')"
v-model="row.iban" v-model="row.iban"
@update:model-value="(value) => findBankFk(value, row)"
:required="true" :required="true"
> >
<template #append> <template #append>
@ -109,7 +134,9 @@ const setWireTransfer = async () => {
<VnSelectDialog <VnSelectDialog
:label="t('worker.create.bankEntity')" :label="t('worker.create.bankEntity')"
v-model="row.bankEntityFk" v-model="row.bankEntityFk"
:options="bankEntitiesOptions" :options="filteredBankEntitiesOptions"
:default-filter="false"
@filter="(val, update) => bankEntityFilter(val, update)"
option-label="bic" option-label="bic"
option-value="id" option-value="id"
hide-selected hide-selected