This commit is contained in:
William Buezas 2023-12-13 12:09:23 -03:00
parent 11839c7811
commit d4b9dcc0b9
5 changed files with 146 additions and 59 deletions

View File

@ -1,7 +1,14 @@
<script setup> <script setup>
import { reactive } from 'vue'; import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import VnSelectFilter from 'src/components/common/VnSelectFilter.vue';
import FetchData from 'components/FetchData.vue';
import FormModel from 'components/FormModel.vue';
import VnRow from 'components/ui/VnRow.vue';
const emit = defineEmits(['closeForm', 'onDataSaved']);
const { t } = useI18n(); const { t } = useI18n();
const formData = reactive({ const formData = reactive({
@ -10,23 +17,122 @@ const formData = reactive({
countryFk: null, countryFk: null,
id: null, id: null,
}); });
const countriesFilter = {
fields: ['id', 'country', 'code'],
};
const countriesOptions = ref([]);
const loading = ref(false);
const setCountriesOptions = (data) => {
countriesOptions.value = data;
};
const closeForm = () => {
emit('closeForm');
};
const onDataSaved = (data) => {
emit('onDataSaved', data);
closeForm();
};
</script> </script>
<template> <template>
<QCard class="q-pa-xl column"> <FetchData
<span>{{ t('title') }}</span> url="Countries"
<span>{{ t('subtitle') }}</span> @on-fetch="(data) => setCountriesOptions(data)"
<QInput :label="t('name')" v-model="formData.name" /> :filter="countriesFilter"
</QCard> auto-load
/>
<FormModel
:form-initial-data="formData"
:observe-form-changes="false"
:default-actions="false"
url-create="bankEntities"
model="bankEntity"
@on-data-saved="onDataSaved(data)"
>
<template #form="{ data, validate }">
<h1 class="title">{{ t('title') }}</h1>
<span class="q-mb-md">{{ t('subtitle') }}</span>
<VnRow class="row q-gutter-md q-mb-md">
<div class="col">
<QInput
:label="t('name')"
v-model="data.name"
:rules="validate('bankEntity.name')"
/>
</div>
<div class="col">
<QInput
:label="t('swift')"
v-model="data.bic"
:rules="validate('bankEntity.bic')"
/>
</div>
</VnRow>
<VnRow class="row q-gutter-md q-mb-md">
<div class="col">
<VnSelectFilter
:label="t('country')"
v-model="formData.countryFk"
:options="countriesOptions"
option-value="id"
option-label="country"
hide-selected
:rules="validate('bankEntity.countryFk')"
/>
</div>
<div class="col">
<QInput :label="t('id')" v-model="formData.id" />
</div>
</VnRow>
<div class="q-mt-lg row justify-end">
<QBtn
:label="t('globals.save')"
type="submit"
color="primary"
:disabled="loading"
:loading="loading"
/>
<QBtn
:label="t('globals.cancel')"
type="reset"
color="primary"
flat
class="q-ml-sm"
:disabled="loading"
:loading="loading"
v-close-popup
/>
</div>
</template>
</FormModel>
</template> </template>
<style lang="scss" scoped>
.title {
font-size: 17px;
font-weight: bold;
line-height: 20px;
}
</style>
<i18n> <i18n>
en: en:
name: Name *
title: New bank entity title: New bank entity
subtitle: Please, ensure you put the correct data! subtitle: Please, ensure you put the correct data!
name: Name *
swift: Swift *
country: Country
id: Entity code
es: es:
name: Nombre *
title: Nueva entidad bancaria title: Nueva entidad bancaria
subtitle: ¡Por favor, asegúrate de poner los datos correctos! subtitle: ¡Por favor, asegúrate de poner los datos correctos!
name: Nombre *
swift: Swift *
country: País
id: Código de la entidad
</i18n> </i18n>

View File

@ -57,7 +57,7 @@ const $props = defineProps({
}, },
}); });
const emit = defineEmits(['onFetch']); const emit = defineEmits(['onFetch', 'onDataSaved']);
defineExpose({ defineExpose({
save, save,
@ -114,7 +114,7 @@ async function fetch() {
} }
async function save() { async function save() {
if (!hasChanges.value) { if ($props.observeFormChanges && !hasChanges.value) {
notify('globals.noChanges', 'negative'); notify('globals.noChanges', 'negative');
return; return;
} }

View File

@ -27,7 +27,7 @@ const $props = defineProps({
}); });
const role = useRole(); const role = useRole();
const popup = ref(null); const showForm = ref(false);
const value = computed({ const value = computed({
get() { get() {
@ -42,31 +42,27 @@ const isAllowedToCreate = computed(() => {
return role.hasAny($props.rolesAllowedToCreate); return role.hasAny($props.rolesAllowedToCreate);
}); });
const openCreateForm = () => { const toggleForm = () => {
popup.value.show(); showForm.value = !showForm.value;
}; };
</script> </script>
<template> <template>
<VnSelectFilter <VnSelectFilter v-model="value" :options="options">
label="Label"
v-model="value"
:options="options"
option-value="value"
option-label="label"
hide-selected
>
<template v-if="isAllowedToCreate" #append> <template v-if="isAllowedToCreate" #append>
<QIcon <QIcon
@click.stop.prevent="openCreateForm()" @click.stop.prevent="toggleForm()"
name="add" name="add"
size="19px" size="19px"
class="add-icon" class="add-icon"
/> />
<QDialog ref="popup" cover transition-show="scale" transition-hide="scale"> <QDialog v-model="showForm" transition-show="scale" transition-hide="scale">
<slot name="form" /> <slot name="form" @close-form="toggleForm()" />
</QDialog> </QDialog>
</template> </template>
<template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
<slot :name="slotName" v-bind="slotData" :key="slotName" />
</template>
</VnSelectFilter> </VnSelectFilter>
</template> </template>

View File

@ -169,11 +169,3 @@ const onFetchWarehouses = (warehouses) => {
</FormModel> </FormModel>
</QPage> </QPage>
</template> </template>
<style lang="scss" scoped>
.card {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
grid-gap: 20px;
}
</style>

View File

@ -59,14 +59,14 @@ const updateFilterOptions = (data, optionKey) => {
filtersOptions[optionKey] = [...data]; filtersOptions[optionKey] = [...data];
}; };
const onFetchWorkerConfig = (workerConfig) => {
newWorkerForm.value.payMethodFk = workerConfig.payMethodFk;
};
onMounted(async () => { onMounted(async () => {
const userInfo = await useUserConfig().fetch(); const userInfo = await useUserConfig().fetch();
newWorkerForm.value = { companyFk: userInfo.companyFk }; newWorkerForm.value = { companyFk: userInfo.companyFk };
}); });
const onFetchWorkerConfig = (workerConfig) => {
newWorkerForm.value.payMethodFk = workerConfig.payMethodFk;
};
</script> </script>
<template> <template>
@ -108,6 +108,7 @@ const onFetchWorkerConfig = (workerConfig) => {
@on-fetch="(data) => updateFilterOptions(data, 'bankEntities')" @on-fetch="(data) => updateFilterOptions(data, 'bankEntities')"
auto-load auto-load
/> />
<QPage> <QPage>
<QToolbar class="bg-vn-dark"> <QToolbar class="bg-vn-dark">
<div id="st-data"></div> <div id="st-data"></div>
@ -115,7 +116,7 @@ const onFetchWorkerConfig = (workerConfig) => {
<div id="st-actions"></div> <div id="st-actions"></div>
</QToolbar> </QToolbar>
<FormModel <FormModel
url-create="Workers/new" url-create="Countries"
model="worker" model="worker"
:form-initial-data="newWorkerForm" :form-initial-data="newWorkerForm"
> >
@ -261,35 +262,27 @@ const onFetchWorkerConfig = (workerConfig) => {
<div class="col"> <div class="col">
<QInput v-model="data.iban" :label="t('worker.create.iban')" /> <QInput v-model="data.iban" :label="t('worker.create.iban')" />
</div> </div>
<!-- <div class="col">
<VnSelectFilter
:label="t('worker.create.bankEntity')"
v-model="data.bankEntityFk"
:options="filtersOptions.bankEntities"
option-value="id"
option-label="bic"
hide-selected
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel
>{{ scope.opt.bic }}
{{ scope.opt.name }}</QItemLabel
>
</QItemSection>
</QItem>
</template></VnSelectFilter
>
</div> -->
<VnSelectCreate <VnSelectCreate
:label="t('worker.create.bankEntity')" :label="t('worker.create.bankEntity')"
v-model="data.bankEntityFk" v-model="data.bankEntityFk"
:options="filtersOptions.bankEntities" :options="filtersOptions.bankEntities"
option-label="name"
option-value="id"
hide-selected
:roles-allowed-to-create="['salesAssistant', 'hr']" :roles-allowed-to-create="['salesAssistant', 'hr']"
> >
<template #form> <template #form>
<CreateBankEntityForm></CreateBankEntityForm> <CreateBankEntityForm />
</template>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection v-if="scope.opt">
<QItemLabel
>{{ scope.opt.bic }}
{{ scope.opt.name }}</QItemLabel
>
</QItemSection>
</QItem>
</template> </template>
</VnSelectCreate> </VnSelectCreate>
</VnRow> </VnRow>