Zone list and Zone summary

This commit is contained in:
William Buezas 2024-05-09 08:21:30 -03:00
parent a3ce81d66d
commit 9b9e482fa7
9 changed files with 243 additions and 135 deletions

View File

@ -2,14 +2,16 @@
import { ref, onMounted, computed } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { dashIfEmpty } from 'src/filters';
import { getUrl } from 'src/composables/getUrl';
import VnLv from 'src/components/ui/VnLv.vue';
import VnLinkPhone from 'src/components/ui/VnLinkPhone.vue';
import CardSummary from 'components/ui/CardSummary.vue';
import VnUserLink from 'src/components/ui/VnUserLink.vue';
import VnTitle from 'src/components/common/VnTitle.vue';
import { getUrl } from 'src/composables/getUrl';
import { toCurrency } from 'filters/index';
import { toTimeFormat } from 'src/filters/date';
import axios from 'axios';
const route = useRoute();
const { t } = useI18n();
@ -23,77 +25,84 @@ const $props = defineProps({
const entityId = computed(() => $props.id || route.params.id);
const zoneUrl = ref();
onMounted(async () => {
zoneUrl.value = (await getUrl('')) + `zone/${entityId.value}/`;
const filter = computed(() => {
const filter = {
include: {
relation: 'agencyMode',
fields: ['name'],
},
where: {
id: route.params.id,
},
};
return filter;
});
const filter = computed(() => {
const columns = computed(() => [
{
label: t('summary.name'),
name: 'name',
field: 'warehouse',
align: 'left',
format: (val) => val.name,
},
]);
const warehouses = ref([]);
const getWarehouses = async () => {
const params = {
filter: {
include: {
relation: 'agencyMode',
relation: 'warehouse',
fields: ['name'],
},
where: {
id: entityId.value,
},
},
};
return params;
const { data } = await axios.get(`Zones/${entityId.value}/warehouses`, { params });
warehouses.value = data;
};
onMounted(async () => {
zoneUrl.value = (await getUrl('')) + `zone/${entityId.value}/`;
await getWarehouses();
});
</script>
<template>
<CardSummary data-key="zoneData" ref="summary" url="Zones/findOne" :filter="filter">
<CardSummary
data-key="ZoneSummary"
ref="summary"
url="Zones/findOne"
:filter="filter"
>
<template #header="{ entity }">
<div>#{{ entity.id }} - {{ entity.name }}</div>
</template>
<template #body="{ entity: zone }">
<QCard class="vn-one">
<VnTitle
:url="zoneUrl + `basic-data`"
:text="t('zone.summary.basicData')"
/>
<VnLv :label="t('zone.card.name')" :value="zone.user?.nickname" />
<VnLv
:label="t('zone.list.department')"
:value="zone.department?.department?.name"
/>
<VnLv :label="t('zone.list.email')" :value="zone.user.email" copy />
<VnLv :label="t('zone.summary.boss')" link>
<template #value>
<VnUserLink
v-if="zone.boss"
:name="dashIfEmpty(zone.boss?.name)"
:zone-id="zone.bossFk"
/>
</template>
</VnLv>
<VnLv :value="zone.mobileExtension">
<template #label>
{{ t('zone.summary.phoneExtension') }}
<VnLinkPhone :phone-number="zone.mobileExtension" />
</template>
</VnLv>
<VnLv :value="zone.phone">
<template #label>
{{ t('zone.summary.entPhone') }}
<VnLinkPhone :phone-number="zone.phone" />
</template>
</VnLv>
<VnLv :label="t('zone.summary.locker')" :value="zone.locker" />
<VnTitle :url="zoneUrl + `basic-data`" :text="t('summary.basicData')" />
<VnLv :label="t('summary.agency')" :value="zone.agencyMode?.name" />
<VnLv :label="t('summary.price')" :value="toCurrency(zone.price)" />
<VnLv :label="t('summary.bonus')" :value="toCurrency(zone.bonus)" />
</QCard>
<QCard class="vn-one">
<VnTitle :text="t('zone.summary.userData')" />
<VnLv :label="t('zone.summary.userId')" :value="zone.user.id" />
<VnLv :label="t('zone.card.name')" :value="zone.user.nickname" />
<VnLv :label="t('zone.summary.role')" :value="zone.user.role.name" />
<VnLv :value="zone?.sip?.extension">
<template #label>
{{ t('zone.summary.sipExtension') }}
<VnLinkPhone :phone-number="zone?.sip?.extension" />
</template>
</VnLv>
<VnTitle :url="zoneUrl + `basic-data`" :text="t('summary.basicData')" />
<VnLv :label="t('summary.closeHour')" :value="toTimeFormat(zone.hour)" />
<VnLv :label="t('summary.travelingDays')" :value="zone.travelingDays" />
<QCheckbox
:label="t('summary.volumetric')"
v-model="zone.isVolumetric"
:disable="true"
/>
</QCard>
<QCard class="full-width">
<VnTitle :url="zoneUrl + `warehouses`" :text="t('summary.warehouse')" />
<QTable
:columns="columns"
:rows="warehouses"
:no-data-label="t('globals.noResults')"
/>
</QCard>
</template>
</CardSummary>

View File

@ -63,7 +63,7 @@ async function remove(row) {
outline
/>
<QBtn
:label="t('zone.list.remove')"
:label="t('list.remove')"
@click.stop="remove(row)"
color="primary"
style="margin-top: 15px"

View File

@ -63,7 +63,7 @@ async function remove(row) {
outline
/>
<QBtn
:label="t('zone.list.remove')"
:label="t('list.remove')"
@click.stop="remove(row)"
color="primary"
style="margin-top: 15px"

View File

@ -96,7 +96,7 @@ function filterType(val, update) {
<QInput
filled
v-model="zone.label"
:label="t('zone.create.name')"
:label="t('create.name')"
type="number"
min="0"
:rules="[(val) => !!val || t('zone.warnings.labelNotEmpty')]"
@ -106,7 +106,7 @@ function filterType(val, update) {
<VnInput
filled
v-model="zone.plate"
:label="t('zone.create.agency')"
:label="t('create.agency')"
:rules="[(val) => !!val || t('zone.warnings.plateNotEmpty')]"
/>
</div>
@ -116,7 +116,7 @@ function filterType(val, update) {
<QInput
filled
v-model="zone.volume"
:label="t('zone.create.close')"
:label="t('create.close')"
type="number"
min="0"
:rules="[(val) => !!val || t('zone.warnings.volumeNotEmpty')]"
@ -134,7 +134,7 @@ function filterType(val, update) {
option-value="id"
emit-value
map-options
:label="t('zone.create.price')"
:label="t('create.price')"
:options="filteredZoneTypes"
:rules="[(val) => !!val || t('zone.warnings.typeNotEmpty')]"
@filter="filterType"
@ -158,9 +158,9 @@ function filterType(val, update) {
</div>
</QCard>
<div class="q-mt-md">
<QBtn :label="t('zone.type.submit')" type="submit" color="primary" />
<QBtn :label="t('type.submit')" type="submit" color="primary" />
<QBtn
:label="t('zone.type.reset')"
:label="t('type.reset')"
type="reset"
color="primary"
flat

View File

@ -4,7 +4,7 @@ import { useI18n } from 'vue-i18n';
import VnInput from 'components/common/VnInput.vue';
import FetchData from 'components/FetchData.vue';
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
import VnSelect from 'components/common/VnSelect.vue';
const { t } = useI18n();
const props = defineProps({
@ -17,37 +17,43 @@ const props = defineProps({
default: null,
},
});
const agencies = ref([]);
</script>
<template>
<FetchData
url="agencies"
limit="30"
@on-fetch="(data) => (agencies = data)"
auto-load
/>
<FetchData url="agencies" @on-fetch="(data) => (agencies = data)" auto-load />
<VnFilterPanel :data-key="props.dataKey" :search-button="true">
<template #body="{ params }">
<template #tags="{ tag }">
<div class="q-gutter-x-xs">
<strong>{{ t(`filterPanel.${tag.label}`) }}: </strong>
<span>{{ tag.value }}</span>
</div>
</template>
<template #body="{ params, searchFn }">
<QItem>
<QItemSection>
<VnInput :label="t('Name')" v-model="params.name" is-outlined />
<VnInput
:label="t('filterPanel.name')"
v-model="params.name"
is-outlined
/>
</QItemSection>
</QItem>
<QItem>
<QItemSection>
<VnSelectFilter
:label="t('Agency')"
v-model="params.agencyModefK"
<VnSelect
:label="t('filterPanel.agencyModeFk')"
v-model="params.agencyModeFk"
:options="agencies"
option-value="id"
option-label="name"
@input-value="agencies.fetch()"
@update:model-value="searchFn()"
dense
outlined
rounded
>
</VnSelectFilter>
</VnSelect>
</QItemSection>
</QItem>
</template>

View File

@ -1,17 +1,24 @@
<script setup>
import axios from 'axios';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import VnPaginate from 'src/components/ui/VnPaginate.vue';
import CardList from 'components/ui/CardList.vue';
import VnLv from 'components/ui/VnLv.vue';
import ZoneSummary from 'src/pages/Zone/Card/ZoneSummary.vue';
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
import ZoneFilterPanel from './ZoneFilterPanel.vue';
import { useSummaryDialog } from 'src/composables/useSummaryDialog';
import { toTimeFormat } from 'src/filters/date';
import { toCurrency } from 'filters/index';
import { useVnConfirm } from 'composables/useVnConfirm';
import useNotify from 'src/composables/useNotify.js';
import { useStateStore } from 'stores/useStateStore';
import axios from 'axios';
const stateStore = useStateStore();
const { t } = useI18n();
const router = useRouter();
const { notify } = useNotify();
@ -26,19 +33,70 @@ function redirectToCreateView() {
router.push({ path: `/zone/create` });
}
const exprBuilder = (param, value) => {
switch (param) {
case 'name':
return {
name: { like: `%${value}%` },
};
case 'code':
return {
code: { like: `%${value}%` },
};
case 'agencyModeFk':
return {
agencyModeFk: value,
};
case 'search':
if (value) {
if (!isNaN(value)) {
return { id: value };
} else {
return {
name: {
like: `%${value}%`,
},
};
}
}
}
};
async function clone(id) {
try {
await axios.post(`Zones/${id}/clone`);
notify(t('globals.dataSaved'), 'positive');
//TODO: Redireccionar Zone Basic data cuando exista
// router.push({ name: 'ZoneBasicData', params: { id: row.id } });
router.push({ name: 'ZoneBasicData', params: { id } });
} catch (error) {
console.error('Error cloning zone: ', error);
}
}
onMounted(async () => {
stateStore.rightDrawer = true;
});
</script>
<template>
<template v-if="stateStore.isHeaderMounted()">
<Teleport to="#searchbar">
<VnSearchbar
data-key="ZoneList"
url="Zones"
:filter="{
include: { relation: 'agencyMode', scope: { fields: ['name'] } },
}"
:expr-builder="exprBuilder"
:label="t('list.searchZone')"
:info="t('list.searchInfo')"
/>
</Teleport>
</template>
<QDrawer v-model="stateStore.rightDrawer" side="right" :width="256" show-if-above>
<QScrollArea class="fit text-grey-8">
<ZoneFilterPanel data-key="ZoneList" :expr-builder="exprBuilder" />
</QScrollArea>
</QDrawer>
<QPage class="column items-center q-pa-md">
<div class="vn-card-list">
<VnPaginate
@ -59,31 +117,31 @@ async function clone(id) {
>
<template #list-items>
<VnLv
:label="t('zone.list.id')"
:title-label="t('zone.list.id')"
:label="t('list.id')"
:title-label="t('list.id')"
:value="row.id"
/>
<VnLv :label="t('zone.list.name')" :value="row?.name" />
<VnLv :label="t('list.name')" :value="row?.name" />
<VnLv
:label="t('zone.list.agency')"
:label="t('list.agency')"
:value="row.agencyMode?.name"
/>
<VnLv
:label="t('zone.list.close')"
:label="t('list.close')"
:value="toTimeFormat(row?.hour)"
/>
<VnLv
:label="t('zone.list.price')"
:label="t('list.price')"
:value="toCurrency(row?.price)"
/>
</template>
<template #actions>
<QBtn
:label="t('zone.list.clone')"
:label="t('list.clone')"
@click.stop="
openConfirmationModal(
t('zone.list.confirmCloneTitle'),
t('zone.list.confirmCloneSubtitle'),
t('list.confirmCloneTitle'),
t('list.confirmCloneSubtitle'),
() => clone(row.id)
)
"
@ -91,7 +149,7 @@ async function clone(id) {
style="margin-top: 15px"
/>
<QBtn
:label="t('zone.list.openSummary')"
:label="t('list.openSummary')"
@click.stop="viewSummary(row.id, ZoneSummary)"
color="primary"
style="margin-top: 15px"
@ -103,7 +161,7 @@ async function clone(id) {
</div>
<QPageSticky position="bottom-right" :offset="[18, 18]">
<QBtn @click="redirectToCreateView()" fab icon="add" color="primary">
<QTooltip>{{ t('zone.list.create') }}</QTooltip>
<QTooltip>{{ t('list.create') }}</QTooltip>
</QBtn>
</QPageSticky>
</QPage>

View File

@ -1,21 +1,34 @@
zone:
list:
volume: Volume
clone: Clone
id: Id
name: Name
agency: Agency
close: Close
price: Price
create: Create zone
openSummary: Details
confirmCloneTitle: All it's properties will be copied
confirmCloneSubtitle: Do you want to clone this zone?
create:
name: Name
agency: Agency
close: Close
price: Price
type:
submit: Save
reset: Reset
list:
clone: Clone
id: Id
name: Name
agency: Agency
close: Close
price: Price
create: Create zone
openSummary: Details
confirmCloneTitle: All it's properties will be copied
confirmCloneSubtitle: Do you want to clone this zone?
searchZone: Search zones
searchInfo: Search zone by id or name
create:
name: Name
agency: Agency
close: Close
price: Price
type:
submit: Save
reset: Reset
summary:
agency: Agency
price: Price
basicData: Basic data
bonus: Bonus
closeHour: Close hour
travelingDays: Traveling days
volumetric: Volumetric
warehouse: Warehouse
name: Name
filterPanel:
name: Name
agencyModeFk: Agency

View File

@ -1,21 +1,34 @@
zone:
list:
volume: Volumen
clone: Clonar
id: Id
name: Nombre
agency: Agencia
close: Cierre
price: Precio
create: Crear zona
openSummary: Detalles
confirmCloneTitle: Todas sus propiedades serán copiadas
confirmCloneSubtitle: ¿Seguro que quieres clonar esta zona?
create:
name: Nombre
agency: Agencia
close: Cierre
price: Precio
type:
submit: Guardar
reset: Reiniciar
list:
clone: Clonar
id: Id
name: Nombre
agency: Agencia
close: Cierre
price: Precio
create: Crear zona
openSummary: Detalles
confirmCloneTitle: Todas sus propiedades serán copiadas
confirmCloneSubtitle: ¿Seguro que quieres clonar esta zona?
searchZone: Buscar zonas
searchInfo: Buscar zonas por identificador o nombre
create:
name: Nombre
agency: Agencia
close: Cierre
price: Precio
type:
submit: Guardar
reset: Reiniciar
summary:
agency: Agencia
price: Precio
basicData: Datos básicos
bonus: Bonificaciones
closeHour: Hora de cierre
travelingDays: Días de viaje
volumetric: Volumétrico
warehouse: Almacén
name: Nombre
filterPanel:
name: Nombre
agencyModeFk: Agencia

View File

@ -12,7 +12,7 @@ export default {
redirect: { name: 'ZoneMain' },
menus: {
main: ['ZoneList', 'ZoneDeliveryList', 'ZoneUpcomingList'],
card: [],
card: ['ZoneBasicData'],
},
children: [
{
@ -74,6 +74,15 @@ export default {
},
component: () => import('src/pages/Zone/Card/ZoneSummary.vue'),
},
{
name: 'ZoneBasicData',
path: 'basic-data',
meta: {
title: 'basicData',
icon: 'vn:settings',
},
component: () => import('src/pages/Zone/Card/ZoneBasicData.vue'),
},
// {
// path: '/zone/delivery',
// name: 'ZoneDeliveryMain',