diff --git a/src/pages/Travel/ExtraCommunity.vue b/src/pages/Travel/ExtraCommunity.vue
index 4cbb850e1..42c5480f4 100644
--- a/src/pages/Travel/ExtraCommunity.vue
+++ b/src/pages/Travel/ExtraCommunity.vue
@@ -47,6 +47,10 @@ const arrayData = useArrayData('ExtraCommunity', {
});
const rows = computed(() => arrayData.store.data || []);
+const draggedRowIndex = ref(null);
+const targetRowIndex = ref(null);
+const entryRowIndex = ref(null);
+const draggedEntry = ref(null);
const tableColumnComponents = {
id: {
@@ -263,6 +267,56 @@ onMounted(async () => {
landedTo.value.setHours(23, 59, 59, 59);
await getData();
});
+
+const handleDragStart = (event, rowIndex, entryIndex) => {
+ draggedRowIndex.value = rowIndex;
+ entryRowIndex.value = entryIndex;
+ event.dataTransfer.effectAllowed = 'move';
+};
+
+const handleDragEnter = (_, targetIndex) => {
+ targetRowIndex.value = targetIndex;
+};
+
+const handleDragOver = (e) => {
+ e.preventDefault();
+};
+
+const saveRowDrop = async (targetRowIndex) => {
+ const entryId = draggedEntry.value.id;
+ const travelId = rows.value[targetRowIndex].id;
+ await axios.patch(`Entries/${entryId}`, { travelFk: travelId });
+};
+
+const moveRow = async (draggedRowIndex, targetRowIndex, entryIndex) => {
+ try {
+ if (draggedRowIndex === targetRowIndex) return;
+ // Remover entry de la row original
+ draggedEntry.value = rows.value[draggedRowIndex].entries.splice(entryIndex, 1)[0];
+ //Si la row de destino por alguna razón no tiene la propiedad entry la creamos
+ if (!rows.value[targetRowIndex].entries) rows.value[targetRowIndex].entries = [];
+ // Añadir entry a la row de destino
+ rows.value[targetRowIndex].entries.push(draggedEntry.value);
+
+ await saveRowDrop(targetRowIndex);
+ } catch (err) {
+ cleanDragAndDropData();
+ console.error('Error moving row', err);
+ }
+};
+
+const handleDrop = () => {
+ if (!draggedRowIndex.value && !targetRowIndex.value) return;
+ moveRow(draggedRowIndex.value, targetRowIndex.value, entryRowIndex.value);
+ cleanDragAndDropData();
+};
+
+const cleanDragAndDropData = () => {
+ draggedRowIndex.value = null;
+ targetRowIndex.value = null;
+ entryRowIndex.value = null;
+ draggedEntry.value = null;
+};
@@ -302,18 +356,23 @@ onMounted(async () => {
row-key="clientId"
:pagination="{ rowsPerPage: 0 }"
class="full-width"
+ table-style="user-select: none;"
>
{
+
-
- {{ entry.id }}
-
-
-
- {{ entry.supplierName }}
-
-
-
- {{ toCurrency(entry.invoiceAmount) }}
- {{ entry.reference }}
- {{ entry.stickers }}
-
- {{ entry.loadedkg }}
- {{ entry.volumeKg }}
-
-
-
-
+
+
+ {{ entry.id }}
+
+
+
+ {{
+ entry.supplierName
+ }}
+
+
+
+ {{ toCurrency(entry.invoiceAmount) }}
+ {{ entry.reference }}
+ {{ entry.stickers }}
+
+ {{ entry.loadedkg }}
+ {{ entry.volumeKg }}
+
+
+
+
+
+
+
en:
searchExtraCommunity: Search for extra community shipping