-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Aucun lieu trouvé.
+
+
+
+ Sélectionné: {{ selectedLocation.name || 'Lieu' }}
+
@@ -74,12 +196,27 @@ import { defineEmits, defineProps } from "vue";
import { ref } from "vue";
import SoftInput from "@/components/SoftInput.vue";
import SoftButton from "@/components/SoftButton.vue";
+import { useClientLocationStore } from "@/stores/clientLocation";
+import { useDeceasedStore } from "@/stores/deceasedStore";
const props = defineProps({
loading: { type: Boolean, default: false },
});
const emit = defineEmits(["createConvoy"]);
+const clientLocationStore = useClientLocationStore();
+const deceasedStore = useDeceasedStore();
+const deceasedSearch = ref("");
+const deceasedResults = ref([]);
+const deceasedLoading = ref(false);
+const showDeceasedResults = ref(false);
+const selectedDeceased = ref(null);
+const locationSearch = ref("");
+const locationResults = ref([]);
+const locationLoading = ref(false);
+const showLocationResults = ref(false);
+const selectedLocation = ref(null);
+let debounceTimeout = null;
const defaultForm = () => ({
deceased_id: "",
@@ -88,12 +225,110 @@ const defaultForm = () => ({
transport_mode: "road",
planned_start_at: "",
estimated_end_at: "",
+ departure_location_id: null,
+ departure_name: "",
+ departure_address: "",
departure_city: "",
+ departure_postal_code: "",
+ departure_country_code: "",
family_email: "",
});
const form = ref(defaultForm());
+const handleDeceasedSearch = () => {
+ showDeceasedResults.value = true;
+
+ if (debounceTimeout) clearTimeout(debounceTimeout);
+
+ if (!deceasedSearch.value.trim()) {
+ deceasedResults.value = [];
+ showDeceasedResults.value = false;
+ clearSelectedDeceased();
+ return;
+ }
+
+ deceasedLoading.value = true;
+
+ debounceTimeout = setTimeout(async () => {
+ try {
+ const results = await deceasedStore.searchDeceased(deceasedSearch.value);
+ deceasedResults.value = results || [];
+ } catch (error) {
+ console.error("Error searching deceased:", error);
+ deceasedResults.value = [];
+ } finally {
+ deceasedLoading.value = false;
+ }
+ }, 300);
+};
+
+const selectDeceased = (deceased) => {
+ selectedDeceased.value = deceased;
+ deceasedSearch.value = [deceased.first_name, deceased.last_name].filter(Boolean).join(" ");
+ form.value.deceased_id = deceased.id;
+ deceasedResults.value = [];
+ showDeceasedResults.value = false;
+};
+
+const clearSelectedDeceased = () => {
+ selectedDeceased.value = null;
+ form.value.deceased_id = "";
+};
+
+const handleLocationSearch = () => {
+ showLocationResults.value = true;
+
+ if (debounceTimeout) clearTimeout(debounceTimeout);
+
+ if (!locationSearch.value.trim()) {
+ locationResults.value = [];
+ showLocationResults.value = false;
+ clearSelectedLocation();
+ return;
+ }
+
+ locationLoading.value = true;
+
+ debounceTimeout = setTimeout(async () => {
+ try {
+ const response = await clientLocationStore.fetchClientLocations({
+ search: locationSearch.value,
+ per_page: 10,
+ });
+ locationResults.value = response.data || [];
+ } catch (error) {
+ console.error("Error searching locations:", error);
+ locationResults.value = [];
+ } finally {
+ locationLoading.value = false;
+ }
+ }, 300);
+};
+
+const selectLocation = (location) => {
+ selectedLocation.value = location;
+ locationSearch.value = location.name || [location.address_line1, location.city].filter(Boolean).join(", ");
+ form.value.departure_location_id = location.id;
+ form.value.departure_name = location.name || null;
+ form.value.departure_address = location.address_line1 || null;
+ form.value.departure_city = location.city || null;
+ form.value.departure_postal_code = location.postal_code || null;
+ form.value.departure_country_code = location.country_code || null;
+ locationResults.value = [];
+ showLocationResults.value = false;
+};
+
+const clearSelectedLocation = () => {
+ selectedLocation.value = null;
+ form.value.departure_location_id = null;
+ form.value.departure_name = "";
+ form.value.departure_address = "";
+ form.value.departure_city = "";
+ form.value.departure_postal_code = "";
+ form.value.departure_country_code = "";
+};
+
const submitForm = () => {
emit("createConvoy", {
deceased_id: Number(form.value.deceased_id),
@@ -102,12 +337,28 @@ const submitForm = () => {
transport_mode: form.value.transport_mode,
planned_start_at: form.value.planned_start_at,
estimated_end_at: form.value.estimated_end_at || null,
+ departure_location_selection_mode: "place",
+ departure_location_id: form.value.departure_location_id || null,
+ departure_name: form.value.departure_name || null,
+ departure_address: form.value.departure_address || null,
departure_city: form.value.departure_city || null,
+ departure_postal_code: form.value.departure_postal_code || null,
+ departure_country_code: form.value.departure_country_code || null,
family_email: form.value.family_email || null,
});
};
const resetForm = () => {
form.value = defaultForm();
+ deceasedSearch.value = "";
+ deceasedResults.value = [];
+ deceasedLoading.value = false;
+ showDeceasedResults.value = false;
+ selectedDeceased.value = null;
+ locationSearch.value = "";
+ locationResults.value = [];
+ locationLoading.value = false;
+ showLocationResults.value = false;
+ selectedLocation.value = null;
};
diff --git a/thanasoft-front/src/stores/deceasedStore.ts b/thanasoft-front/src/stores/deceasedStore.ts
index cdfc4ae..ad2e57f 100644
--- a/thanasoft-front/src/stores/deceasedStore.ts
+++ b/thanasoft-front/src/stores/deceasedStore.ts
@@ -63,8 +63,31 @@ export const useDeceasedStore = defineStore("deceased", () => {
success.value = false;
};
+ const normalizeDeceased = (entry: Partial | null | undefined): Deceased | null => {
+ if (!entry || typeof entry !== "object") {
+ return null;
+ }
+
+ return {
+ id: entry.id,
+ last_name: entry.last_name || "",
+ first_name: entry.first_name || "",
+ full_name: entry.full_name,
+ birth_date: entry.birth_date,
+ death_date: entry.death_date,
+ place_of_death: entry.place_of_death,
+ notes: entry.notes,
+ documents_count: entry.documents_count,
+ interventions_count: entry.interventions_count,
+ created_at: entry.created_at,
+ updated_at: entry.updated_at,
+ };
+ };
+
const setDeceased = (newDeceased: Deceased[]) => {
- deceased.value = newDeceased;
+ deceased.value = (newDeceased || [])
+ .map((entry) => normalizeDeceased(entry))
+ .filter((entry): entry is Deceased => entry !== null);
};
const setCurrentDeceased = (deceased: Deceased | null) => {