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 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(
() => {