feat: refs #8118 add VnDropdown component and integrate it into Claim and Ticket summaries #1517

Merged
benjaminedc merged 53 commits from 8118-createComponentVnDropdown into dev 2025-03-26 10:32:30 +00:00
3 changed files with 86 additions and 53 deletions
Showing only changes of commit 0e48701bc7 - Show all commits

View File

@ -0,0 +1,60 @@
<script setup>
import { ref } from 'vue';
import VnSelect from './VnSelect.vue';
const stateBtnDropdownRef = ref();
const emit = defineEmits(['changeState']);
const $props = defineProps({
disable: {
type: Boolean,
default: null,
},
moduleName: {
benjaminedc marked this conversation as resolved
Review

No usar moduleName , optionLabel

No usar moduleName , optionLabel
type: String,
default: null,
},
options: {
type: Array,
default: null,
},
benjaminedc marked this conversation as resolved Outdated

añadir también optionValue, tiene que ser flexible, puede que no se quiera usar siempre code, si quieres ponerlo como opción por defecto vale.

añadir también optionValue, tiene que ser flexible, puede que no se quiera usar siempre code, si quieres ponerlo como opción por defecto vale.
});
async function changeState(value) {
stateBtnDropdownRef.value?.hide();
emit('changeState', value);
}
</script>
<template>
<QBtnDropdown
ref="stateBtnDropdownRef"
color="black"
text-color="white"
:label="$t('globals.changeState')"
:disable="$props.disable"
>
<VnSelect
:options="$props.options"
hide-selected
option-value="code"
hide-dropdown-icon
benjaminedc marked this conversation as resolved
Review

añadir: :option-label="optionLabel", se puede hacer directamente :option-label si se llama igual la variable que quieres pasar, pero al ser camelCase no sé si funciona.

añadir: `:option-label="optionLabel"`, se puede hacer directamente :option-label si se llama igual la variable que quieres pasar, pero al ser camelCase no sé si funciona.
focus-on-mount
@update:model-value="changeState"
>
<template #option="scope">
<QItem v-bind="scope.itemProps">
<QItemSection>
<QItemLabel v-if="$props.moduleName === 'Ticket'">
{{ scope.opt?.name }}
</QItemLabel>
benjaminedc marked this conversation as resolved
Review

Este template es el que tiene por defecto VnSelect, no hace falta que lo añadas aquí.

Este template es el que tiene por defecto VnSelect, no hace falta que lo añadas aquí.
<QItemLabel v-if="$props.moduleName === 'Claim'">
{{ scope.opt?.description }}
</QItemLabel>
</QItemSection>
</QItem>
</template>
</VnSelect>
</QBtnDropdown>
</template>

View File

@ -1,6 +1,6 @@
<script setup>
import axios from 'axios';
import { ref, computed } from 'vue';
import { ref, computed, onMounted } from 'vue';
benjaminedc marked this conversation as resolved Outdated

onMounted no se usa, quitar

