From 022ef2428927a12b57c58430eb7fb7f7c76b8952 Mon Sep 17 00:00:00 2001 From: Kevin Martinez Date: Mon, 26 Feb 2024 07:53:52 -0300 Subject: [PATCH] Refactor roadmaps stops with crud model --- src/pages/Route/Roadmap/RoadmapStops.vue | 224 ++++++++++------------- 1 file changed, 95 insertions(+), 129 deletions(-) diff --git a/src/pages/Route/Roadmap/RoadmapStops.vue b/src/pages/Route/Roadmap/RoadmapStops.vue index 5aba86062..6dc21563f 100644 --- a/src/pages/Route/Roadmap/RoadmapStops.vue +++ b/src/pages/Route/Roadmap/RoadmapStops.vue @@ -3,79 +3,41 @@ import { useI18n } from 'vue-i18n'; import { useRoute } from 'vue-router'; import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue'; import FetchData from 'components/FetchData.vue'; -import { computed, ref } from 'vue'; -import { useStateStore } from 'stores/useStateStore'; +import { onMounted, ref } from 'vue'; import VnSelectFilter from 'components/common/VnSelectFilter.vue'; import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputTime from 'components/common/VnInputTime.vue'; import VnInput from 'components/common/VnInput.vue'; -import axios from 'axios'; +import VnRow from 'components/ui/VnRow.vue'; +import CrudModel from 'components/CrudModel.vue'; const { t } = useI18n(); const route = useRoute(); -const stateStore = useStateStore(); - -const refreshKey = ref(0); -const expeditionList = ref([]); const warehouseList = ref([]); +const roadmapStopsCrudRef = ref(null); -const stopList = computed(() => expeditionList.value.filter((item) => !item.deleted)); +const defaultStop = ref({ + roadmapFk: Number(route.params?.id) || 0, + eta: new Date().toISOString(), +}); -const addStop = async () => { - const response = await axios.get(`Roadmaps/${route.params?.id}`, { - params: { - filter: JSON.stringify({ - fields: ['etd'], - }), - }, - }); - const eta = new Date(response.data.etd); +const updateDefaultStop = (data) => { + const eta = new Date(data.etd); eta.setDate(eta.getDate() + 1); - expeditionList.value.push({ - id: expeditionList.value.length * -1, - roadmapFk: Number(route.params?.id) || 0, - eta: eta.toISOString(), - }); + defaultStop.value.eta = eta.toISOString(); }; -const updateStop = (stop) => { - if (stop.id > 0) { - stop.updated = true; - } -}; - -const deleteStop = (stop) => { - if (stop.id > 0) { - stop.deleted = true; - } -}; - -const onSave = async () => { - const body = { - creates: expeditionList.value - .filter((item) => item.id < 0) - .map(({ id, ...data }) => data), - deletes: expeditionList.value - .filter((item) => item.deleted) - .map((item) => item.id), - updates: expeditionList.value - .filter((item) => item.updated) - .map(({ id, updated, ...data }) => ({ data, where: { id } })), - }; - await axios.post(`ExpeditionTrucks/crud`, body); - refreshKey.value ++; -}; +onMounted(() => { + if (roadmapStopsCrudRef.value) roadmapStopsCrudRef.value.reload(); +}); es: @@ -166,4 +130,6 @@ es: ETA date: Fecha ETA ETA hour: Hora ETA Description: DescripciĆ³n + Remove stop: Eliminar parada + Add stop: AƱadir parada