refactor: refs #8217 eliminate unnecessary onBeforeSave function
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
This commit is contained in:
parent
4599686f77
commit
dae5fb5241
|
@ -1,16 +1,26 @@
|
|||
export default function getDifferences(initialData, formData) {
|
||||
const differences = {};
|
||||
if (initialData) delete initialData.$index;
|
||||
if (formData) delete formData.$index;
|
||||
const diff = {};
|
||||
if (!initialData) return diff;
|
||||
if (!formData) return initialData;
|
||||
delete initialData.$index;
|
||||
delete formData.$index;
|
||||
|
||||
for (const key in initialData) {
|
||||
if (
|
||||
formData[key] &&
|
||||
JSON.stringify(initialData[key]) !== JSON.stringify(formData[key])
|
||||
) {
|
||||
diff[key] = formData[key];
|
||||
}
|
||||
}
|
||||
for (const key in formData) {
|
||||
if (formData.hasOwnProperty(key)) {
|
||||
if (!initialData.hasOwnProperty(key) || formData[key] !== initialData[key]) {
|
||||
if (initialData) {
|
||||
differences[key] = formData[key];
|
||||
}
|
||||
}
|
||||
if (
|
||||
initialData[key] === undefined ||
|
||||
JSON.stringify(initialData[key]) !== JSON.stringify(formData[key])
|
||||
) {
|
||||
diff[key] = formData[key];
|
||||
}
|
||||
}
|
||||
|
||||
return differences;
|
||||
return diff;
|
||||
}
|
||||
|
|
|
@ -15,13 +15,6 @@ import VnAvatar from 'src/components/ui/VnAvatar.vue';
|
|||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
const workersOptions = ref([]);
|
||||
|
||||
function onBeforeSave(formData, originalData) {
|
||||
return getUpdatedValues(
|
||||
Object.keys(getDifferences(formData, originalData)),
|
||||
formData,
|
||||
);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
|
@ -34,7 +27,6 @@ function onBeforeSave(formData, originalData) {
|
|||
<FormModel
|
||||
model="Claim"
|
||||
:url-update="`Claims/updateClaim/${route.params.id}`"
|
||||
:mapper="onBeforeSave"
|
||||
auto-load
|
||||
>
|
||||
<template #form="{ data, validate }">
|
||||
|
|
|
@ -8,37 +8,12 @@ import FormModel from 'components/FormModel.vue';
|
|||
import VnRow from 'components/ui/VnRow.vue';
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import { getDifferences, getUpdatedValues } from 'src/filters';
|
||||
|
||||
const route = useRoute();
|
||||
const { t } = useI18n();
|
||||
|
||||
const businessTypes = ref([]);
|
||||
const contactChannels = ref([]);
|
||||
const handleSalesModelValue = (val) => {
|
||||
if (!val) val = '';
|
||||
return {
|
||||
or: [
|
||||
{ id: val },
|
||||
{ name: val },
|
||||
{ nickname: { like: '%' + val + '%' } },
|
||||
{ code: { like: `${val}%` } },
|
||||
],
|
||||
};
|
||||
};
|
||||
|
||||
const exprBuilder = (param, value) => {
|
||||
return {
|
||||
and: [{ active: { neq: false } }, handleSalesModelValue(value)],
|
||||
};
|
||||
};
|
||||
|
||||
function onBeforeSave(formData, originalData) {
|
||||
return getUpdatedValues(
|
||||
Object.keys(getDifferences(formData, originalData)),
|
||||
formData,
|
||||
);
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
|
@ -52,12 +27,7 @@ function onBeforeSave(formData, originalData) {
|
|||
@on-fetch="(data) => (businessTypes = data)"
|
||||
auto-load
|
||||
/>
|
||||
<FormModel
|
||||
:url-update="`Clients/${route.params.id}`"
|
||||
auto-load
|
||||
:mapper="onBeforeSave"
|
||||
model="Customer"
|
||||
>
|
||||
<FormModel :url-update="`Clients/${route.params.id}`" auto-load model="Customer">
|
||||
<template #form="{ data, validate }">
|
||||
<VnRow>
|
||||
<VnInput
|
||||
|
|
|
@ -13,7 +13,6 @@ import VnInput from 'src/components/common/VnInput.vue';
|
|||
import VnSelect from 'src/components/common/VnSelect.vue';
|
||||
import VnLocation from 'src/components/common/VnLocation.vue';
|
||||
import VnCheckbox from 'src/components/common/VnCheckbox.vue';
|
||||
import { getDifferences, getUpdatedValues } from 'src/filters';
|
||||
import VnConfirm from 'src/components/ui/VnConfirm.vue';
|
||||
|
||||
const quasar = useQuasar();
|
||||
|
@ -31,12 +30,6 @@ function handleLocation(data, location) {
|
|||
data.provinceFk = provinceFk;
|
||||
data.countryFk = countryFk;
|
||||
}
|
||||
function onBeforeSave(formData, originalData) {
|
||||
return getUpdatedValues(
|
||||
Object.keys(getDifferences(formData, originalData)),
|
||||
formData,
|
||||
);
|
||||
}
|
||||
|
||||
async function checkEtChanges(data, _, originalData) {
|
||||
const equalizatedHasChanged = originalData.isEqualizated != data.isEqualizated;
|
||||
|
@ -75,7 +68,6 @@ async function acceptPropagate({ isEqualizated }) {
|
|||
:url-update="`Clients/${route.params.id}/updateFiscalData`"
|
||||
auto-load
|
||||
model="Customer"
|
||||
:mapper="onBeforeSave"
|
||||
observe-form-changes
|
||||
@on-data-saved="checkEtChanges"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue