refs #6694 feat call new method for filter
This commit is contained in:
parent
c0005c0544
commit
817a4e9e3f
|
@ -7,11 +7,12 @@ const emit = defineEmits(['update:modelValue', 'update:options']);
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const citiesLocationOptions = ref([]);
|
// const citiesLocationOptions = ref([]);
|
||||||
const provincesLocationOptions = ref([]);
|
// const provincesLocationOptions = ref([]);
|
||||||
const countriesOptions = ref([]);
|
// const countriesOptions = ref([]);
|
||||||
|
// const townsRef = ref([]);
|
||||||
const postcodesOptions = ref([]);
|
const postcodesOptions = ref([]);
|
||||||
const postcodeFetchDataRef = ref(null);
|
const postcodesRef = ref(null);
|
||||||
|
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
modelValue: {
|
modelValue: {
|
||||||
|
@ -67,24 +68,60 @@ watch(options, (newValue) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function showLabel(data) {
|
function showLabel(data) {
|
||||||
return `${data.code} - ${data.town.name}(${data.town.province.name}), ${data.town.province.country.country}`;
|
return `${data.code} - ${data.town}(${data.province}), ${data.country}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
function locationFilter(value) {
|
||||||
|
// if(value==='') return [];
|
||||||
|
let where = { limit: 30 };
|
||||||
|
const params = { value };
|
||||||
|
postcodesRef.value.fetch({ where: Object.assign(where, params) });
|
||||||
|
// postcodesRef.value.fetch({
|
||||||
|
// where: {
|
||||||
|
// or: [
|
||||||
|
// { code: { like: '%4660%' } },
|
||||||
|
// { 'town.name': { like: '%Alz%' } }
|
||||||
|
// ]
|
||||||
|
// }});
|
||||||
|
// const townParams = { name: { like: `%${val}%` } };
|
||||||
|
|
||||||
<template>
|
// townsRef.value.fetch({ where: Object.assign(where, townParams) });
|
||||||
<FetchData
|
}
|
||||||
ref="postcodeFetchDataRef"
|
function handleFetch( data) {
|
||||||
url="Postcodes/location"
|
// if (from === 'towns') {
|
||||||
@on-fetch="(data) => (postcodesOptions = data)"
|
// data = data.reduce((acc, town) => {
|
||||||
auto-load
|
// for (const postcode of town.postcodes) {
|
||||||
/>
|
// console.log(postcode);
|
||||||
<FetchData
|
// acc.push({ ...postcode, town:{name: town.name, province: town.province} });
|
||||||
@on-fetch="(data) => (citiesLocationOptions = data)"
|
// }
|
||||||
|
|
||||||
|
// return acc;
|
||||||
|
// }, []);
|
||||||
|
// }
|
||||||
|
// console.log(from, data);
|
||||||
|
postcodesOptions.value = data;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<!-- let where = { limit: 30 };
|
||||||
|
|
||||||
|
const params = { 'town': false, 'townsFk': {like: ``} };
|
||||||
|
where = Object.assign(where, params);
|
||||||
|
postcodesRef.value.fetch({ where});
|
||||||
|
} -->
|
||||||
|
<!-- <FetchData
|
||||||
|
ref="townsRef"
|
||||||
|
@on-fetch="(data) => handleFetch('towns', data)"
|
||||||
auto-load
|
auto-load
|
||||||
url="Towns/location"
|
url="Towns/location"
|
||||||
/>
|
/> -->
|
||||||
|
<template>
|
||||||
<FetchData
|
<FetchData
|
||||||
|
ref="postcodesRef"
|
||||||
|
url="Postcodes/filter"
|
||||||
|
@on-fetch="(data) =>handleFetch(data)"
|
||||||
|
auto-load
|
||||||
|
/>
|
||||||
|
<!-- <FetchData
|
||||||
@on-fetch="(data) => (provincesLocationOptions = data)"
|
@on-fetch="(data) => (provincesLocationOptions = data)"
|
||||||
auto-load
|
auto-load
|
||||||
url="Provinces/location"
|
url="Provinces/location"
|
||||||
|
@ -93,23 +130,26 @@ function showLabel(data){
|
||||||
@on-fetch="(data) => (countriesOptions = data)"
|
@on-fetch="(data) => (countriesOptions = data)"
|
||||||
auto-load
|
auto-load
|
||||||
url="Countries"
|
url="Countries"
|
||||||
/>
|
/> -->
|
||||||
|
<!-- :filter-options="['code','town.name']"
|
||||||
|
:filter-rules="['val.length>2']" -->
|
||||||
<VnSelectCreate
|
<VnSelectCreate
|
||||||
|
v-if="postcodesRef"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
:options="postcodesOptions"
|
:options="postcodesOptions"
|
||||||
:label="t('Location')"
|
:label="t('Location')"
|
||||||
:option-label="showLabel"
|
:option-label="showLabel"
|
||||||
:placeholder="t('Search by postalCode or town (at least 3 characters')"
|
:placeholder="t('Search by postalCode, town, province or country')"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
emit-value
|
emit-value
|
||||||
map-options
|
map-options
|
||||||
use-input
|
use-input
|
||||||
:filter-options="['code','town.name']"
|
|
||||||
:filter-rules="['val.length>2']"
|
|
||||||
clearable
|
clearable
|
||||||
hide-selected
|
hide-selected
|
||||||
fill-input
|
fill-input
|
||||||
:class="{ required: $attrs.required }"
|
:class="{ required: $attrs.required }"
|
||||||
|
@input-value="locationFilter"
|
||||||
|
:default-filter="false"
|
||||||
>
|
>
|
||||||
<template #form>
|
<template #form>
|
||||||
<CreateNewPostcode @on-data-saved="onPostcodeCreated($event)" />
|
<CreateNewPostcode @on-data-saved="onPostcodeCreated($event)" />
|
||||||
|
@ -118,9 +158,7 @@ function showLabel(data){
|
||||||
<QItem v-bind="scope.itemProps">
|
<QItem v-bind="scope.itemProps">
|
||||||
<QItemSection v-if="scope.opt">
|
<QItemSection v-if="scope.opt">
|
||||||
<QItemLabel>{{ scope.opt.code }}</QItemLabel>
|
<QItemLabel>{{ scope.opt.code }}</QItemLabel>
|
||||||
<QItemLabel caption
|
<QItemLabel caption>{{ showLabel(scope.opt) }}</QItemLabel>
|
||||||
>{{ showLabel(scope.opt)}}</QItemLabel
|
|
||||||
>
|
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
</template>
|
</template>
|
||||||
|
@ -137,5 +175,5 @@ function showLabel(data){
|
||||||
<i18n>
|
<i18n>
|
||||||
es:
|
es:
|
||||||
Location: Ubicación
|
Location: Ubicación
|
||||||
Search by postalCode or town (at least 3 characters): Buscar por código postal o nombre ( al menos 3 letras)
|
Search by postalCode, town, province or country: Buscar por código postal, ciudad o país
|
||||||
</i18n>
|
</i18n>
|
||||||
|
|
Loading…
Reference in New Issue