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,57 +1,113 @@
<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 () => {
unpaidClient.value = true; 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;
} 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
<VnRow class="row q-gutter-md q-mb-md"> icon="restart_alt"
<div class="col"> type="reset"
<QCheckbox :label="t('Unpaid client')" v-model="unpaidClient" /> />
</div> <QBtn
</VnRow> :disabled="isLoading"
:label="t('globals.save')"
:loading="isLoading"
@click="onSubmit"
color="primary"
icon="save"
/>
</QBtnGroup>
</Teleport>
<VnRow class="row q-gutter-md q-mb-md" v-if="unpaidClient"> <div class="full-width flex justify-center">
<div class="col"> <QCard class="card-width q-pa-lg">
<VnInputDate :label="t('Date')" v-model="data.dated" /> <QForm>
</div> <VnRow class="row q-gutter-md q-mb-md">
<div class="col"> <div class="col">
<VnInput <QCheckbox :label="t('Unpaid client')" v-model="unpaidClient" />
:label="t('Amount')" </div>
clearable </VnRow>
type="number"
v-model="data.amount" <VnRow class="row q-gutter-md q-mb-md" v-if="unpaidClient">
/> <div class="col">
</div> <VnInputDate :label="t('Date')" v-model="dated" />
</VnRow> </div>
</template> <div class="col">
</FormModel> <VnInput
:label="t('Amount')"
clearable
type="number"
v-model="amount"
/>
</div>
</VnRow>
</QForm>
</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>