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;
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;

View File

@ -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"
>