forked from verdnatura/hedera-web
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 warehouses = ref([]);
|
||||||
const currentStep = ref('method');
|
const currentStep = ref('method');
|
||||||
const id = route.params.id;
|
const id = route.params.id;
|
||||||
|
const defaultValues = ref(null);
|
||||||
const orderForm = ref({
|
const orderForm = ref({
|
||||||
method: 'AGENCY',
|
method: 'AGENCY',
|
||||||
date: formatDate(Date.vnNew(), 'YYYY/MM/DD'),
|
date: formatDate(Date.vnNew(), 'YYYY/MM/DD'),
|
||||||
|
@ -179,6 +180,15 @@ const getAgencies = async () => {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
agencies.value = results[1].data;
|
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) {
|
} catch (error) {
|
||||||
console.error('Error getting agencies:', 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 () => {
|
onMounted(async () => {
|
||||||
today.value = Date.vnNew();
|
today.value = Date.vnNew();
|
||||||
today.value.setHours(0, 0, 0, 0);
|
today.value.setHours(0, 0, 0, 0);
|
||||||
|
@ -305,6 +322,9 @@ onMounted(async () => {
|
||||||
orderForm.value.agency = order.agencyModeFk;
|
orderForm.value.agency = order.agencyModeFk;
|
||||||
orderForm.value.address = order.addressFk;
|
orderForm.value.address = order.addressFk;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const [_defaultValues] = await getDefaultValues();
|
||||||
|
if (_defaultValues) defaultValues.value = _defaultValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
getAddresses();
|
getAddresses();
|
||||||
|
|
Loading…
Reference in New Issue