forked from verdnatura/salix-front
refs #6280 feat: return geoFk VnLocation
This commit is contained in:
parent
67d4471f42
commit
4b3ca3bbd9
|
@ -2,7 +2,6 @@
|
|||
import { ref, toRefs, computed, watch } from 'vue';
|
||||
import CreateNewPostcode from 'src/components/CreateNewPostcodeForm.vue';
|
||||
import VnSelectCreate from 'components/common/VnSelectCreate.vue';
|
||||
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
|
||||
import FetchData from 'components/FetchData.vue';
|
||||
const emit = defineEmits(['update:modelValue', 'update:options']);
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
@ -44,14 +43,10 @@ const $props = defineProps({
|
|||
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 myOptionsOriginal = ref([]);
|
||||
const vnSelectRef = ref();
|
||||
const showForm = ref(false);
|
||||
|
||||
const value = computed({
|
||||
get() {
|
||||
|
@ -67,42 +62,6 @@ function setOptions(data) {
|
|||
myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
|
||||
}
|
||||
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) => {
|
||||
setOptions(newValue);
|
||||
});
|
||||
|
@ -135,19 +94,19 @@ function showLabel(data){
|
|||
auto-load
|
||||
url="Countries"
|
||||
/>
|
||||
<!-- @input-value="filter"
|
||||
:default-filter="false" -->
|
||||
<VnSelectCreate
|
||||
v-model="value"
|
||||
:options="postcodesOptions"
|
||||
:label="t('Location')"
|
||||
option-label="code"
|
||||
option-value="geoFk"
|
||||
:option-label="showLabel"
|
||||
:placeholder="t('Min. 3 char')"
|
||||
v-bind="$attrs"
|
||||
emit-value
|
||||
map-options
|
||||
use-input
|
||||
:filter-options="['code','town.name']"
|
||||
:filter-rules="['val.length>2',{code:'.length > 2'}]"
|
||||
:filter-rules="['val.length>2']"
|
||||
clearable
|
||||
hide-selected
|
||||
fill-input
|
||||
|
|
|
@ -72,7 +72,6 @@ const filter = (val, options) => {
|
|||
if (!search) return options;
|
||||
if($props.filterRules.length) {
|
||||
const passSomeRule = $props.filterRules.some((rule) => {
|
||||
if(typeof rule === 'object') return true
|
||||
const cond = eval(rule)
|
||||
return cond;
|
||||
});
|
||||
|
@ -82,15 +81,7 @@ const filter = (val, options) => {
|
|||
return options.filter((row) => {
|
||||
if ($props.filterOptions.length) {
|
||||
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();
|
||||
if(passRules)
|
||||
return propValue.includes(search);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue