diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index bfb470c48..75f0648c8 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -207,7 +207,9 @@ async function save() { isLoading.value = true; try { formData.value = trimData(formData.value); - const body = $props.mapper ? $props.mapper(formData.value) : formData.value; + const body = $props.mapper + ? $props.mapper(formData.value, originalData.value) + : formData.value; const method = $props.urlCreate ? 'post' : 'patch'; const url = $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; diff --git a/src/pages/Customer/components/CustomerAddressEdit.vue b/src/pages/Customer/components/CustomerAddressEdit.vue index af15962fa..8e464dd7c 100644 --- a/src/pages/Customer/components/CustomerAddressEdit.vue +++ b/src/pages/Customer/components/CustomerAddressEdit.vue @@ -28,7 +28,7 @@ let originalNotes = []; const deletes = ref([]); onBeforeMount(() => { - updateAddress(); + urlUpdate.value = `Clients/${route.params.id}/updateAddress/${route.params.addressId}`; }); const getData = async (observations) => { @@ -83,16 +83,21 @@ const deleteNote = (id, index) => { notes.value.splice(index, 1); }; -const updateAddress = () => { - urlUpdate.value = `Clients/${route.params.id}/updateAddress/${route.params.addressId}`; +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`; + + console.log('gg'); }; const resetAndSend = async (payload) => { await axios.post('AddressObservations/crud', payload); notes.value = []; deletes.value = []; }; -const onDataSaved = async () => { - let payload = { +function getPayload() { + return { creates: notes.value.filter((note) => note.$isNew), deletes: deletes.value, updates: notes.value @@ -109,7 +114,17 @@ const onDataSaved = async () => { where: { id: note.id }, })), }; - if (payload.updates.length) { +} +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) { quasar .dialog({ component: VnConfirm, @@ -121,19 +136,22 @@ const onDataSaved = async () => { }, }) .onOk(async () => { - resetAndSend(payload); - updateAddress(payload); - toCustomerAddress(); + // await resetAndSend(payload); + await updateAddress(); + await onDataSaved(data); }) .onCancel(async () => { - resetAndSend(payload); - toCustomerAddress(); + // await resetAndSend(payload); + await onDataSaved(data); }); // .hide(toCustomerAddress); } else { - resetAndSend(payload); + console.log('sinModificarObservation'); + await onDataSaved(data); + // await resetAndSend(payload); + // toCustomerAddress(); } -}; +} const toCustomerAddress = () => { router.push({ @@ -170,7 +188,7 @@ function handleLocation(data, location) { :observe-form-changes="false" :url-update="urlUpdate" :url="`Addresses/${route.params.addressId}`" - @on-data-saved="onDataSaved" + :save-fn="handleDialog" auto-load model="client" >