0
0
Fork 0

fix: Update from-to when cmpaign changes

This commit is contained in:
Javier Segarra 2024-05-06 15:15:35 +02:00
parent 6ce57d3c40
commit b21abf40d2
1 changed files with 18 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import axios from 'axios';
import useNotify from 'src/composables/useNotify'; import useNotify from 'src/composables/useNotify';
import { useValidator } from 'src/composables/useValidator'; import { useValidator } from 'src/composables/useValidator';
import VnRow from 'components/ui/VnRow.vue'; import VnRow from 'components/ui/VnRow.vue';
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputDate from 'components/common/VnInputDate.vue';
import FetchData from 'src/components/FetchData.vue'; import FetchData from 'src/components/FetchData.vue';
import { watch } from 'vue'; import { watch } from 'vue';
@ -28,18 +29,25 @@ const { notify } = useNotify();
const { t } = useI18n(); const { t } = useI18n();
const validationsStore = useValidator(); const validationsStore = useValidator();
const campaignParams = ref(null); const campaignParams = ref(null);
const campaignsOptions = ref(null);
const moreFields = ref([]); const moreFields = ref([]);
const popupProxyRef = ref(null); const popupProxyRef = ref(null);
const upcomingOptions = ref(null); const upcomingOptions = ref(null);
const campaignChange = ({ name }) => {
watch(selectedRows, () => { const campaign = campaignsOptions.value.find((c) => c.code === name);
const from = new Date(upcomingOptions.value.dated); handleDates(campaign);
from.setDate(from.getDate() - upcomingOptions.value.scopeDays);
campaignParams.value = {
code: upcomingOptions.value.code,
from: from,
to: upcomingOptions.value.dated,
}; };
const handleDates = (campaign) => {
const from = new Date(campaign.dated);
from.setDate(from.getDate() - campaign.scopeDays);
campaignParams.value = {
code: campaign.code,
from: from,
to: campaign.dated,
};
};
watch(selectedRows, () => {
handleDates(upcomingOptions.value);
}); });
const onSubmit = async () => { const onSubmit = async () => {
try { try {
@ -90,14 +98,15 @@ onMounted(async () => {
<QBtn color="primary" icon="show_chart" :disable="!selectedRows"> <QBtn color="primary" icon="show_chart" :disable="!selectedRows">
<QPopupProxy ref="popupProxyRef"> <QPopupProxy ref="popupProxyRef">
<QCard class="column q-pa-md"> <QCard class="column q-pa-md">
{{ campaignParams }}
<span class="text-body1 q-mb-sm">{{ t('Campaign consumption') }}</span> <span class="text-body1 q-mb-sm">{{ t('Campaign consumption') }}</span>
<VnRow class="row q-gutter-md q-mb-md"> <VnRow class="row q-gutter-md q-mb-md">
<QSelect <VnSelectFilter
:options="moreFields" :options="moreFields"
option-value="code"
option-label="label"
v-model="campaignParams.code" v-model="campaignParams.code"
:label="t('Campaign')" :label="t('Campaign')"
option-label="label" @update:model-value="campaignChange"
/> />
</VnRow> </VnRow>
<VnRow class="row q-gutter-md q-mb-md"> <VnRow class="row q-gutter-md q-mb-md">