-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsejours.vue
More file actions
146 lines (132 loc) · 4.14 KB
/
sejours.vue
File metadata and controls
146 lines (132 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
<TitleWithIcon
icon="fr-icon-map-pin-2-fill"
:level="3"
title-class="fr-text--lead fr-mb-0"
>
Séjours (par années)
</TitleWithIcon>
<p class="light-decisions-text-text-default-info fr-text--xs">
<span class="fr-icon-info-fill" aria-hidden="true"></span>
Ces informations ont été automatiquement remplies à partir de vos
déclarations de séjour. Veuillez les vérifier et les corriger si nécessaire.
</p>
<p>Sélectionner les années</p>
<p class="fr-hint-text">Toutes les années doivent être renseignées</p>
<DsfrTabs
v-model="selectedTabIndex"
tab-list-name="display-sejours-tabs"
:tab-titles="tabTitles"
:initial-selected-index="initialSelectedIndex"
@update:model-value="selectTab"
>
<DsfrTabContent
v-for="(tab, idx) in tabTitles"
:key="tab.tabId"
:panel-id="tab.panelId"
:tab-id="tab.tabId"
:selected="selectedTabIndex === idx"
:asc="asc"
>
<AgrementBilanSejourDetails
:ref="(el) => setSejourDetailsRef(el, idx)"
:year="parseInt(tab.title)"
:bilan-annuel="bilanAnnuelByYear[parseInt(tab.title)]"
:agrement-status="props.initAgrement?.statut"
:agrement-id="props.initAgrement?.id"
:modifiable="props.modifiable"
/>
</DsfrTabContent>
</DsfrTabs>
</template>
<script setup lang="ts">
import { TitleWithIcon, useToaster } from "@vao/shared-ui";
const props = defineProps({
initAgrement: { type: Object, required: true },
cdnUrl: { type: String, required: true },
modifiable: { type: Boolean, default: true },
});
const toaster = useToaster();
const initialSelectedIndex = 0;
const selectedTabIndex = ref<number>(initialSelectedIndex);
const asc = ref<boolean>(true);
const sejourDetailsRefs = ref<any[]>([]);
function setSejourDetailsRef(el: any, idx: number) {
sejourDetailsRefs.value[idx] = el;
}
const currentYear = new Date().getFullYear();
const startYear = 2021;
const tabTitles = computed(() => {
const years = [];
for (let year = currentYear - 1; year >= startYear; year--) {
years.push({
title: `${year}`,
tabId: `declaration-sejour-tab-${year}`,
panelId: `declaration-sejour-content-${year}`,
});
}
return years;
});
const bilanAnnuelByYear = computed(() => {
const result: Record<number, any> = {};
const data = props.initAgrement?.agrementBilanAnnuel || [];
data.forEach((bilan: any) => {
const year = bilan.annee;
if (!result[year]) {
result[year] = {
...bilan,
bilanHebergement: [...bilan.bilanHebergement],
trancheAge: [...bilan.trancheAge],
typeHandicap: [...bilan.typeHandicap],
nbFemmes: bilan.nbFemmes,
nbHommes: bilan.nbHommes,
nbGlobalVacanciers: bilan.nbGlobalVacanciers,
nbTotalJoursVacances: bilan.nbTotalJoursVacances,
};
} else {
result[year].bilanHebergement.push(...bilan.bilanHebergement);
result[year].trancheAge = Array.from(
new Set([...result[year].trancheAge, ...bilan.trancheAge]),
);
result[year].typeHandicap = Array.from(
new Set([...result[year].typeHandicap, ...bilan.typeHandicap]),
);
result[year].nbFemmes += bilan.nbFemmes;
result[year].nbHommes += bilan.nbHommes;
result[year].nbGlobalVacanciers += bilan.nbGlobalVacanciers;
result[year].nbTotalJoursVacances += bilan.nbTotalJoursVacances;
}
});
return result;
});
const selectTab = async (idx: number) => {
asc.value = selectedTabIndex.value < idx;
};
async function validateAllYears() {
let allValid = true;
const allResults = [];
for (const ref of sejourDetailsRefs.value) {
if (ref && ref.validateForm) {
const result = await ref.validateForm();
if (!result || result === false) {
allValid = false;
} else if (result?.annee) {
allResults.push(result);
}
} else {
allValid = false;
}
}
if (!allValid) {
toaster.error({
titleTag: "h2",
description: "Toutes les années doivent être renseignées et valides.",
});
return false;
}
return allResults;
}
defineExpose({
validateForm: validateAllYears,
});
</script>