set filters loads locations & images preview

This commit is contained in:
Alexandro Uc Santos
2024-10-05 17:37:05 -06:00
parent f129acf9e6
commit 325d2f3fd2
5 changed files with 120 additions and 36 deletions

View File

@@ -17,7 +17,8 @@ export const useCompanyStore = defineStore('company', () => {
const budgetsTotal = ref(0);
const budgetsCurrentPage = ref(0);
const locations = ref([]);
const locationsLoads = ref([]);
const locationsLoad = ref([]);
const locationsDowload = ref([]);
const locationsTotal = ref(0);
const locationType = ref({value: '', label: t('labels.alls')})
const locationsCurrentPage = ref(0);
@@ -150,7 +151,7 @@ export const useCompanyStore = defineStore('company', () => {
budgetsTotal.value = 0;
budgetsCurrentPage.value = 0;
locations.value = [];
locationsLoads.value = [];
locationsLoad.value = [];
locationsTotal.value = 0;
locationsCurrentPage.value = 0;
proposals.value = [];
@@ -300,16 +301,37 @@ export const useCompanyStore = defineStore('company', () => {
}
}
const getLocationsLoads = async() => {
if(locationsLoads.value.length <= 0) {
const filterStr = "?company="+ localStorage.getItem('id') + '&$limit=100'
const resp = await getLocations(filterStr);
const getLocationsLoads = async(type) => {
console.log(type);
let locationsType = (type === 'loading') ? locationsLoad.value : locationsDowload.value;
console.log(locationsType);
if(locationsType.length <= 0) {
const filterStr = "?company="+ localStorage.getItem('id') + '&$limit=100';
const respBoth = await getLocations(filterStr + '&type=' + 'both');
const resp = await getLocations(filterStr + '&type=' + type);
if(resp !== null && resp.total > 0) {
locationsLoads.value = resp.data;
locationsType = [...respBoth.data, ...resp.data];
if(type === 'loading') {
locationsLoad.value = [
...respBoth.data,
...resp.data
];
} else {
locationsDowload.value = [
...respBoth.data,
...resp.data
];
}
} else {
locationsLoads.value = [];
if(type === 'loading') {
locationsLoad.value = [];
} else {
locationsDowload.value = [];
}
locationsType = [];
}
}
return locationsType;
}
const createLocationCompany = async(formData, localData) => {
@@ -320,10 +342,21 @@ export const useCompanyStore = defineStore('company', () => {
...localData
});
locationsTotal.value++;
locationsLoads.value.unshift({
locationsLoad.value.unshift({
...data?.data,
...localData
})
if(data?.data.type === 'both' || data?.data.type === 'loading' && locationsLoad.value.length > 0) {
locationsLoad.value.unshift({
...data?.data,
...localData
})
} else if (data?.data.type == 'both' || data?.data.type === 'unloading' && locationsDowload.value.length > 0) {
locationsDowload.value.unshift({
...data?.data,
...localData
})
}
return 'success';
} else {
return t('errors.generic');
@@ -340,13 +373,25 @@ export const useCompanyStore = defineStore('company', () => {
...data,
...localData
};
if(locationsLoads.value.length > 0) {
const indexl = locationsLoads.value.findIndex((loc) => loc._id === id);
locationsLoads.value[indexl] = {
...locationsLoads.value[index],
...data,
...localData
};
if(locationsLoad.value.length > 0) {
const indexl = locationsLoad.value.findIndex((loc) => loc._id === id);
if(indexl !== -1) {
locationsLoad.value[indexl] = {
...locationsLoad.value[index],
...data,
...localData
};
}
}
if(locationsDowload.value.length > 0) {
const indexl = locationsDowload.value.findIndex((loc) => loc._id === id);
if(indexl !== -1) {
locationsDowload.value[indexl] = {
...locationsDowload.value[index],
...data,
...localData
};
}
}
}
return 'success';
@@ -359,8 +404,11 @@ export const useCompanyStore = defineStore('company', () => {
const data = await deleteLocation(id);
if(data) {
locations.value = locations.value.filter(loc => loc._id !== id);
if(locationsLoads.value.length > 0) {
locationsLoads.value = locationsLoads.value.filter(loc => loc._id !== id);
if(locationsLoad.value.length > 0) {
locationsLoad.value = locationsLoad.value.filter(loc => loc._id !== id);
}
if(locationsDowload.value.length > 0) {
locationsDowload.value = locationsDowload.value.filter(loc => loc._id !== id);
}
return 'success';
@@ -398,7 +446,8 @@ export const useCompanyStore = defineStore('company', () => {
usersTotal,
usersCurrentPage,
locations,
locationsLoads,
locationsLoad,
locationsDowload,
locationsTotal,
locationsCurrentPage,
locationType,