add: Form create load
This commit is contained in:
@@ -32,6 +32,8 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
sesion.value = resp.data.session_token;
|
||||
token.value = resp.data.accessToken;
|
||||
localStorage.setItem('session', resp.data.session_token);
|
||||
localStorage.setItem('access', resp.data.accessToken);
|
||||
localStorage.setItem('id', resp.data.user.company);
|
||||
checking.value = false;
|
||||
} else {
|
||||
noty.show = true;
|
||||
@@ -53,6 +55,8 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
const logout = () => {
|
||||
|
||||
localStorage.removeItem('session');
|
||||
localStorage.removeItem('access');
|
||||
localStorage.removeItem('id');
|
||||
company.clear();
|
||||
router.push({name: 'login'});
|
||||
sesion.value = '';
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref, watch, onMounted } from "vue";
|
||||
import { ref } from "vue";
|
||||
import { useAuthStore } from "./auth";
|
||||
import { getCompany } from "../services/company";
|
||||
import api from "../lib/axios";
|
||||
|
||||
export const useCompanyStore = defineStore('company', () => {
|
||||
|
||||
const auth = useAuthStore();
|
||||
const companyid = localStorage.getItem('id');
|
||||
const company = ref(null)
|
||||
const loads = ref([])
|
||||
const proposals = ref([])
|
||||
const loading = ref(false);
|
||||
|
||||
const getCompanyData = async() => {
|
||||
loading.value = true;
|
||||
if(!company.value) {
|
||||
console.log('Se ejecuta');
|
||||
loading.value = true;
|
||||
const companyId = auth.user?.company;
|
||||
console.log({companyId});
|
||||
const resp = await getCompany(companyId);
|
||||
const resp = await getCompany(companyid);
|
||||
console.log(resp);
|
||||
company.value = resp;
|
||||
}
|
||||
@@ -28,11 +28,49 @@ export const useCompanyStore = defineStore('company', () => {
|
||||
loading.value = false;
|
||||
}
|
||||
|
||||
const getCompanyLoads = async(filterQuery) => {
|
||||
let filterArr = Object.values(filterQuery);
|
||||
let cleanfilterArr = filterArr.filter(n=>n);
|
||||
var filterStr = "";
|
||||
if(cleanfilterArr.length >0){
|
||||
filterStr = cleanfilterArr.join("&");
|
||||
}
|
||||
console.log(filterStr);
|
||||
try {
|
||||
const endpoint = `/loads?company=${companyid}&${filterStr}`;
|
||||
console.log(endpoint);
|
||||
const {data} = await api.get(endpoint);
|
||||
loads.value = data.data;
|
||||
} catch (error) {
|
||||
loads.value = [];
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
///loads?company=64fa70c130d2650011ac4f3a&status[$ne]=Closed,posted_by_name[$regex]=ju&posted_by_name[$options]=i
|
||||
|
||||
const getProposalsCompany = async() => {
|
||||
try {
|
||||
const endpoint = `/proposals?carrier=${companyid}`;
|
||||
console.log(endpoint);
|
||||
const {data} = await api.get(endpoint);
|
||||
proposals.value = data.data;
|
||||
console.log(data);
|
||||
} catch (error) {
|
||||
proposals.value = [];
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
company,
|
||||
loading,
|
||||
getCompanyData,
|
||||
clear
|
||||
getCompanyData,
|
||||
getCompanyLoads,
|
||||
getProposalsCompany,
|
||||
clear,
|
||||
loading,
|
||||
loads,
|
||||
proposals,
|
||||
company,
|
||||
}
|
||||
});
|
||||
11
src/stores/loads.js
Normal file
11
src/stores/loads.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
export const useLoadsStore = defineStore('load', () => {
|
||||
|
||||
const currentLoad = ref(null);
|
||||
|
||||
return {
|
||||
currentLoad
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user