refs #6280 feat: return geoFk VnLocation
gitea/salix-front/pipeline/head This commit looks good Details

This commit is contained in:
Javier Segarra 2024-01-12 11:27:54 +01:00
parent 67d4471f42
commit 4b3ca3bbd9
2 changed files with 5 additions and 55 deletions

View File

@ -2,7 +2,6 @@
import { ref, toRefs, computed, watch } from 'vue'; import { ref, toRefs, computed, watch } from 'vue';
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue'; import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
import VnSelectCreate from 'components/common/VnSelectCreate.vue'; import VnSelectCreate from 'components/common/VnSelectCreate.vue';
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
const emit = defineEmits(['update:modelValue', 'update:options']); const emit = defineEmits(['update:modelValue', 'update:options']);
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
@ -44,14 +43,10 @@ const $props = defineProps({
default: true, default: true,
}, },
}); });
const locationsRef = ref();
const locationsRefFilter = ref({ fields: ['code', 'nickname'], limit: 30 });
const { optionLabel, optionValue, options } = toRefs($props); const { options } = toRefs($props);
const myOptions = ref([]); const myOptions = ref([]);
const myOptionsOriginal = ref([]); const myOptionsOriginal = ref([]);
const vnSelectRef = ref();
const showForm = ref(false);
const value = computed({ const value = computed({
get() { get() {
@ -67,42 +62,6 @@ function setOptions(data) {
myOptionsOriginal.value = JSON.parse(JSON.stringify(data)); myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
} }
setOptions(options.value); setOptions(options.value);
const filter = (val, options) => {
const search = val.toString().toLowerCase();
if (!search) return options;
// if (!search.length < 2) return options;
return options
};
const filterHandler = (val, update) => {
update(
() => {
// if (val.length>2)
myOptions.value = filter(val, myOptionsOriginal.value);
},
(ref) => {
if (val !== '' && ref.options.length > 0) {
ref.setOptionIndex(-1);
ref.moveOptionSelection(1, true);
}
}
);
};
function locationFilter(val) {
let where = { limit: 30 };
let params = {};
let key = 'nickname';
if (new RegExp(/\d/g).test(val)) {
key = 'id';
}
params = { [key]: { like: `%${val}%` } };
where = Object.assign(where, params);
locationsRef.value.fetch({ where });
}
watch(options, (newValue) => { watch(options, (newValue) => {
setOptions(newValue); setOptions(newValue);
}); });
@ -135,19 +94,19 @@ function showLabel(data){
auto-load auto-load
url="Countries" url="Countries"
/> />
<!-- @input-value="filter"
:default-filter="false" -->
<VnSelectCreate <VnSelectCreate
v-model="value" v-model="value"
:options="postcodesOptions" :options="postcodesOptions"
:label="t('Location')" :label="t('Location')"
option-label="code" option-value="geoFk"
:option-label="showLabel"
:placeholder="t('Min. 3 char')"
v-bind="$attrs" v-bind="$attrs"
emit-value emit-value
map-options map-options
use-input use-input
:filter-options="['code','town.name']" :filter-options="['code','town.name']"
:filter-rules="['val.length>2',{code:'.length > 2'}]" :filter-rules="['val.length>2']"
clearable clearable
hide-selected hide-selected
fill-input fill-input

View File

@ -72,7 +72,6 @@ const filter = (val, options) => {
if (!search) return options; if (!search) return options;
if($props.filterRules.length) { if($props.filterRules.length) {
const passSomeRule = $props.filterRules.some((rule) => { const passSomeRule = $props.filterRules.some((rule) => {
if(typeof rule === 'object') return true
const cond = eval(rule) const cond = eval(rule)
return cond; return cond;
}); });
@ -82,15 +81,7 @@ const filter = (val, options) => {
return options.filter((row) => { return options.filter((row) => {
if ($props.filterOptions.length) { if ($props.filterOptions.length) {
return $props.filterOptions.some((prop) => { return $props.filterOptions.some((prop) => {
const passRules = $props.filterRules
.filter(rule=>typeof rule === 'object')
.every(rule=>{
const propExists = Object.keys(rule).includes(prop);
if(!propExists) return false;
return eval(prop.concat(rule[prop]))
});
const propValue = String(deepFind(row,prop)).toLowerCase(); const propValue = String(deepFind(row,prop)).toLowerCase();
if(passRules)
return propValue.includes(search); return propValue.includes(search);
}); });
} }