From 117c2e90db029798f888864a8110e0af2c0c4f59 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 7 Jun 2024 12:59:34 +0200 Subject: [PATCH] comments --- src/components/common/VnSelect.vue | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index 3b93fcca4..c855ed6c5 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -66,7 +66,7 @@ const requiredFieldRule = (val) => val ?? t('globals.fieldRequired'); const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props); const myOptions = ref([]); -const myOptionsFiltered = ref([]); +// const myOptionsFiltered = ref([]); const myOptionsOriginal = ref([]); const vnSelectRef = ref(); const dataRef = ref(); @@ -76,6 +76,7 @@ const selectValue = computed({ return $props.modelValue; }, set(value) { + arrayData.store.page.value = 0; emit('update:modelValue', value); }, }); @@ -103,8 +104,7 @@ onMounted(async () => { setOptions(data); return; } - if ($props.options) setOptions($props.options); - else fetchFilter($props.modelValue); + if (!$props.options) fetchFilter($props.modelValue); }); watch(modelValue, (newValue) => { @@ -136,37 +136,31 @@ function filter(val, options) { return optionsFiltered; } -function buildwhere(val) { +async function fetchFilter(val) { if (!useURL.value || !dataRef.value) return; - let key = optionLabel.value; - + const { fields, sortBy, limit } = $props; + let key = null; if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value; const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where }; - return where; -} -async function fetchFilter(val) { - const { fields, sortBy, limit } = $props; - const where = buildwhere(val); - if (!dataRef.value) return; return dataRef.value.fetch({ fields, where, order: sortBy, limit }); } async function filterHandler(val, update) { if (!$props.defaultFilter) return update(); let newOptions = []; - if (myOptionsFiltered.value.length > 0) { - newOptions = filter(val, myOptionsFiltered.value); - myOptionsFiltered.value = []; + if (myOptions.value.length > 0) { + newOptions = filter(val, myOptions.value); + myOptions.value = []; } else newOptions = filter(val, myOptionsOriginal.value); if (useURL.value && myOptions.value.length < 1) { arrayData.store.skip = 0; arrayData.store.filter.skip = 0; - arrayData.store.filter.where = { [optionFilter.value]: val }; + arrayData.store.filter.where = { [optionFilter.value]: val, ...$props.where }; const { data } = await arrayData.fetch({ append: false }); newOptions = data; - myOptionsFiltered.value = data; + myOptions.value = data; } update( () => {