From 8a0b65998ea2c437a801eb56a88c72fefaa4d7ab Mon Sep 17 00:00:00 2001 From: robert Date: Tue, 26 Nov 2024 13:41:26 +0100 Subject: [PATCH] feat: refs #6629 customerAddressEdit --- .../components/CustomerAddressEdit.vue | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index 8e464dd7c..b403d1012 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -83,19 +83,27 @@ const deleteNote = (id, index) => { notes.value.splice(index, 1); }; -const updateAddress = async () => { - /* await axios.patch( - `Clients/${route.params.id}/updateAddress/${route.params.addressId}?updateObservations=true` - );*/ - urlUpdate.value = `Clients/${route.params.id}/updateAddress/${route.params.addressId}?updateObservations=true`; +const updateAddress = async (data) => { + await axios.patch(urlUpdate.value, data); +}; + +const updateAddressTicket = async () => { + urlUpdate.value += '?updateObservations=true'; console.log('gg'); }; -const resetAndSend = async (payload) => { + +const updateObservations = async (payload) => { await axios.post('AddressObservations/crud', payload); notes.value = []; deletes.value = []; + toCustomerAddress(); }; +async function updateAll({ data, payload }) { + console.log('Si no hay notas modificadas'); + await updateAddress(data); + await updateObservations(payload); +} function getPayload() { return { creates: notes.value.filter((note) => note.$isNew), @@ -115,16 +123,12 @@ function getPayload() { })), }; } -const onDataSaved = async (payload) => { - await axios.post('AddressObservations/crud', payload); - notes.value = []; - deletes.value = []; - toCustomerAddress(); -}; async function handleDialog(data) { console.error(data); - if (getPayload().updates.length) { + const payload = getPayload(); + const body = { data, payload }; + if (payload.updates.length) { quasar .dialog({ component: VnConfirm, @@ -136,24 +140,30 @@ async function handleDialog(data) { }, }) .onOk(async () => { + console.log('Actualiza notas'); // await resetAndSend(payload); - await updateAddress(); - await onDataSaved(data); + await updateAll(body); + await updateAddressTicket(); + toCustomerAddress(); }) .onCancel(async () => { // await resetAndSend(payload); - await onDataSaved(data); + console.log('Actualiza datos'); + await updateAll(body); + toCustomerAddress(); }); // .hide(toCustomerAddress); } else { - console.log('sinModificarObservation'); - await onDataSaved(data); + updateAll(body); + toCustomerAddress(); // await resetAndSend(payload); // toCustomerAddress(); } } const toCustomerAddress = () => { + notes.value = []; + deletes.value = []; router.push({ name: 'CustomerAddress', params: {