add: search vehicles view & fixes: bugs state

This commit is contained in:
Alexandro Uc Santos
2024-08-17 18:56:22 -06:00
parent 3cd6715c4b
commit 84c0595f5b
24 changed files with 392 additions and 75 deletions

View File

@@ -0,0 +1,37 @@
import { ref } from "vue";
import api from "../lib/axios";
export default function useSearchVehicles() {
const vehicles = ref([]);
const loading = ref(false);
const total = ref(0);
const currentPage = ref(0);
const getVehiclesPublished = async(filterQuery) => {
loading.value = true;
let filterArr = Object.values(filterQuery);
let cleanfilterArr = filterArr.filter(n=>n);
var filterStr = "";
if(cleanfilterArr.length >0){
filterStr = "?"+cleanfilterArr.join("&");
}
try {
const endpoint = `/v1/vehicles/global/find${filterStr}&$sort[createdAt]=-1`;
const {data} = await api.get(endpoint);
total.value = data.total;
vehicles.value = data.data;
} catch (error) {
vehicles.value = [];
total.value = 0;
}
loading.value = false;
}
return {
getVehiclesPublished,
loading,
vehicles,
total,
currentPage,
}
}

View File

@@ -17,7 +17,7 @@ export default function useSearchLoads() {
}
try {
const endpoint = `/v1/loads/find${filterStr}&$sort[createdAt]=-1`;
console.log(endpoint);
// console.log(endpoint);
const {data} = await api.get(endpoint);
total.value = data.total;
loads.value = data.data;