refactor: refs #7322 update getAgencies to handle client and return default agency
This commit is contained in:
parent
de39839140
commit
b10cb9f09f
|
@ -1,12 +1,21 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import agency from 'src/router/modules/agency';
|
||||||
|
|
||||||
export async function getAgencies(formData) {
|
export async function getAgencies(formData, client) {
|
||||||
if (!formData.warehouseId || !formData.addressId || !formData.landed) return;
|
if (!formData.warehouseId || !formData.addressId || !formData.landed) return;
|
||||||
|
|
||||||
|
let defaultAgency = null;
|
||||||
let params = {
|
let params = {
|
||||||
warehouseFk: formData.warehouseId,
|
warehouseFk: formData.warehouseId,
|
||||||
addressFk: formData.addressId,
|
addressFk: formData.addressId,
|
||||||
landed: formData.landed,
|
landed: formData.landed,
|
||||||
};
|
};
|
||||||
|
|
||||||
return await axios.get('Agencies/getAgenciesWithWarehouse', { params });
|
const { data } = await axios.get('Agencies/getAgenciesWithWarehouse', { params });
|
||||||
|
|
||||||
|
if(data && client) {
|
||||||
|
defaultAgency = data.find((agency) => agency.agencyModeFk === client.defaultAddress.agencyModeFk );
|
||||||
|
};
|
||||||
|
|
||||||
|
return {options: data, agency: defaultAgency}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,11 @@ onBeforeMount(async () => {
|
||||||
await onClientSelected(initialFormState);
|
await onClientSelected(initialFormState);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function resetAgenciesSelector(formData) {
|
||||||
|
agenciesOptions.value = [];
|
||||||
|
formData.agencyModeId = null;
|
||||||
|
}
|
||||||
|
|
||||||
const fetchClient = async (formData) => {
|
const fetchClient = async (formData) => {
|
||||||
const response = await getClient(formData.clientId);
|
const response = await getClient(formData.clientId);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
|
@ -55,21 +60,21 @@ const fetchAddresses = async (formData) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClientSelected = async (formData) => {
|
const onClientSelected = async (formData) => {
|
||||||
|
resetAgenciesSelector(formData);
|
||||||
await fetchClient(formData);
|
await fetchClient(formData);
|
||||||
await fetchAddresses(formData);
|
await fetchAddresses(formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAvailableAgencies = async (formData) => {
|
const fetchAvailableAgencies = async (formData) => {
|
||||||
const response = await getAgencies(formData);
|
resetAgenciesSelector(formData);
|
||||||
|
const response= await getAgencies(formData, selectedClient.value);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
agenciesOptions.value = response.data;
|
|
||||||
|
const { options, agency } = response
|
||||||
const defaultAgency = agenciesOptions.value.find(
|
if(options)
|
||||||
(agency) =>
|
agenciesOptions.value = options;
|
||||||
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
|
if(agency)
|
||||||
);
|
formData.agencyModeId = agency;
|
||||||
|
|
||||||
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const redirectToTicketList = (_, { id }) => {
|
const redirectToTicketList = (_, { id }) => {
|
||||||
|
|
|
@ -38,6 +38,11 @@ onBeforeMount(async () => {
|
||||||
await onClientSelected(initialFormState);
|
await onClientSelected(initialFormState);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function resetAgenciesSelector(formData) {
|
||||||
|
agenciesOptions.value = [];
|
||||||
|
if(formData) formData.agencyModeId = null;
|
||||||
|
}
|
||||||
|
|
||||||
const fetchClient = async (formData) => {
|
const fetchClient = async (formData) => {
|
||||||
const response = await getClient(formData.clientId);
|
const response = await getClient(formData.clientId);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
|
@ -55,21 +60,21 @@ const fetchAddresses = async (formData) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClientSelected = async (formData) => {
|
const onClientSelected = async (formData) => {
|
||||||
|
resetAgenciesSelector(formData);
|
||||||
await fetchClient(formData);
|
await fetchClient(formData);
|
||||||
await fetchAddresses(formData);
|
await fetchAddresses(formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAvailableAgencies = async (formData) => {
|
const fetchAvailableAgencies = async (formData) => {
|
||||||
const response = await getAgencies(formData);
|
resetAgenciesSelector(formData);
|
||||||
|
const response= await getAgencies(formData, selectedClient.value);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
agenciesOptions.value = response.data;
|
|
||||||
|
const { options, agency } = response
|
||||||
const defaultAgency = agenciesOptions.value.find(
|
if(options)
|
||||||
(agency) =>
|
agenciesOptions.value = options;
|
||||||
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
|
if(agency)
|
||||||
);
|
formData.agencyModeId = agency;
|
||||||
|
|
||||||
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const redirectToTicketList = (_, { id }) => {
|
const redirectToTicketList = (_, { id }) => {
|
||||||
|
|
|
@ -229,27 +229,33 @@ const columns = computed(() => [
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
function resetAgenciesSelector(formData) {
|
||||||
|
agenciesOptions.value = [];
|
||||||
|
if(formData) formData.agencyModeId = null;
|
||||||
|
}
|
||||||
|
|
||||||
function redirectToLines(id) {
|
function redirectToLines(id) {
|
||||||
const url = `#/ticket/${id}/sale`;
|
const url = `#/ticket/${id}/sale`;
|
||||||
window.open(url, '_blank');
|
window.open(url, '_blank');
|
||||||
}
|
}
|
||||||
|
|
||||||
const onClientSelected = async (formData) => {
|
const onClientSelected = async (formData) => {
|
||||||
|
resetAgenciesSelector(formData);
|
||||||
await fetchClient(formData);
|
await fetchClient(formData);
|
||||||
await fetchAddresses(formData);
|
await fetchAddresses(formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAvailableAgencies = async (formData) => {
|
const fetchAvailableAgencies = async (formData) => {
|
||||||
const response = await getAgencies(formData);
|
resetAgenciesSelector(formData);
|
||||||
|
const response= await getAgencies(formData, selectedClient.value);
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
agenciesOptions.value = response.data;
|
|
||||||
|
const { options, agency } = response
|
||||||
const defaultAgency = agenciesOptions.value.find(
|
if(options)
|
||||||
(agency) =>
|
agenciesOptions.value = options;
|
||||||
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
|
if(agency)
|
||||||
);
|
formData.agencyModeId = agency;
|
||||||
|
|
||||||
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchClient = async (formData) => {
|
const fetchClient = async (formData) => {
|
||||||
|
|
Loading…
Reference in New Issue