onMounted no se usa, quitar
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { toDate, toCurrency } from 'src/filters';
@ -20,6 +20,7 @@ import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue';
import CustomerDescriptorProxy from 'src/pages/Customer/Card/CustomerDescriptorProxy.vue';
import WorkerDescriptorProxy from 'src/pages/Worker/Card/WorkerDescriptorProxy.vue';
import ClaimDescriptorMenu from './ClaimDescriptorMenu.vue';
import VnDropdown from 'src/components/common/VnDropdown.vue';
const route = useRoute();
const router = useRouter();
@ -35,7 +36,7 @@ const $props = defineProps({
});
const entityId = computed(() => $props.id || route.params.id);
const ClaimStates = ref([]);
const claimStates = ref([]);
const claimDmsRef = ref();
const claimDms = ref([]);
const multimediaDialog = ref();
@ -172,13 +173,21 @@ function openDialog(dmsId) {
}
async function changeState(value) {
await axios.patch(`Claims/updateClaim/${entityId.value}`, { claimStateFk: value });
const newState = claimStates.value.find((state) => state.code == value);
benjaminedc marked this conversation as resolved Outdated

Si en VnDropdown, creas la prop optionValue y le dices que use id , ya no te hace falta hacer un find para encontrar el id.

Si en VnDropdown, creas la prop optionValue y le dices que use id , ya no te hace falta hacer un find para encontrar el id.
await axios.patch(`Claims/updateClaim/${entityId.value}`, {
claimStateFk: newState.id,
});
router.go(route.fullPath);
}
function claimUrl(section) {
return '#/claim/' + entityId.value + '/' + section;
}
onMounted(async () => {
benjaminedc marked this conversation as resolved Outdated

Pasar a fetchData y obtener solo los campos que necesitas(id y name)

Pasar a fetchData y obtener solo los campos que necesitas(id y name)
const { data } = await axios.get('ClaimStates');
claimStates.value = data;
});
</script>
<template>
@ -188,7 +197,6 @@ function claimUrl(section) {
@on-fetch="(data) => setClaimDms(data)"
ref="claimDmsRef"
/>
<FetchData url="ClaimStates" @on-fetch="(data) => (ClaimStates = data)" auto-load />
<CardSummary
ref="summary"
:url="`Claims/${entityId}/getSummary`"
@ -200,34 +208,11 @@ function claimUrl(section) {
{{ claim.id }} - {{ claim.client.name }} ({{ claim.client.id }})
</template>
<template #header-right>
<QBtnDropdown
side
top
color="black"
text-color="white"
:label="t('globals.changeState')"
>
<QList>
<QVirtualScroll
class="max-container-height"
:items="ClaimStates"
separator
v-slot="{ item, index }"
>
<QItem
:key="index"
dense
clickable
v-close-popup
@click="changeState(item.id)"
>
<QItemSection>
<QItemLabel>{{ item.description }}</QItemLabel>
</QItemSection>
</QItem>
</QVirtualScroll>
</QList>
</QBtnDropdown>
<VnDropdown
:moduleName="route.meta.moduleName"
:options="claimStates"
@change-state="changeState($event)"
/>
benjaminedc marked this conversation as resolved Outdated

Si usas id no no hace falta pasar la propiedad, utiliza ese por defecto

Si usas id no no hace falta pasar la propiedad, utiliza ese por defecto
</template>
<template #menu="{ entity }">
<ClaimDescriptorMenu :claim="entity.claim" />

View File

@ -21,6 +21,7 @@ import VnSelect from 'src/components/common/VnSelect.vue';
import VnToSummary from 'src/components/ui/VnToSummary.vue';
import TicketDescriptorMenu from './TicketDescriptorMenu.vue';
import TicketProblems from 'src/components/TicketProblems.vue';
import VnDropdown from 'src/components/common/VnDropdown.vue';
const route = useRoute();
const { notify } = useNotify();
@ -40,7 +41,7 @@ const ticket = computed(() => summary.value?.entity);
const editableStates = ref([]);
const ticketUrl = ref();
const grafanaUrl = 'https://grafana.verdnatura.es';
const stateBtnDropdownRef = ref();
const descriptorData = useArrayData('Ticket');
onMounted(async () => {
@ -67,7 +68,6 @@ function isEditable() {
}
async function changeState(value) {
stateBtnDropdownRef.value?.hide();
const formData = {
ticketFk: entityId.value,
code: value,
@ -113,25 +113,13 @@ onMounted(async () => {
</div>
</template>
<template #header-right>
<div>
<QBtnDropdown
ref="stateBtnDropdownRef"
color="black"
text-color="white"
:label="t('globals.changeState')"
:disable="!isEditable()"
>
<VnSelect
:options="editableStates"
hide-selected
option-label="name"
option-value="code"
hide-dropdown-icon
focus-on-mount
@update:model-value="changeState"
/>
</QBtnDropdown>
</div>
<VnDropdown
:moduleName="route.meta.moduleName"
:moduleId="entityId"
:options="editableStates"
benjaminedc marked this conversation as resolved Outdated

no hace falta usar ":" cuando es texto.

no hace falta usar ":" cuando es texto.
:disable="!isEditable()"
benjaminedc marked this conversation as resolved Outdated

Aquí tenías puesto antes el code, ahora usas el id,, pero el back espera un code.

Aquí tenías puesto antes el code, ahora usas el id,, pero el back espera un code.
@change-state="changeState($event)"
benjaminedc marked this conversation as resolved
Review

No hace falta poner $event, con poner changeState es suficiente.

No hace falta poner $event, con poner **changeState** es suficiente.
/>
</template>
<template #menu="{ entity }">
<TicketDescriptorMenu :ticket="entity" />