0
0
Fork 0
salix-front-mindshore-fork2/src/components/CreateNewProvinceForm.vue

95 lines
2.7 KiB
Vue
Raw Normal View History

2023-12-20 15:23:42 +00:00
<script setup>
import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import FetchData from 'components/FetchData.vue';
import VnRow from 'components/ui/VnRow.vue';
2024-04-23 11:03:32 +00:00
import VnSelect from 'src/components/common/VnSelect.vue';
2023-12-20 15:23:42 +00:00
import VnInput from 'src/components/common/VnInput.vue';
import FormModelPopup from './FormModelPopup.vue';
2023-12-20 15:23:42 +00:00
const emit = defineEmits(['onDataSaved']);
const { t } = useI18n();
const provinceFormData = reactive({
name: null,
autonomyFk: null,
});
2024-09-30 22:24:34 +00:00
const $props = defineProps({
countryFk: {
type: Number,
default: null,
},
provinces: {
type: Array,
default: () => [],
},
});
2023-12-20 15:23:42 +00:00
const autonomiesOptions = ref([]);
2024-07-29 13:03:21 +00:00
const onDataSaved = (dataSaved, requestResponse) => {
requestResponse.autonomy = autonomiesOptions.value.find(
(autonomy) => autonomy.id == requestResponse.autonomyFk
);
2024-07-29 13:03:21 +00:00
emit('onDataSaved', dataSaved, requestResponse);
2023-12-20 15:23:42 +00:00
};
</script>
<template>
<FetchData
@on-fetch="(data) => (autonomiesOptions = data)"
auto-load
2024-09-30 22:24:34 +00:00
:filter="{
where: {
countryFk: $props.countryFk,
},
}"
url="Autonomies/location"
2023-12-20 15:23:42 +00:00
/>
<FormModelPopup
:title="t('New province')"
:subtitle="t('Please, ensure you put the correct data!')"
2023-12-20 15:23:42 +00:00
url-create="provinces"
model="province"
:form-initial-data="provinceFormData"
2024-07-29 13:03:21 +00:00
@on-data-saved="onDataSaved"
2023-12-20 15:23:42 +00:00
>
<template #form-inputs="{ data, validate }">
2024-07-26 07:27:38 +00:00
<VnRow>
<VnInput
:label="t('Name')"
v-model="data.name"
:rules="validate('province.name')"
/>
2024-04-26 07:47:44 +00:00
<VnSelect
:label="t('Autonomy')"
:options="autonomiesOptions"
hide-selected
option-label="name"
option-value="id"
v-model="data.autonomyFk"
:rules="validate('province.autonomyFk')"
>
<template #option="{ itemProps, opt }">
<QItem v-bind="itemProps">
<QItemSection>
<QItemLabel>{{ opt.name }}</QItemLabel>
<QItemLabel caption> {{ opt.country.name }} </QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
2023-12-20 15:23:42 +00:00
</VnRow>
</template>
</FormModelPopup>
2023-12-20 15:23:42 +00:00
</template>
<i18n>
es:
New province: Nueva provincia
2023-12-20 15:23:42 +00:00
Please, ensure you put the correct data!: ¡Por favor, asegúrese de poner los datos correctos!
Name: Nombre
Autonomy: Autonomía
</i18n>