fix: fixed autocomplete when entering an iban
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jon Elias 2025-04-10 12:37:14 +02:00
parent c633a3e283
commit bc6d11846f
3 changed files with 68 additions and 32 deletions

View File

@ -0,0 +1,44 @@
<script setup>
import { useI18n } from 'vue-i18n';
import axios from 'axios';
import VnInput from 'src/components/common/VnInput.vue';
const { t } = useI18n();
const model = defineModel({ type: [Number, String] });
const emit = defineEmits(['updateBic']);
const getIbanCountry = (bank) => {
return bank.substr(0, 2);
};
const autofillBic = async (iban) => {
if (!iban) return;
const bankEntityId = parseInt(iban.substr(4, 4));
const ibanCountry = getIbanCountry(iban);
if (ibanCountry != 'ES') return;
const filter = { where: { id: bankEntityId.value } };
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get(`BankEntities`, { params });
emit('updateBic', data[0].id);
};
</script>
<template>
<VnInput
:label="t('IBAN')"
clearable
v-model="model"
@update:model-value="autofillBic($event)"
>
<template #append>
<QIcon name="info" class="cursor-info">
<QTooltip>{{ t('components.iban_tooltip') }}</QTooltip>
</QIcon>
</template>
</VnInput>
</template>

View File

@ -9,21 +9,27 @@ import VnInput from 'src/components/common/VnInput.vue';
import VnSelect from 'src/components/common/VnSelect.vue'; import VnSelect from 'src/components/common/VnSelect.vue';
import VnSelectDialog from 'src/components/common/VnSelectDialog.vue'; import VnSelectDialog from 'src/components/common/VnSelectDialog.vue';
import CreateBankEntityForm from 'src/components/CreateBankEntityForm.vue'; import CreateBankEntityForm from 'src/components/CreateBankEntityForm.vue';
import VnInputBic from 'src/components/common/VnInputBic.vue';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const bankEntitiesRef = ref(null); const bankEntitiesRef = ref(null);
const bankEntity = ref();
const filter = { const filter = {
fields: ['id', 'bic', 'name'], fields: ['id', 'bic', 'name'],
order: 'bic ASC' order: 'bic ASC',
}; };
const getBankEntities = (data, formData) => { const getBankEntities = (data, formData) => {
bankEntitiesRef.value.fetch(); bankEntitiesRef.value.fetch();
formData.bankEntityFk = Number(data.id); formData.bankEntityFk = Number(data.id);
}; };
const autofillSwiftBic = (bankEntityFk) => {
bankEntity.value = bankEntityFk;
};
</script> </script>
<template> <template>
@ -43,13 +49,11 @@ const getBankEntities = (data, formData) => {
</VnRow> </VnRow>
<VnRow> <VnRow>
<VnInput :label="t('IBAN')" clearable v-model="data.iban"> <VnInputBic
<template #append> :label="t('IBAN')"
<QIcon name="info" class="cursor-info"> v-model="data.iban"
<QTooltip>{{ t('components.iban_tooltip') }}</QTooltip> @update-bic="autofillSwiftBic($event)"
</QIcon> />
</template>
</VnInput>
<VnSelectDialog <VnSelectDialog
:label="t('Swift / BIC')" :label="t('Swift / BIC')"
ref="bankEntitiesRef" ref="bankEntitiesRef"
@ -61,7 +65,7 @@ const getBankEntities = (data, formData) => {
hide-selected hide-selected
option-label="name" option-label="name"
option-value="id" option-value="id"
v-model="data.bankEntityFk" v-model="bankEntity"
> >
<template #form> <template #form>
<CreateBankEntityForm <CreateBankEntityForm

View File

@ -18,6 +18,8 @@ import { useState } from 'src/composables/useState';
import axios from 'axios'; import axios from 'axios';
import VnSelectWorker from 'src/components/common/VnSelectWorker.vue'; import VnSelectWorker from 'src/components/common/VnSelectWorker.vue';
import VnSection from 'src/components/common/VnSection.vue'; import VnSection from 'src/components/common/VnSection.vue';
import VnInputBic from 'src/components/common/VnInputBic.vue';
const { t } = useI18n(); const { t } = useI18n();
const tableRef = ref(); const tableRef = ref();
const { viewSummary } = useSummaryDialog(); const { viewSummary } = useSummaryDialog();
@ -29,6 +31,7 @@ const postcodesOptions = ref([]);
const user = useState().getUser(); const user = useState().getUser();
const defaultPayMethod = ref(); const defaultPayMethod = ref();
const bankEntitiesRef = ref(); const bankEntitiesRef = ref();
const bankEntity = ref();
const dataKey = 'WorkerList'; const dataKey = 'WorkerList';
const columns = computed(() => [ const columns = computed(() => [
{ {
@ -162,15 +165,9 @@ function generateCodeUser(worker) {
if (!worker.companyFk) worker.companyFk = user.companyFk; if (!worker.companyFk) worker.companyFk = user.companyFk;
} }
async function autofillBic(worker) { const autofillSwiftBic = (bankEntityFk) => {
if (!worker || !worker.iban) return; bankEntity.value = bankEntityFk;
};
let bankEntityId = parseInt(worker.iban.substr(4, 4));
let filter = { where: { id: bankEntityId } };
const { data } = await axios.get(`BankEntities`, { params: { filter } });
worker.bankEntityFk = data?.[0]?.id ?? undefined;
}
</script> </script>
<template> <template>
<FetchData <FetchData
@ -331,25 +328,17 @@ async function autofillBic(worker) {
(val) => !val && delete data.payMethodFk (val) => !val && delete data.payMethodFk
" "
/> />
<VnInput <VnInputBic
:label="t('IBAN')"
v-model="data.iban" v-model="data.iban"
:label="t('worker.create.iban')"
:disable="data.isFreelance" :disable="data.isFreelance"
@update:model-value="autofillBic(data)" @update-bic="autofillSwiftBic($event)"
> />
<template #append>
<QIcon name="info" class="cursor-info">
<QTooltip>{{
t('components.iban_tooltip')
}}</QTooltip>
</QIcon>
</template>
</VnInput>
</VnRow> </VnRow>
<VnRow> <VnRow>
<VnSelectDialog <VnSelectDialog
:label="t('worker.create.bankEntity')" :label="t('worker.create.bankEntity')"
v-model="data.bankEntityFk" v-model="bankEntity"
:options="bankEntitiesOptions" :options="bankEntitiesOptions"
option-label="name" option-label="name"
option-value="id" option-value="id"
@ -362,7 +351,6 @@ async function autofillBic(worker) {
}, },
]" ]"
:disable="data.isFreelance" :disable="data.isFreelance"
@update:model-value="autofillBic(data)"
:filter-options="['bic', 'name']" :filter-options="['bic', 'name']"
> >
<template #form> <template #form>