diff --git a/src/pages/Zone/Card/ZoneEventExclusionForm.vue b/src/pages/Zone/Card/ZoneEventExclusionForm.vue index f75745c7a..1573614a6 100644 --- a/src/pages/Zone/Card/ZoneEventExclusionForm.vue +++ b/src/pages/Zone/Card/ZoneEventExclusionForm.vue @@ -9,7 +9,6 @@ import ZoneLocationsTree from './ZoneLocationsTree.vue'; import VnInputDate from 'src/components/common/VnInputDate.vue'; import { useArrayData } from 'src/composables/useArrayData'; -import { useWeekdayStore } from 'src/stores/useWeekdayStore'; import { useVnConfirm } from 'composables/useVnConfirm'; import axios from 'axios'; @@ -27,9 +26,13 @@ const props = defineProps({ type: Boolean, default: true, }, - isExclusion: { - type: Boolean, - default: true, + eventType: { + type: String, + default: '', + }, + geoIds: { + type: Array, + default: () => [], }, }); @@ -37,11 +40,11 @@ const emit = defineEmits(['onSubmit', 'closeForm']); const route = useRoute(); const { t } = useI18n(); -const weekdayStore = useWeekdayStore(); const { openConfirmationModal } = useVnConfirm(); const isNew = computed(() => props.isNewMode); const dated = ref(null); +const tickedNodes = ref(); const _excludeType = ref('all'); const excludeType = computed({ @@ -55,7 +58,21 @@ const arrayData = useArrayData('ZoneEvents'); const exclusionGeoCreate = async () => { try { - console.log('exclusionGeoCreate'); + if (isNew.value) { + const params = { + zoneFk: parseInt(route.params.id), + date: dated.value, + geoIds: tickedNodes.value, + }; + await axios.post('Zones/exclusionGeo', params); + } else { + const params = { + zoneExclusionFk: props.event?.id, + geoIds: tickedNodes.value, + }; + await axios.post('Zones/updateExclusionGeo', params); + } + await refetchEvents(); } catch (err) { console.error('Error creating exclusion geo: ', err); } @@ -86,7 +103,9 @@ const onSubmit = async () => { const deleteEvent = async () => { try { if (!props.event) return; - await axios.delete(`Zones/${route.params.id}/exclusions/${props.event?.id}`); + await axios.delete( + `Zones/${route.params.id}/exclusions/${props.event?.zoneExclusionFk}` + ); await refetchEvents(); } catch (err) { console.error('Error deleting event: ', err); @@ -104,7 +123,8 @@ onMounted(() => { console.log('props.event', props.event); if (props.event) { dated.value = props.event?.dated; - excludeType.value = props.event?.type || 'all'; + excludeType.value = props.geoIds.length ? 'specificLocations' : 'all'; + tickedNodes.value = props.geoIds || []; } else if (props.date) dated.value = props.date; }); @@ -138,6 +158,13 @@ onMounted(() => { :label="t('eventsExclusionForm.specificLocations')" /> +
+ +