forked from verdnatura/salix-front
fix: Update from-to when cmpaign changes
This commit is contained in:
parent
6ce57d3c40
commit
b21abf40d2
|
@ -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);
|
};
|
||||||
|
const handleDates = (campaign) => {
|
||||||
|
const from = new Date(campaign.dated);
|
||||||
|
from.setDate(from.getDate() - campaign.scopeDays);
|
||||||
campaignParams.value = {
|
campaignParams.value = {
|
||||||
code: upcomingOptions.value.code,
|
code: campaign.code,
|
||||||
from: from,
|
from: from,
|
||||||
to: upcomingOptions.value.dated,
|
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">
|
||||||
|
|
Loading…
Reference in New Issue