Add default agency if found

This commit is contained in:
William Buezas 2024-12-03 13:04:21 -03:00
parent e7289b05e9
commit 221d0e7b8c
1 changed files with 20 additions and 0 deletions

View File

@ -28,6 +28,7 @@ const agencies = ref([]);
const warehouses = ref([]);
const currentStep = ref('method');
const id = route.params.id;
const defaultValues = ref(null);
const orderForm = ref({
method: 'AGENCY',
date: formatDate(Date.vnNew(), 'YYYY/MM/DD'),
@ -179,6 +180,15 @@ const getAgencies = async () => {
}
);
agencies.value = results[1].data;
if (agencies.value && agencies.value.length && defaultValues.value) {
const found = agencies.value.find(
agency => agency.id === defaultValues.value.defaultAgencyFk
);
if (found)
orderForm.value.agency = defaultValues.value.defaultAgencyFk;
}
} catch (error) {
console.error('Error getting agencies:', error);
}
@ -284,6 +294,13 @@ const submit = async () => {
}
};
const getDefaultValues = async () => {
return await jApi.query(
`SELECT deliveryMethod, agencyModeFk, addressFk, defaultAgencyFk
FROM myBasketDefaults`
);
};
onMounted(async () => {
today.value = Date.vnNew();
today.value.setHours(0, 0, 0, 0);
@ -305,6 +322,9 @@ onMounted(async () => {
orderForm.value.agency = order.agencyModeFk;
orderForm.value.address = order.addressFk;
}
} else {
const [_defaultValues] = await getDefaultValues();
if (_defaultValues) defaultValues.value = _defaultValues;
}
getAddresses();