0
0
Fork 0

Solucion a comentarios 20

This commit is contained in:
carlosfonseca 2024-02-22 18:01:38 -05:00
parent 2c70a73b8e
commit 90ee50eab5
2 changed files with 99 additions and 37 deletions

View File

@ -1,36 +1,91 @@
<script setup> <script setup>
import { reactive, ref } from 'vue'; import { onBeforeMount, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import FormModel from 'components/FormModel.vue'; import axios from 'axios';
import useNotify from 'src/composables/useNotify';
import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputDate from 'components/common/VnInputDate.vue';
import VnInput from 'src/components/common/VnInput.vue'; import VnInput from 'src/components/common/VnInput.vue';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const { notify } = useNotify();
const unpaidClient = ref(false); const unpaidClient = ref(false);
const initialData = reactive({ const isLoading = ref(false);
const amount = ref(null);
const dated = ref(null);
const initialData = ref({
dated: '2001-01-01T11:00:00.000Z', dated: '2001-01-01T11:00:00.000Z',
clientFk: 1,
}); });
const onFetch = () => { onBeforeMount(async () => {
try {
const { data } = await axios.get(`ClientUnpaids/${route.params.id}`);
amount.value = data.amount;
dated.value = data.dated;
initialData.value = data;
} catch (error) {
setInitialData();
}
});
const setInitialData = () => {
amount.value = initialData.value.amount;
dated.value = initialData.value.dated;
};
const onSubmit = async () => {
isLoading.value = true;
const payload = {
amount: amount.value,
clientFk: route.params.id,
dated: dated.value,
};
try {
await axios.patch('ClientUnpaids', payload);
notify('globals.dataSaved', 'positive');
unpaidClient.value = true; unpaidClient.value = true;
} catch (error) {
notify('errors.create', 'negative');
} finally {
isLoading.value = false;
}
}; };
</script> </script>
<template> <template>
<FormModel <Teleport to="#st-actions">
:form-initial-data="initialData" <QBtnGroup push class="q-gutter-x-sm">
:observe-form-changes="true" <QBtn
:url="`ClientUnpaids/${route.params.id}`" :disabled="isLoading"
@on-fetch="onFetch" :label="t('globals.reset')"
url-create="ClientUnpaids" :loading="isLoading"
auto-load @click="setInitialData"
> color="primary"
<template #form="{ data }"> flat
icon="restart_alt"
type="reset"
/>
<QBtn
:disabled="isLoading"
:label="t('globals.save')"
:loading="isLoading"
@click="onSubmit"
color="primary"
icon="save"
/>
</QBtnGroup>
</Teleport>
<div class="full-width flex justify-center">
<QCard class="card-width q-pa-lg">
<QForm>
<VnRow class="row q-gutter-md q-mb-md"> <VnRow class="row q-gutter-md q-mb-md">
<div class="col"> <div class="col">
<QCheckbox :label="t('Unpaid client')" v-model="unpaidClient" /> <QCheckbox :label="t('Unpaid client')" v-model="unpaidClient" />
@ -39,19 +94,20 @@ const onFetch = () => {
<VnRow class="row q-gutter-md q-mb-md" v-if="unpaidClient"> <VnRow class="row q-gutter-md q-mb-md" v-if="unpaidClient">
<div class="col"> <div class="col">
<VnInputDate :label="t('Date')" v-model="data.dated" /> <VnInputDate :label="t('Date')" v-model="dated" />
</div> </div>
<div class="col"> <div class="col">
<VnInput <VnInput
:label="t('Amount')" :label="t('Amount')"
clearable clearable
type="number" type="number"
v-model="data.amount" v-model="amount"
/> />
</div> </div>
</VnRow> </VnRow>
</template> </QForm>
</FormModel> </QCard>
</div>
</template> </template>
<i18n> <i18n>

View File

@ -15,8 +15,8 @@ const $props = defineProps({
</script> </script>
<template> <template>
<QDialog ref="dialogRef"> <QDialog ref="dialogRef" full-width>
<QCard class="q-pa-lg"> <QCard class="dialog-width q-pa-lg">
<QCardSection> <QCardSection>
<span ref="closeButton" class="row justify-end close-icon" v-close-popup> <span ref="closeButton" class="row justify-end close-icon" v-close-popup>
<QIcon name="close" size="sm" /> <QIcon name="close" size="sm" />
@ -26,3 +26,9 @@ const $props = defineProps({
</QCard> </QCard>
</QDialog> </QDialog>
</template> </template>
<style lang="scss" scoped>
.dialog-width {
max-width: 900px !important;
}
</style>