forked from verdnatura/salix-front
fix(TicketBasicData): getShipped, getLanded & bad try catch
This commit is contained in:
parent
6de5864dd6
commit
e230cc61a0
|
@ -16,12 +16,9 @@ import { useAcl } from 'src/composables/useAcl';
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
import { toTimeFormat } from 'filters/date.js';
|
import { toTimeFormat } from 'filters/date.js';
|
||||||
|
|
||||||
const $props = defineProps({
|
const formData = defineModel({
|
||||||
formData: {
|
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
default: () => ({}),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['updateForm']);
|
const emit = defineEmits(['updateForm']);
|
||||||
|
@ -40,7 +37,6 @@ const agenciesOptions = ref([]);
|
||||||
const zonesOptions = ref([]);
|
const zonesOptions = ref([]);
|
||||||
const addresses = ref([]);
|
const addresses = ref([]);
|
||||||
const zoneSelectRef = ref();
|
const zoneSelectRef = ref();
|
||||||
const formData = ref($props.formData);
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => formData.value,
|
() => formData.value,
|
||||||
|
@ -69,75 +65,44 @@ const zoneWhere = computed(() => {
|
||||||
: {};
|
: {};
|
||||||
});
|
});
|
||||||
|
|
||||||
const getLanded = async (params) => {
|
async function getLanded(params) {
|
||||||
try {
|
getDate(`Agencies/getLanded`, params);
|
||||||
const validParams =
|
}
|
||||||
shipped.value && addressId.value && agencyModeId.value && warehouseId.value;
|
|
||||||
if (!validParams) return;
|
async function getShipped(params) {
|
||||||
|
getDate(`Agencies/getShipped`, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getDate(query, params) {
|
||||||
|
for (const param in params) {
|
||||||
|
if (!params[param]) return;
|
||||||
|
}
|
||||||
|
|
||||||
formData.value.zoneFk = null;
|
formData.value.zoneFk = null;
|
||||||
zonesOptions.value = [];
|
zonesOptions.value = [];
|
||||||
const { data } = await axios.get(`Agencies/getLanded`, { params });
|
const { data } = await axios.get(query, { params });
|
||||||
if (data) {
|
if (!data) return notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
|
||||||
formData.value.zoneFk = data.zoneFk;
|
|
||||||
formData.value.landed = data.landed;
|
|
||||||
formData.value.shipped = params.shipped;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getShipped = async (params) => {
|
|
||||||
try {
|
|
||||||
const validParams =
|
|
||||||
landed.value && addressId.value && agencyModeId.value && warehouseId.value;
|
|
||||||
if (!validParams) return;
|
|
||||||
|
|
||||||
formData.value.zoneFk = null;
|
|
||||||
zonesOptions.value = [];
|
|
||||||
const { data } = await axios.get(`Agencies/getShipped`, { params });
|
|
||||||
if (data) {
|
|
||||||
formData.value.zoneFk = data.zoneFk;
|
formData.value.zoneFk = data.zoneFk;
|
||||||
formData.value.landed = params.landed;
|
if (data.landed) formData.value.landed = data.landed;
|
||||||
formData.value.shipped = data.shipped;
|
if (data.shipped) formData.value.shipped = data.shipped;
|
||||||
} else {
|
|
||||||
notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onChangeZone = async (zoneId) => {
|
const onChangeZone = async (zoneId) => {
|
||||||
try {
|
|
||||||
formData.value.agencyModeFk = null;
|
formData.value.agencyModeFk = null;
|
||||||
const { data } = await axios.get(`Zones/${zoneId}`);
|
const { data } = await axios.get(`Zones/${zoneId}`);
|
||||||
formData.value.agencyModeFk = data.agencyModeFk;
|
formData.value.agencyModeFk = data.agencyModeFk;
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onChangeAddress = async (addressId) => {
|
const onChangeAddress = async (addressId) => {
|
||||||
try {
|
|
||||||
formData.value.nickname = null;
|
formData.value.nickname = null;
|
||||||
const { data } = await axios.get(`Addresses/${addressId}`);
|
const { data } = await axios.get(`Addresses/${addressId}`);
|
||||||
formData.value.nickname = data.nickname;
|
formData.value.nickname = data.nickname;
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getClientDefaultAddress = async (clientId) => {
|
const getClientDefaultAddress = async (clientId) => {
|
||||||
try {
|
|
||||||
const { data } = await axios.get(`Clients/${clientId}`);
|
const { data } = await axios.get(`Clients/${clientId}`);
|
||||||
if (data) addressId.value = data.defaultAddressFk;
|
if (data) addressId.value = data.defaultAddressFk;
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const clientAddressesList = async (value) => {
|
const clientAddressesList = async (value) => {
|
||||||
|
@ -189,18 +154,26 @@ const clientId = computed({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const landed = computed({
|
function addDateParams(obj) {
|
||||||
get: () => formData.value?.landed,
|
return {
|
||||||
set: (val) => {
|
...obj,
|
||||||
formData.value.landed = val;
|
...{
|
||||||
getShipped({
|
|
||||||
landed: val,
|
|
||||||
addressFk: formData.value?.addressFk,
|
addressFk: formData.value?.addressFk,
|
||||||
agencyModeFk: formData.value?.agencyModeFk,
|
agencyModeFk: formData.value?.agencyModeFk,
|
||||||
warehouseFk: formData.value?.warehouseFk,
|
warehouseFk: formData.value?.warehouseFk,
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setLanded(landed) {
|
||||||
|
if (!landed) return;
|
||||||
|
getShipped(addDateParams({ landed }));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setShipped(shipped) {
|
||||||
|
if (!shipped) return;
|
||||||
|
getLanded(addDateParams({ shipped }));
|
||||||
|
}
|
||||||
|
|
||||||
const agencyModeId = computed({
|
const agencyModeId = computed({
|
||||||
get: () => formData.value.agencyModeFk,
|
get: () => formData.value.agencyModeFk,
|
||||||
|
@ -248,21 +221,6 @@ const warehouseId = computed({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const shipped = computed({
|
|
||||||
get: () => formData.value?.shipped,
|
|
||||||
set: (val) => {
|
|
||||||
if (new Date(formData.value?.shipped).toDateString() != val.toDateString())
|
|
||||||
val.setHours(0, 0, 0, 0);
|
|
||||||
formData.value.shipped = val;
|
|
||||||
getLanded({
|
|
||||||
shipped: val,
|
|
||||||
addressFk: formData.value?.addressFk,
|
|
||||||
agencyModeFk: formData.value?.agencyModeFk,
|
|
||||||
warehouseFk: formData.value?.warehouseFk,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const onFormModelInit = () => {
|
const onFormModelInit = () => {
|
||||||
if (formData.value?.clientFk) clientAddressesList(formData.value?.clientFk);
|
if (formData.value?.clientFk) clientAddressesList(formData.value?.clientFk);
|
||||||
};
|
};
|
||||||
|
@ -463,18 +421,21 @@ async function getZone(options) {
|
||||||
v-model="formData.shipped"
|
v-model="formData.shipped"
|
||||||
:required="true"
|
:required="true"
|
||||||
:rules="validate('basicData.shipped')"
|
:rules="validate('basicData.shipped')"
|
||||||
|
@update:model-value="setShipped"
|
||||||
/>
|
/>
|
||||||
<VnInputTime
|
<VnInputTime
|
||||||
:label="t('basicData.shippedHour')"
|
:label="t('basicData.shippedHour')"
|
||||||
v-model="formData.shipped"
|
v-model="formData.shipped"
|
||||||
:required="true"
|
:required="true"
|
||||||
:rules="validate('basicData.shippedHour')"
|
:rules="validate('basicData.shippedHour')"
|
||||||
|
@update:model-value="setShipped"
|
||||||
/>
|
/>
|
||||||
<VnInputDate
|
<VnInputDate
|
||||||
:label="t('basicData.landed')"
|
:label="t('basicData.landed')"
|
||||||
v-model="formData.landed"
|
v-model="formData.landed"
|
||||||
:required="true"
|
:required="true"
|
||||||
:rules="validate('basicData.landed')"
|
:rules="validate('basicData.landed')"
|
||||||
|
@update:model-value="setLanded"
|
||||||
/>
|
/>
|
||||||
</VnRow>
|
</VnRow>
|
||||||
</QForm>
|
</QForm>
|
||||||
|
|
|
@ -70,7 +70,6 @@ const isFormInvalid = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getPriceDifference = async () => {
|
const getPriceDifference = async () => {
|
||||||
try {
|
|
||||||
const params = {
|
const params = {
|
||||||
landed: formData.value.landed,
|
landed: formData.value.landed,
|
||||||
addressId: formData.value.addressFk,
|
addressId: formData.value.addressFk,
|
||||||
|
@ -84,15 +83,10 @@ const getPriceDifference = async () => {
|
||||||
params
|
params
|
||||||
);
|
);
|
||||||
formData.value.sale = data;
|
formData.value.sale = data;
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
try {
|
if (!formData.value.option) return notify(t('basicData.chooseAnOption'), 'negative');
|
||||||
if (!formData.value.option)
|
|
||||||
return notify(t('basicData.chooseAnOption'), 'negative');
|
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
clientFk: formData.value.clientFk,
|
clientFk: formData.value.clientFk,
|
||||||
|
@ -121,9 +115,6 @@ const submit = async () => {
|
||||||
const ticketToMove = data.id;
|
const ticketToMove = data.id;
|
||||||
notify(t('basicData.unroutedTicket'), 'positive');
|
notify(t('basicData.unroutedTicket'), 'positive');
|
||||||
router.push({ name: 'TicketSummary', params: { id: ticketToMove } });
|
router.push({ name: 'TicketSummary', params: { id: ticketToMove } });
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const submitWithNegatives = async () => {
|
const submitWithNegatives = async () => {
|
||||||
|
@ -167,7 +158,7 @@ onBeforeMount(async () => await getTicketData());
|
||||||
<TicketBasicDataForm
|
<TicketBasicDataForm
|
||||||
v-if="initialDataLoaded"
|
v-if="initialDataLoaded"
|
||||||
@update-form="($event) => (formData = $event)"
|
@update-form="($event) => (formData = $event)"
|
||||||
:form-data="formData"
|
v-model="formData"
|
||||||
/>
|
/>
|
||||||
</QStep>
|
</QStep>
|
||||||
<QStep :name="2" :title="t('basicData.priceDifference')">
|
<QStep :name="2" :title="t('basicData.priceDifference')">
|
||||||
|
|
Loading…
Reference in New Issue