Add default agency if found
This commit is contained in:
parent
e7289b05e9
commit
221d0e7b8c
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue