comments
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-06-07 12:59:34 +02:00
parent 0dd3e6be09
commit 117c2e90db
1 changed files with 11 additions and 17 deletions

View File

@ -66,7 +66,7 @@ const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props); const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
const myOptions = ref([]); const myOptions = ref([]);
const myOptionsFiltered = ref([]); // const myOptionsFiltered = ref([]);
const myOptionsOriginal = ref([]); const myOptionsOriginal = ref([]);
const vnSelectRef = ref(); const vnSelectRef = ref();
const dataRef = ref(); const dataRef = ref();
@ -76,6 +76,7 @@ const selectValue = computed({
return $props.modelValue; return $props.modelValue;
}, },
set(value) { set(value) {
arrayData.store.page.value = 0;
emit('update:modelValue', value); emit('update:modelValue', value);
}, },
}); });
@ -103,8 +104,7 @@ onMounted(async () => {
setOptions(data); setOptions(data);
return; return;
} }
if ($props.options) setOptions($props.options); if (!$props.options) fetchFilter($props.modelValue);
else fetchFilter($props.modelValue);
}); });
watch(modelValue, (newValue) => { watch(modelValue, (newValue) => {
@ -136,37 +136,31 @@ function filter(val, options) {
return optionsFiltered; return optionsFiltered;
} }
function buildwhere(val) { async function fetchFilter(val) {
if (!useURL.value || !dataRef.value) return; 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; 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 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 }); return dataRef.value.fetch({ fields, where, order: sortBy, limit });
} }
async function filterHandler(val, update) { async function filterHandler(val, update) {
if (!$props.defaultFilter) return update(); if (!$props.defaultFilter) return update();
let newOptions = []; let newOptions = [];
if (myOptionsFiltered.value.length > 0) { if (myOptions.value.length > 0) {
newOptions = filter(val, myOptionsFiltered.value); newOptions = filter(val, myOptions.value);
myOptionsFiltered.value = []; myOptions.value = [];
} else newOptions = filter(val, myOptionsOriginal.value); } else newOptions = filter(val, myOptionsOriginal.value);
if (useURL.value && myOptions.value.length < 1) { if (useURL.value && myOptions.value.length < 1) {
arrayData.store.skip = 0; arrayData.store.skip = 0;
arrayData.store.filter.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 }); const { data } = await arrayData.fetch({ append: false });
newOptions = data; newOptions = data;
myOptionsFiltered.value = data; myOptions.value = data;
} }
update( update(
() => { () => {