forked from verdnatura/salix-front
refs #7391 fix url, fix filters
This commit is contained in:
parent
f414b8aa0e
commit
e464608a9f
|
@ -116,7 +116,9 @@ async function fetchFilter(val) {
|
||||||
if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value;
|
if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value;
|
||||||
|
|
||||||
const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where };
|
const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where };
|
||||||
return dataRef.value.fetch({ fields, where, order: sortBy, limit });
|
const fetchOptions = { where, order: sortBy, limit };
|
||||||
|
if (fields) fetchOptions.fields = fields;
|
||||||
|
return dataRef.value.fetch(fetchOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function filterHandler(val, update) {
|
async function filterHandler(val, update) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ const balanceDueTotal = ref(0);
|
||||||
const selected = ref([]);
|
const selected = ref([]);
|
||||||
|
|
||||||
const tableColumnComponents = {
|
const tableColumnComponents = {
|
||||||
client: {
|
clientFk: {
|
||||||
component: QBtn,
|
component: QBtn,
|
||||||
props: () => ({ flat: true, class: 'link', noCaps: true }),
|
props: () => ({ flat: true, class: 'link', noCaps: true }),
|
||||||
event: () => {},
|
event: () => {},
|
||||||
|
@ -43,7 +43,7 @@ const tableColumnComponents = {
|
||||||
props: () => ({ flat: true, class: 'link', noCaps: true }),
|
props: () => ({ flat: true, class: 'link', noCaps: true }),
|
||||||
event: () => {},
|
event: () => {},
|
||||||
},
|
},
|
||||||
department: {
|
departmentName: {
|
||||||
component: 'span',
|
component: 'span',
|
||||||
props: () => {},
|
props: () => {},
|
||||||
event: () => {},
|
event: () => {},
|
||||||
|
@ -105,12 +105,12 @@ const columns = computed(() => [
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: 'clientName',
|
field: 'clientName',
|
||||||
label: t('Client'),
|
label: t('Client'),
|
||||||
name: 'client',
|
name: 'clientFk',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: 'isWorker',
|
field: ({ isWorker }) => Boolean(isWorker),
|
||||||
label: t('Is worker'),
|
label: t('Is worker'),
|
||||||
name: 'isWorker',
|
name: 'isWorker',
|
||||||
},
|
},
|
||||||
|
@ -125,7 +125,7 @@ const columns = computed(() => [
|
||||||
align: 'left',
|
align: 'left',
|
||||||
field: 'departmentName',
|
field: 'departmentName',
|
||||||
label: t('Department'),
|
label: t('Department'),
|
||||||
name: 'department',
|
name: 'departmentName',
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -207,48 +207,24 @@ const viewAddObservation = (rowsSelected) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const departments = ref(new Map());
|
|
||||||
|
|
||||||
const onFetch = async (data) => {
|
const onFetch = async (data) => {
|
||||||
const salesPersonFks = data.map((item) => item.salesPersonFk);
|
|
||||||
const departmentNames = salesPersonFks.map(async (salesPersonFk) => {
|
|
||||||
try {
|
|
||||||
const { data: workerDepartment } = await axios.get(
|
|
||||||
`WorkerDepartments/${salesPersonFk}`
|
|
||||||
);
|
|
||||||
const { data: department } = await axios.get(
|
|
||||||
`Departments/${workerDepartment.departmentFk}`
|
|
||||||
);
|
|
||||||
departments.value.set(salesPersonFk, department.name);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Err: ', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
const recoveryData = await axios.get('Recoveries');
|
const recoveryData = await axios.get('Recoveries');
|
||||||
|
|
||||||
const recoveries = recoveryData.data.map(({ clientFk, finished }) => ({
|
const recoveries = recoveryData.data.map(({ clientFk, finished }) => ({
|
||||||
clientFk,
|
clientFk,
|
||||||
finished,
|
finished,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await Promise.all(departmentNames);
|
|
||||||
|
|
||||||
data.forEach((item) => {
|
data.forEach((item) => {
|
||||||
item.departmentName = departments.value.get(item.salesPersonFk);
|
|
||||||
item.isWorker = item.businessTypeFk === 'worker';
|
|
||||||
const recovery = recoveries.find(({ clientFk }) => clientFk === item.clientFk);
|
const recovery = recoveries.find(({ clientFk }) => clientFk === item.clientFk);
|
||||||
item.finished = recovery?.finished === null;
|
item.finished = recovery?.finished === null;
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const element of data) element.isWorker = element.businessTypeFk === 'worker';
|
|
||||||
|
|
||||||
balanceDueTotal.value = data.reduce((acc, { amount = 0 }) => acc + amount, 0);
|
balanceDueTotal.value = data.reduce((acc, { amount = 0 }) => acc + amount, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
function exprBuilder(param, value) {
|
function exprBuilder(param, value) {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'clientFk':
|
case 'clientFk':
|
||||||
return { [`d.${param}`]: value?.id };
|
return { [`d.${param}`]: value };
|
||||||
case 'creditInsurance':
|
case 'creditInsurance':
|
||||||
case 'amount':
|
case 'amount':
|
||||||
case 'workerFk':
|
case 'workerFk':
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
||||||
import VnInput from 'src/components/common/VnInput.vue';
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
@ -16,7 +15,6 @@ const props = defineProps({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const clients = ref();
|
|
||||||
const salespersons = ref();
|
const salespersons = ref();
|
||||||
const countries = ref();
|
const countries = ref();
|
||||||
const authors = ref();
|
const authors = ref();
|
||||||
|
@ -24,7 +22,6 @@ const departments = ref();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData @on-fetch="(data) => (clients = data)" auto-load url="Clients" />
|
|
||||||
<FetchData
|
<FetchData
|
||||||
:filter="{ where: { role: 'salesPerson' } }"
|
:filter="{ where: { role: 'salesPerson' } }"
|
||||||
@on-fetch="(data) => (salespersons = data)"
|
@on-fetch="(data) => (salespersons = data)"
|
||||||
|
@ -49,29 +46,22 @@ const departments = ref();
|
||||||
|
|
||||||
<template #body="{ params, searchFn }">
|
<template #body="{ params, searchFn }">
|
||||||
<QItem class="q-mb-sm">
|
<QItem class="q-mb-sm">
|
||||||
<QItemSection v-if="clients">
|
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:label="t('Client')"
|
:label="t('Client')"
|
||||||
:options="clients"
|
url="Clients"
|
||||||
dense
|
dense
|
||||||
emit-value
|
|
||||||
hide-selected
|
|
||||||
map-options
|
|
||||||
option-label="name"
|
option-label="name"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
outlined
|
outlined
|
||||||
rounded
|
rounded
|
||||||
use-input
|
emit-value
|
||||||
|
hide-selected
|
||||||
|
map-options
|
||||||
v-model="params.clientFk"
|
v-model="params.clientFk"
|
||||||
|
use-input
|
||||||
@update:model-value="searchFn()"
|
@update:model-value="searchFn()"
|
||||||
auto-load
|
|
||||||
/>
|
/>
|
||||||
</QItemSection>
|
|
||||||
<QItemSection v-else>
|
|
||||||
<QSkeleton class="full-width" type="QInput" />
|
|
||||||
</QItemSection>
|
|
||||||
</QItem>
|
</QItem>
|
||||||
|
|
||||||
<QItem class="q-mb-sm">
|
<QItem class="q-mb-sm">
|
||||||
<QItemSection v-if="salespersons">
|
<QItemSection v-if="salespersons">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
|
@ -95,7 +85,6 @@ const departments = ref();
|
||||||
<QSkeleton class="full-width" type="QInput" />
|
<QSkeleton class="full-width" type="QInput" />
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
|
|
||||||
<QItem class="q-mb-sm">
|
<QItem class="q-mb-sm">
|
||||||
<QItemSection v-if="departments">
|
<QItemSection v-if="departments">
|
||||||
<VnSelect
|
<VnSelect
|
||||||
|
|
Loading…
Reference in New Issue