feat: refs #6629 update

This commit is contained in:
Robert Ferrús 2024-11-26 13:06:41 +01:00
parent 00b15c1129
commit b07286d43d
2 changed files with 35 additions and 15 deletions

View File

@ -207,7 +207,9 @@ async function save() {
isLoading.value = true; isLoading.value = true;
try { try {
formData.value = trimData(formData.value); 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 method = $props.urlCreate ? 'post' : 'patch';
const url = const url =
$props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url;

View File

@ -28,7 +28,7 @@ let originalNotes = [];
const deletes = ref([]); const deletes = ref([]);
onBeforeMount(() => { onBeforeMount(() => {
updateAddress(); urlUpdate.value = `Clients/${route.params.id}/updateAddress/${route.params.addressId}`;
}); });
const getData = async (observations) => { const getData = async (observations) => {
@ -83,16 +83,21 @@ const deleteNote = (id, index) => {
notes.value.splice(index, 1); notes.value.splice(index, 1);
}; };
const updateAddress = () => { const updateAddress = async () => {
urlUpdate.value = `Clients/${route.params.id}/updateAddress/${route.params.addressId}`; /* 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) => { const resetAndSend = async (payload) => {
await axios.post('AddressObservations/crud', payload); await axios.post('AddressObservations/crud', payload);
notes.value = []; notes.value = [];
deletes.value = []; deletes.value = [];
}; };
const onDataSaved = async () => { function getPayload() {
let payload = { return {
creates: notes.value.filter((note) => note.$isNew), creates: notes.value.filter((note) => note.$isNew),
deletes: deletes.value, deletes: deletes.value,
updates: notes.value updates: notes.value
@ -109,7 +114,17 @@ const onDataSaved = async () => {
where: { id: note.id }, 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 quasar
.dialog({ .dialog({
component: VnConfirm, component: VnConfirm,
@ -121,19 +136,22 @@ const onDataSaved = async () => {
}, },
}) })
.onOk(async () => { .onOk(async () => {
resetAndSend(payload); // await resetAndSend(payload);
updateAddress(payload); await updateAddress();
toCustomerAddress(); await onDataSaved(data);
}) })
.onCancel(async () => { .onCancel(async () => {
resetAndSend(payload); // await resetAndSend(payload);
toCustomerAddress(); await onDataSaved(data);
}); });
// .hide(toCustomerAddress); // .hide(toCustomerAddress);
} else { } else {
resetAndSend(payload); console.log('sinModificarObservation');
await onDataSaved(data);
// await resetAndSend(payload);
// toCustomerAddress();
} }
}; }
const toCustomerAddress = () => { const toCustomerAddress = () => {
router.push({ router.push({
@ -170,7 +188,7 @@ function handleLocation(data, location) {
:observe-form-changes="false" :observe-form-changes="false"
:url-update="urlUpdate" :url-update="urlUpdate"
:url="`Addresses/${route.params.addressId}`" :url="`Addresses/${route.params.addressId}`"
@on-data-saved="onDataSaved" :save-fn="handleDialog"
auto-load auto-load
model="client" model="client"
> >