fix(TicketBasicData): getShipped, getLanded & bad try catch
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Alex Moreno 2024-11-18 09:18:06 +01:00
parent 6de5864dd6
commit e230cc61a0
2 changed files with 88 additions and 136 deletions

View File

@ -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;
formData.value.zoneFk = null; async function getShipped(params) {
zonesOptions.value = []; getDate(`Agencies/getShipped`, params);
const { data } = await axios.get(`Agencies/getLanded`, { params }); }
if (data) {
formData.value.zoneFk = data.zoneFk; async function getDate(query, params) {
formData.value.landed = data.landed; for (const param in params) {
formData.value.shipped = params.shipped; if (!params[param]) return;
}
} catch (error) {
console.error(error);
notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
} }
};
const getShipped = async (params) => { formData.value.zoneFk = null;
try { zonesOptions.value = [];
const validParams = const { data } = await axios.get(query, { params });
landed.value && addressId.value && agencyModeId.value && warehouseId.value; if (!data) return notify(t('basicData.noDeliveryZoneAvailable'), 'negative');
if (!validParams) return;
formData.value.zoneFk = null; formData.value.zoneFk = data.zoneFk;
zonesOptions.value = []; if (data.landed) formData.value.landed = data.landed;
const { data } = await axios.get(`Agencies/getShipped`, { params }); if (data.shipped) formData.value.shipped = data.shipped;
if (data) { }
formData.value.zoneFk = data.zoneFk;
formData.value.landed = params.landed;
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>

View File

@ -70,60 +70,51 @@ 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, agencyModeId: formData.value.agencyModeFk,
agencyModeId: formData.value.agencyModeFk, zoneId: formData.value.zoneFk,
zoneId: formData.value.zoneFk, warehouseId: formData.value.warehouseFk,
warehouseId: formData.value.warehouseFk, shipped: formData.value.shipped,
shipped: formData.value.shipped, };
}; const { data } = await axios.post(
const { data } = await axios.post( `tickets/${formData.value.id}/priceDifference`,
`tickets/${formData.value.id}/priceDifference`, 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,
nickname: formData.value.nickname, nickname: formData.value.nickname,
agencyModeFk: formData.value.agencyModeFk, agencyModeFk: formData.value.agencyModeFk,
addressFk: formData.value.addressFk, addressFk: formData.value.addressFk,
zoneFk: formData.value.zoneFk, zoneFk: formData.value.zoneFk,
warehouseFk: formData.value.warehouseFk, warehouseFk: formData.value.warehouseFk,
companyFk: formData.value.companyFk, companyFk: formData.value.companyFk,
shipped: formData.value.shipped, shipped: formData.value.shipped,
landed: formData.value.landed, landed: formData.value.landed,
isDeleted: formData.value.isDeleted, isDeleted: formData.value.isDeleted,
option: formData.value.option, option: formData.value.option,
isWithoutNegatives: formData.value.withoutNegatives, isWithoutNegatives: formData.value.withoutNegatives,
withWarningAccept: formData.value.withWarningAccept, withWarningAccept: formData.value.withWarningAccept,
keepPrice: false, keepPrice: false,
}; };
const { data } = await axios.post( const { data } = await axios.post(
`tickets/${formData.value.id}/componentUpdate`, `tickets/${formData.value.id}/componentUpdate`,
params params
); );
if (!data) return; if (!data) return;
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')">