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 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;
|
||||
|
||||
let defaultAgency = null;
|
||||
let params = {
|
||||
warehouseFk: formData.warehouseId,
|
||||
addressFk: formData.addressId,
|
||||
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);
|
||||
});
|
||||
|
||||
function resetAgenciesSelector(formData) {
|
||||
agenciesOptions.value = [];
|
||||
formData.agencyModeId = null;
|
||||
}
|
||||
|
||||
const fetchClient = async (formData) => {
|
||||
const response = await getClient(formData.clientId);
|
||||
if (!response) return;
|
||||
|
@ -55,21 +60,21 @@ const fetchAddresses = async (formData) => {
|
|||
};
|
||||
|
||||
const onClientSelected = async (formData) => {
|
||||
resetAgenciesSelector(formData);
|
||||
await fetchClient(formData);
|
||||
await fetchAddresses(formData);
|
||||
};
|
||||
|
||||
const fetchAvailableAgencies = async (formData) => {
|
||||
const response = await getAgencies(formData);
|
||||
resetAgenciesSelector(formData);
|
||||
const response= await getAgencies(formData, selectedClient.value);
|
||||
if (!response) return;
|
||||
agenciesOptions.value = response.data;
|
||||
|
||||
const defaultAgency = agenciesOptions.value.find(
|
||||
(agency) =>
|
||||
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
|
||||
);
|
||||
|
||||
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
|
||||
|
||||
const { options, agency } = response
|
||||
if(options)
|
||||
agenciesOptions.value = options;
|
||||
if(agency)
|
||||
formData.agencyModeId = agency;
|
||||
};
|
||||
|
||||
const redirectToTicketList = (_, { id }) => {
|
||||
|
|
|
@ -38,6 +38,11 @@ onBeforeMount(async () => {
|
|||
await onClientSelected(initialFormState);
|
||||
});
|
||||
|
||||
function resetAgenciesSelector(formData) {
|
||||
agenciesOptions.value = [];
|
||||
if(formData) formData.agencyModeId = null;
|
||||
}
|
||||
|
||||
const fetchClient = async (formData) => {
|
||||
const response = await getClient(formData.clientId);
|
||||
if (!response) return;
|
||||
|
@ -55,21 +60,21 @@ const fetchAddresses = async (formData) => {
|
|||
};
|
||||
|
||||
const onClientSelected = async (formData) => {
|
||||
resetAgenciesSelector(formData);
|
||||
await fetchClient(formData);
|
||||
await fetchAddresses(formData);
|
||||
};
|
||||
|
||||
const fetchAvailableAgencies = async (formData) => {
|
||||
const response = await getAgencies(formData);
|
||||
resetAgenciesSelector(formData);
|
||||
const response= await getAgencies(formData, selectedClient.value);
|
||||
if (!response) return;
|
||||
agenciesOptions.value = response.data;
|
||||
|
||||
const defaultAgency = agenciesOptions.value.find(
|
||||
(agency) =>
|
||||
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
|
||||
);
|
||||
|
||||
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
|
||||
|
||||
const { options, agency } = response
|
||||
if(options)
|
||||
agenciesOptions.value = options;
|
||||
if(agency)
|
||||
formData.agencyModeId = agency;
|
||||
};
|
||||
|
||||
const redirectToTicketList = (_, { id }) => {
|
||||
|
|
|
@ -229,27 +229,33 @@ const columns = computed(() => [
|
|||
],
|
||||
},
|
||||
]);
|
||||
|
||||
function resetAgenciesSelector(formData) {
|
||||
agenciesOptions.value = [];
|
||||
if(formData) formData.agencyModeId = null;
|
||||
}
|
||||
|
||||
function redirectToLines(id) {
|
||||
const url = `#/ticket/${id}/sale`;
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
const onClientSelected = async (formData) => {
|
||||
const onClientSelected = async (formData) => {
|
||||
resetAgenciesSelector(formData);
|
||||
await fetchClient(formData);
|
||||
await fetchAddresses(formData);
|
||||
};
|
||||
|
||||
const fetchAvailableAgencies = async (formData) => {
|
||||
const response = await getAgencies(formData);
|
||||
resetAgenciesSelector(formData);
|
||||
const response= await getAgencies(formData, selectedClient.value);
|
||||
if (!response) return;
|
||||
agenciesOptions.value = response.data;
|
||||
|
||||
const defaultAgency = agenciesOptions.value.find(
|
||||
(agency) =>
|
||||
agency.agencyModeFk === selectedClient.value.defaultAddress.agencyModeFk
|
||||
);
|
||||
|
||||
if (defaultAgency) formData.agencyModeId = defaultAgency.agencyModeFk;
|
||||
|
||||
const { options, agency } = response
|
||||
if(options)
|
||||
agenciesOptions.value = options;
|
||||
if(agency)
|
||||
formData.agencyModeId = agency;
|
||||
};
|
||||
|
||||
const fetchClient = async (formData) => {
|
||||
|
|
Loading…
Reference in New Issue