forked from verdnatura/salix-front
fix: refs #7353 salesorderTable
This commit is contained in:
parent
1cca504c87
commit
bd9aea767a
|
@ -1,11 +1,8 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
|
||||||
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
|
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
|
||||||
import CustomerDescriptorProxy from 'src/pages/Customer/Card/CustomerDescriptorProxy.vue';
|
import CustomerDescriptorProxy from 'src/pages/Customer/Card/CustomerDescriptorProxy.vue';
|
||||||
import VnSubToolbar from 'src/components/ui/VnSubToolbar.vue';
|
|
||||||
import VnTable from 'components/VnTable/VnTable.vue';
|
import VnTable from 'components/VnTable/VnTable.vue';
|
||||||
|
|
||||||
import { toDateFormat, toDateTimeFormat } from 'src/filters/date.js';
|
import { toDateFormat, toDateTimeFormat } from 'src/filters/date.js';
|
||||||
|
@ -16,32 +13,15 @@ import axios from 'axios';
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const { openConfirmationModal } = useVnConfirm();
|
const { openConfirmationModal } = useVnConfirm();
|
||||||
|
|
||||||
const paginateRef = ref(null);
|
const table = ref();
|
||||||
const workersActiveOptions = ref([]);
|
|
||||||
const clientsOptions = ref([]);
|
|
||||||
const selectedRows = ref([]);
|
const selectedRows = ref([]);
|
||||||
|
|
||||||
const dateRange = (value) => {
|
|
||||||
const minHour = new Date(value);
|
|
||||||
minHour.setHours(0, 0, 0, 0);
|
|
||||||
const maxHour = new Date(value);
|
|
||||||
maxHour.setHours(23, 59, 59, 59);
|
|
||||||
|
|
||||||
return [minHour, maxHour];
|
|
||||||
};
|
|
||||||
|
|
||||||
function exprBuilder(param, value) {
|
function exprBuilder(param, value) {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'date_send':
|
|
||||||
return {
|
|
||||||
[`o.date_send`]: {
|
|
||||||
between: dateRange(value),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
case 'clientFk':
|
case 'clientFk':
|
||||||
return { [`c.id`]: value };
|
return { [`c.id`]: value };
|
||||||
case 'salesPersonFk':
|
case 'salesPersonFk':
|
||||||
return { [`c.${param}`]: value };
|
return { [`c.salesPersonFk`]: value };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,22 +31,37 @@ const columns = computed(() => [
|
||||||
name: 'date',
|
name: 'date',
|
||||||
field: 'dated',
|
field: 'dated',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
sortable: true,
|
orderBy: 'date_send',
|
||||||
cardVisible: true,
|
columnFilter: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('salesOrdersTable.client'),
|
label: t('salesOrdersTable.client'),
|
||||||
name: 'client',
|
name: 'clientFk',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
sortable: true,
|
columnFilter: {
|
||||||
cardVisible: true,
|
component: 'select',
|
||||||
|
attrs: {
|
||||||
|
url: 'Clients',
|
||||||
|
fields: ['id', 'name'],
|
||||||
|
sortBy: 'name ASC',
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('salesOrdersTable.salesPerson'),
|
label: t('salesOrdersTable.salesPerson'),
|
||||||
name: 'salesPerson',
|
name: 'salesPersonFk',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
sortable: true,
|
optionFilter: 'firstName',
|
||||||
cardVisible: true,
|
columnFilter: {
|
||||||
|
component: 'select',
|
||||||
|
attrs: {
|
||||||
|
url: 'Workers/activeWithInheritedRole',
|
||||||
|
fields: ['id', 'name'],
|
||||||
|
sortBy: 'nickname ASC',
|
||||||
|
where: { role: 'salesPerson' },
|
||||||
|
useLike: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -90,47 +85,23 @@ const removeOrders = async () => {
|
||||||
const params = { deletes: selectedIds };
|
const params = { deletes: selectedIds };
|
||||||
await axios.post('SalesMonitors/deleteOrders', params);
|
await axios.post('SalesMonitors/deleteOrders', params);
|
||||||
selectedRows.value = [];
|
selectedRows.value = [];
|
||||||
await paginateRef.value.fetch();
|
await table.value.reload();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error deleting orders', err);
|
console.error('Error deleting orders', err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const redirectToOrderSummary = (orderId) => {
|
const openTab = (id) =>
|
||||||
const url = `#/order/${orderId}/summary`;
|
window.open(`#/order/${id}/summary`, '_blank', 'noopener, noreferrer');
|
||||||
window.open(url, '_blank');
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<FetchData
|
|
||||||
url="Workers/activeWithInheritedRole"
|
|
||||||
:filter="{
|
|
||||||
fields: ['id', 'nickname'],
|
|
||||||
order: 'nickname ASC',
|
|
||||||
where: { role: 'salesPerson' },
|
|
||||||
}"
|
|
||||||
auto-load
|
|
||||||
@on-fetch="(data) => (workersActiveOptions = data)"
|
|
||||||
/>
|
|
||||||
<FetchData
|
|
||||||
url="Clients"
|
|
||||||
:filter="{
|
|
||||||
fields: ['id', 'name'],
|
|
||||||
order: 'name ASC',
|
|
||||||
}"
|
|
||||||
auto-load
|
|
||||||
@on-fetch="(data) => (clientsOptions = data)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<VnSubToolbar />
|
|
||||||
<QCard style="max-height: 380px; overflow-y: scroll">
|
<QCard style="max-height: 380px; overflow-y: scroll">
|
||||||
<VnTable
|
<VnTable
|
||||||
ref="paginateRef"
|
ref="table"
|
||||||
data-key="SalesMonitorOrders"
|
data-key="SalesMonitorOrders"
|
||||||
url="SalesMonitors/ordersFilter"
|
url="SalesMonitors/ordersFilter"
|
||||||
search-url="SalesMonitorOrders"
|
search-url="SalesMonitorOrders"
|
||||||
order="date_make DESC"
|
order="date_send DESC"
|
||||||
:limit="6"
|
:limit="6"
|
||||||
:right-search="false"
|
:right-search="false"
|
||||||
:expr-builder="exprBuilder"
|
:expr-builder="exprBuilder"
|
||||||
|
@ -142,15 +113,25 @@ const redirectToOrderSummary = (orderId) => {
|
||||||
'hide-bottom': true,
|
'hide-bottom': true,
|
||||||
}"
|
}"
|
||||||
default-mode="table"
|
default-mode="table"
|
||||||
:without-header="false"
|
:row-click="({ id }) => openTab(id)"
|
||||||
@row-click="(_, row) => redirectToOrderSummary(row.id)"
|
|
||||||
v-model:selected="selectedRows"
|
v-model:selected="selectedRows"
|
||||||
|
:disable-option="{ card: true }"
|
||||||
>
|
>
|
||||||
<template #top-left>
|
<template #top-left>
|
||||||
<QBtn
|
<QBtn
|
||||||
v-if="selectedRows.length > 0"
|
icon="refresh"
|
||||||
|
size="md"
|
||||||
|
color="primary"
|
||||||
|
dense
|
||||||
|
flat
|
||||||
|
@click="$refs.table.reload()"
|
||||||
|
/>
|
||||||
|
<QBtn
|
||||||
|
v-if="selectedRows.length"
|
||||||
icon="delete"
|
icon="delete"
|
||||||
size="md"
|
size="md"
|
||||||
|
dense
|
||||||
|
flat
|
||||||
color="primary"
|
color="primary"
|
||||||
@click="
|
@click="
|
||||||
openConfirmationModal(
|
openConfirmationModal(
|
||||||
|
@ -176,7 +157,7 @@ const redirectToOrderSummary = (orderId) => {
|
||||||
<div>{{ toDateTimeFormat(row.date_make) }}</div>
|
<div>{{ toDateTimeFormat(row.date_make) }}</div>
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
<template #column-client="{ row }">
|
<template #column-clientFk="{ row }">
|
||||||
<QTd>
|
<QTd>
|
||||||
<div class="q-mb-md">
|
<div class="q-mb-md">
|
||||||
<span class="link">{{ row.clientName }}</span>
|
<span class="link">{{ row.clientName }}</span>
|
||||||
|
@ -186,7 +167,7 @@ const redirectToOrderSummary = (orderId) => {
|
||||||
</QTd>
|
</QTd>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #column-salesPerson="{ row }">
|
<template #column-salesPersonFk="{ row }">
|
||||||
<QTd>
|
<QTd>
|
||||||
<div class="q-mb-md">
|
<div class="q-mb-md">
|
||||||
<span class="link">{{ row.salesPerson }}</span>
|
<span class="link">{{ row.salesPerson }}</span>
|
||||||
|
@ -202,4 +183,8 @@ const redirectToOrderSummary = (orderId) => {
|
||||||
.q-td {
|
.q-td {
|
||||||
color: gray;
|
color: gray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.q-table__container > div:first-child) {
|
||||||
|
background-color: var(--vn-section-color);
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue