salix-front/src/components/CreateBankEntityForm.vue

117 lines
3.2 KiB
Vue
Raw Normal View History

2023-12-12 14:58:44 +00:00
<script setup>
import { reactive, ref, onMounted, nextTick } from 'vue';
2023-12-12 14:58:44 +00:00
import { useI18n } from 'vue-i18n';
import VnInput from 'src/components/common/VnInput.vue';
2023-12-12 14:58:44 +00:00
2024-04-23 11:03:32 +00:00
import VnSelect from 'src/components/common/VnSelect.vue';
2023-12-13 15:09:23 +00:00
import FetchData from 'components/FetchData.vue';
import VnRow from 'components/ui/VnRow.vue';
import FormModelPopup from './FormModelPopup.vue';
2023-12-13 15:09:23 +00:00
2024-01-08 14:32:42 +00:00
const props = defineProps({
showEntityField: {
type: Boolean,
default: true,
},
});
const emit = defineEmits(['onDataSaved']);
2023-12-12 14:58:44 +00:00
const { t } = useI18n();
const bicInputRef = ref(null);
const bankEntityFormData = reactive({
2023-12-12 14:58:44 +00:00
name: null,
bic: null,
countryFk: null,
id: null,
});
2023-12-13 15:09:23 +00:00
const countriesFilter = {
fields: ['id', 'country', 'code'],
};
const countriesOptions = ref([]);
2024-03-04 12:47:47 +00:00
const onDataSaved = (formData, requestResponse) => {
emit('onDataSaved', formData, requestResponse);
};
onMounted(async () => {
await nextTick();
bicInputRef.value.focus();
});
2023-12-12 14:58:44 +00:00
</script>
<template>
2023-12-13 15:09:23 +00:00
<FetchData
url="Countries"
:filter="countriesFilter"
auto-load
2024-01-02 11:47:38 +00:00
@on-fetch="(data) => (countriesOptions = data)"
2023-12-13 15:09:23 +00:00
/>
<FormModelPopup
2023-12-13 15:09:23 +00:00
url-create="bankEntities"
model="bankEntity"
:title="t('title')"
:subtitle="t('subtitle')"
:form-initial-data="bankEntityFormData"
2024-03-04 12:47:47 +00:00
@on-data-saved="onDataSaved"
2023-12-13 15:09:23 +00:00
>
<template #form-inputs="{ data, validate }">
2023-12-13 15:09:23 +00:00
<VnRow class="row q-gutter-md q-mb-md">
<VnInput
:label="t('name')"
v-model="data.name"
:required="true"
:rules="validate('bankEntity.name')"
/>
<VnInput
ref="bicInputRef"
:label="t('swift')"
v-model="data.bic"
:required="true"
:rules="validate('bankEntity.bic')"
/>
2023-12-13 15:09:23 +00:00
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">
<div class="col">
2024-04-23 11:03:32 +00:00
<VnSelect
2023-12-13 15:09:23 +00:00
:label="t('country')"
v-model="data.countryFk"
2023-12-13 15:09:23 +00:00
:options="countriesOptions"
option-value="id"
option-label="country"
hide-selected
:required="true"
2023-12-13 15:09:23 +00:00
:rules="validate('bankEntity.countryFk')"
/>
</div>
2024-01-08 14:32:42 +00:00
<div v-if="showEntityField" class="col">
<VnInput
:label="t('id')"
v-model="data.id"
:required="true"
:rules="validate('city.name')"
/>
2023-12-13 15:09:23 +00:00
</div>
</VnRow>
</template>
</FormModelPopup>
2023-12-12 14:58:44 +00:00
</template>
<i18n>
en:
2023-12-12 17:00:56 +00:00
title: New bank entity
subtitle: Please, ensure you put the correct data!
name: Name
swift: Swift
2023-12-13 15:09:23 +00:00
country: Country
id: Entity code
2023-12-12 14:58:44 +00:00
es:
2023-12-12 17:00:56 +00:00
title: Nueva entidad bancaria
subtitle: ¡Por favor, asegúrate de poner los datos correctos!
name: Nombre
swift: Swift
2023-12-13 15:09:23 +00:00
country: País
id: Código de la entidad
2023-12-12 14:58:44 +00:00
</i18n>