perf: remove almost fonseca code

This commit is contained in:
Javier Segarra 2024-11-23 00:33:30 +01:00
parent 12dcb51fbe
commit 276dc233c1
10 changed files with 121 additions and 263 deletions

View File

@ -2,6 +2,7 @@
import { onBeforeMount, ref, watch } from 'vue'; import { onBeforeMount, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import axios from 'axios'; import axios from 'axios';
@ -52,7 +53,7 @@ const addressFilter = {
onBeforeMount(() => { onBeforeMount(() => {
const { id } = route.params; const { id } = route.params;
getAddressesData(id); // getAddressesData(id);
getClientData(id); getClientData(id);
}); });
@ -60,22 +61,14 @@ watch(
() => route.params.id, () => route.params.id,
(newValue) => { (newValue) => {
if (!newValue) return; if (!newValue) return;
getAddressesData(newValue); // getAddressesData(newValue);
getClientData(newValue); getClientData(newValue);
} }
); );
async function onFetch(data) {
const getAddressesData = async (id) => {
try {
const { data } = await axios.get(`Clients/${id}/addresses`, {
params: { filter: JSON.stringify(addressFilter) },
});
addresses.value = data; addresses.value = data;
sortAddresses(); sortAddresses();
} catch (error) { }
return error;
}
};
const getClientData = async (id) => { const getClientData = async (id) => {
try { try {
@ -125,7 +118,16 @@ const toCustomerAddressEdit = (addressId) => {
<template> <template>
<div class="full-width flex justify-center"> <div class="full-width flex justify-center">
<QCard class="card-width q-pa-lg" v-if="addresses.length"> <QCard class="card-width q-pa-lg">
<VnPaginate
@on-fetch="onFetch"
auto-load
data-key="CustomerAddresses"
order="id DESC"
ref="vnPaginateRef"
:filter="addressFilter"
:url="`Clients/${route.params.id}/addresses`"
></VnPaginate>
<QCardSection> <QCardSection>
<div <div
v-for="(item, index) in addresses" v-for="(item, index) in addresses"

View File

@ -51,12 +51,7 @@ function onBeforeSave(formData, originalData) {
@on-fetch="(data) => (businessTypes = data)" @on-fetch="(data) => (businessTypes = data)"
auto-load auto-load
/> />
<FormModel <FormModel auto-load model="customer" :mapper="onBeforeSave">
:url="`Clients/${route.params.id}`"
auto-load
model="customer"
:mapper="onBeforeSave"
>
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<VnRow> <VnRow>
<VnInput <VnInput

View File

@ -28,12 +28,7 @@ const getBankEntities = (data, formData) => {
</script> </script>
<template> <template>
<FormModel <FormModel :url-update="`Clients/${route.params.id}`" auto-load model="customer">
:url-update="`Clients/${route.params.id}`"
:url="`Clients/${route.params.id}/getCard`"
auto-load
model="customer"
>
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<VnRow> <VnRow>
<VnSelect <VnSelect

View File

@ -93,22 +93,6 @@ const columns = computed(() => [
<WorkerDescriptorProxy :id="row.worker.id" /> <WorkerDescriptorProxy :id="row.worker.id" />
</template> </template>
</VnTable> </VnTable>
<!-- <QTable
:columns="columns"
:pagination="{ rowsPerPage: 0 }"
:rows="rows"
hide-bottom
row-key="id"
v-model:selected="selected"
class="card-width q-px-lg"
>
<template #body-cell-employee="{ row }">
<QTd @click.stop>
<span class="link">{{ row.worker.user.nickname }}</span>
<WorkerDescriptorProxy :id="row.clientFk" />
</QTd>
</template>
</QTable> -->
</template> </template>
<i18n> <i18n>

View File

@ -34,7 +34,6 @@ function handleLocation(data, location) {
/> />
<FormModel <FormModel
:url-update="`Clients/${route.params.id}/updateFiscalData`" :url-update="`Clients/${route.params.id}/updateFiscalData`"
:url="`Clients/${route.params.id}/getCard`"
auto-load auto-load
model="customer" model="customer"
> >

View File

@ -1,165 +1,79 @@
<script setup> <script setup>
import { computed, onBeforeMount, ref, watch, nextTick } from 'vue'; import { ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import VnInputDate from 'components/common/VnInputDate.vue'; import VnInputDate from 'components/common/VnInputDate.vue';
import VnInput from 'src/components/common/VnInput.vue'; import FormModel from 'components/FormModel.vue';
import FetchData from 'components/FetchData.vue';
import axios from 'axios'; import VnInputNumber from 'src/components/common/VnInputNumber.vue';
import useNotify from 'src/composables/useNotify'; const formModelRef = ref(false);
import { useStateStore } from 'stores/useStateStore';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const { notify } = useNotify();
const stateStore = useStateStore();
const amountInputRef = ref(null); const amountInputRef = ref(null);
const initialDated = Date.vnNew();
const unpaidClient = ref(false);
const isLoading = ref(false);
const amount = ref(null);
const dated = ref(initialDated);
const initialData = ref({ const initialData = ref({
dated: initialDated, dated: Date.vnNew(),
amount: null,
}); });
const hasChanged = computed(() => { const filterClientFindOne = {
return ( fields: ['unpaid', 'dated', 'amount'],
initialData.value.dated !== dated.value || where: {
initialData.value.amount !== amount.value
);
});
onBeforeMount(() => {
getData(route.params.id);
});
watch(
() => route.params.id,
(newValue) => {
if (!newValue) return;
getData(newValue);
}
);
const getData = async (id) => {
const filter = { where: { clientFk: id } };
try {
const { data } = await axios.get('ClientUnpaids', {
params: { filter: JSON.stringify(filter) },
});
if (data.length) {
setValues(data[0]);
} else {
defaultValues();
}
} catch (error) {
defaultValues();
}
};
const setValues = (data) => {
unpaidClient.value = true;
amount.value = data.amount;
dated.value = data.dated;
initialData.value = data;
};
const defaultValues = () => {
unpaidClient.value = false;
initialData.value.amount = null;
setInitialData();
};
const setInitialData = () => {
amount.value = initialData.value.amount;
dated.value = initialData.value.dated;
};
const onSubmit = async () => {
isLoading.value = true;
const payload = {
amount: amount.value,
clientFk: route.params.id, clientFk: route.params.id,
dated: dated.value, },
};
try {
await axios.patch('ClientUnpaids', payload);
notify('globals.dataSaved', 'positive');
unpaidClient.value = true;
} catch (error) {
notify('errors.writeRequest', 'negative');
} finally {
isLoading.value = false;
}
}; };
watch(
() => unpaidClient.value,
async (val) => {
await nextTick();
if (val) amountInputRef.value.focus();
}
);
</script> </script>
<template> <template>
<Teleport v-if="stateStore?.isSubToolbarShown()" to="#st-actions"> <FetchData
<QBtnGroup push class="q-gutter-x-sm"> :filter="filterClientFindOne"
<QBtn auto-load
:disabled="!hasChanged" url="ClientUnpaids"
:label="t('globals.reset')" @on-fetch="
:loading="isLoading" (data) => {
@click="setInitialData" const unpaid = data.length == 1;
color="primary" initialData = { ...data[0], unpaid };
flat }
icon="restart_alt" "
type="reset"
/> />
<QBtn <QCard>
:disabled="!hasChanged" <FormModel
:label="t('globals.save')" v-if="'unpaid' in initialData"
:loading="isLoading" :observe-form-changes="false"
@click="onSubmit" ref="formModelRef"
color="primary" model="unpaid"
icon="save" url-update="ClientUnpaids"
/> :mapper="(formData) => ({ ...formData, clientFk: route.params.id })"
</QBtnGroup> :form-initial-data="initialData"
</Teleport> >
<template #form="{ data }">
<div class="full-width flex justify-center"> {{ data }}
<QCard class="card-width q-pa-lg">
<QForm>
<VnRow> <VnRow>
<div class="col"> <QCheckbox :label="t('Unpaid client')" v-model="data.unpaid" />
<QCheckbox :label="t('Unpaid client')" v-model="unpaidClient" />
</div>
</VnRow> </VnRow>
<VnRow class="row q-gutter-md q-mb-md" v-show="unpaidClient"> <VnRow class="row q-gutter-md q-mb-md" v-show="data.unpaid">
<div class="col"> <div class="col">
<VnInputDate :label="t('Date')" v-model="dated" /> <VnInputDate :label="t('Date')" v-model="data.dated" />
</div> </div>
<div class="col"> <div class="col">
<VnInput <VnInputNumber
ref="amountInputRef" ref="amountInputRef"
:label="t('Amount')" :label="t('Amount')"
clearable clearable
type="number" v-model="data.amount"
v-model="amount"
autofocus autofocus
> >
<template #append></template></VnInput <template #append></template></VnInputNumber
> >
</div> </div>
</VnRow> </VnRow>
</QForm> </template>
</FormModel>
</QCard> </QCard>
</div> <!-- </div> -->
</template> </template>
<i18n> <i18n>

View File

@ -25,10 +25,9 @@ async function hasCustomerRole() {
</script> </script>
<template> <template>
<FormModel <FormModel
url="VnUsers/preview"
:url-update="`Clients/${route.params.id}/updateUser`" :url-update="`Clients/${route.params.id}/updateUser`"
:filter="filter" :filter="filter"
model="webAccess" model="customer"
:mapper=" :mapper="
({ active, name, email }) => { ({ active, name, email }) => {
return { return {
@ -42,7 +41,7 @@ async function hasCustomerRole() {
auto-load auto-load
> >
<template #form="{ data, validate }"> <template #form="{ data, validate }">
<QCheckbox :label="t('Enable web access')" v-model="data.active" /> <QCheckbox :label="t('Enable web access')" v-model="data.account.active" />
<VnInput :label="t('User')" clearable v-model="data.name" /> <VnInput :label="t('User')" clearable v-model="data.name" />
<VnInput <VnInput
:label="t('Recovery email')" :label="t('Recovery email')"

View File

@ -1,14 +1,14 @@
<script setup> <script setup>
import { computed, onBeforeMount, ref, watch } from 'vue'; import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import axios from 'axios'; import FetchData from 'src/components/FetchData.vue';
import { toCurrency, toDateHourMin } from 'src/filters'; import { toCurrency, toDateHourMin } from 'src/filters';
import CustomerCloseIconTooltip from '../components/CustomerCloseIconTooltip.vue'; import CustomerCloseIconTooltip from 'src/components/CustomerCloseIconTooltip.vue';
import CustomerCheckIconTooltip from '../components/CustomerCheckIconTooltip.vue'; import CustomerCheckIconTooltip from 'src/components/CustomerCheckIconTooltip.vue';
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
@ -20,10 +20,11 @@ const filter = {
{ relation: 'mandateType', scope: { fields: ['id', 'name'] } }, { relation: 'mandateType', scope: { fields: ['id', 'name'] } },
{ relation: 'company', scope: { fields: ['id', 'code'] } }, { relation: 'company', scope: { fields: ['id', 'code'] } },
], ],
where: { clientFk: null }, where: { clientFk: route.params.id },
order: ['created DESC'], order: ['created DESC'],
limit: 20, limit: 20,
}; };
const ClientDmsRef = ref(false);
const tableColumnComponents = { const tableColumnComponents = {
state: { state: {
@ -50,7 +51,7 @@ const tableColumnComponents = {
component: CustomerCheckIconTooltip, component: CustomerCheckIconTooltip,
props: ({ row }) => ({ props: ({ row }) => ({
transaction: row, transaction: row,
promise: refreshData, promise: () => ClientDmsRef.value.fetch(),
}), }),
event: () => {}, event: () => {},
}, },
@ -89,38 +90,16 @@ const columns = computed(() => [
name: 'validate', name: 'validate',
}, },
]); ]);
onBeforeMount(() => {
getData(route.params.id);
});
watch(
() => route.params.id,
(newValue) => {
if (!newValue) return;
getData(newValue);
}
);
const getData = async (id) => {
filter.where.clientFk = id;
try {
const { data } = await axios.get('clients/transactions', {
params: { filter: JSON.stringify(filter) },
});
rows.value = data;
} catch (error) {
return error;
}
};
const refreshData = () => {
getData(route.params.id);
};
</script> </script>
<template> <template>
<div class="full-width flex justify-center"> <FetchData
ref="ClientDmsRef"
:filter="filter"
@on-fetch="(data) => (rows = data)"
auto-load
url="Clients/transactions"
/>
<QPage class="card-width q-pa-lg"> <QPage class="card-width q-pa-lg">
<QTable <QTable
:columns="columns" :columns="columns"
@ -135,13 +114,9 @@ const refreshData = () => {
<QTr :props="props"> <QTr :props="props">
<component <component
:is="tableColumnComponents[props.col.name].component" :is="tableColumnComponents[props.col.name].component"
@click=" @click="tableColumnComponents[props.col.name].event(props)"
tableColumnComponents[props.col.name].event(props)
"
class="rounded-borders q-pa-sm" class="rounded-borders q-pa-sm"
v-bind=" v-bind="tableColumnComponents[props.col.name].props(props)"
tableColumnComponents[props.col.name].props(props)
"
> >
{{ props.value }} {{ props.value }}
</component> </component>
@ -154,7 +129,6 @@ const refreshData = () => {
{{ t('globals.noResults') }} {{ t('globals.noResults') }}
</h5> </h5>
</QPage> </QPage>
</div>
</template> </template>
<i18n> <i18n>

View File

@ -1,9 +1,8 @@
<script setup> <script setup>
import { onBeforeMount, reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
import VnLocation from 'src/components/common/VnLocation.vue'; import VnLocation from 'src/components/common/VnLocation.vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import FormModel from 'components/FormModel.vue'; import FormModel from 'components/FormModel.vue';
@ -25,20 +24,6 @@ const agencyModes = ref([]);
const incoterms = ref([]); const incoterms = ref([]);
const customsAgents = ref([]); const customsAgents = ref([]);
onBeforeMount(() => {
urlCreate.value = `Clients/${route.params.id}/createAddress`;
getCustomsAgents();
});
const getCustomsAgents = async () => {
const { data } = await axios.get('CustomsAgents');
customsAgents.value = data;
};
const refreshData = () => {
getCustomsAgents();
};
const toCustomerAddress = () => { const toCustomerAddress = () => {
router.push({ router.push({
name: 'CustomerAddress', name: 'CustomerAddress',
@ -54,6 +39,11 @@ function handleLocation(data, location) {
data.provinceFk = provinceFk; data.provinceFk = provinceFk;
data.countryFk = countryFk; data.countryFk = countryFk;
} }
function onAgentCreated(requestResponse, data) {
customsAgents.value.push(requestResponse);
data.customsAgentFk = requestResponse.id;
}
</script> </script>
<template> <template>
@ -128,6 +118,7 @@ function handleLocation(data, location) {
/> />
<VnSelectDialog <VnSelectDialog
url="CustomsAgents"
:label="t('Customs agent')" :label="t('Customs agent')"
:options="customsAgents" :options="customsAgents"
hide-selected hide-selected
@ -137,7 +128,12 @@ function handleLocation(data, location) {
:tooltip="t('Create a new expense')" :tooltip="t('Create a new expense')"
> >
<template #form> <template #form>
<CustomerNewCustomsAgent @on-data-saved="refreshData()" /> <CustomerNewCustomsAgent
@on-data-saved="
(_, requestResponse) =>
onAgentCreated(requestResponse, data)
"
/>
</template> </template>
</VnSelectDialog> </VnSelectDialog>
</VnRow> </VnRow>

View File

@ -144,7 +144,7 @@ function handleLocation(data, location) {
:url="`Addresses/${route.params.addressId}`" :url="`Addresses/${route.params.addressId}`"
@on-data-saved="onDataSaved()" @on-data-saved="onDataSaved()"
auto-load auto-load
model="client" model="customer"
> >
<template #moreActions> <template #moreActions>
<QBtn <QBtn