0
0
Fork 0

fix: refs #6539 VnSelect use url

This commit is contained in:
Alex Moreno 2024-05-17 14:32:39 +02:00
parent 01ad6d9bea
commit 75f3d4f410
2 changed files with 19 additions and 36 deletions

View File

@ -22,6 +22,10 @@ const $props = defineProps({
type: String,
default: '',
},
optionFilter: {
type: String,
default: null,
},
url: {
type: String,
default: '',
@ -59,7 +63,7 @@ const $props = defineProps({
const { t } = useI18n();
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
const { optionLabel, optionValue, options, modelValue } = toRefs($props);
const { optionLabel, optionValue, optionFilter, options, modelValue } = toRefs($props);
const myOptions = ref([]);
const myOptionsOriginal = ref([]);
const vnSelectRef = ref();
@ -109,9 +113,9 @@ async function fetchFilter(val) {
const { fields, sortBy, limit } = $props;
let key = optionLabel.value;
if (new RegExp(/\d/g).test(val)) key = optionValue.value;
if (new RegExp(/\d/g).test(val)) key = optionFilter.value ?? optionValue.value;
const where = { [key]: { like: `%${val}%` } };
const where = { ...{ [key]: { like: `%${val}%` } }, ...$props.where };
return dataRef.value.fetch({ fields, where, order: sortBy, limit });
}

View File

@ -14,17 +14,8 @@ const { t } = useI18n();
const { notify } = useNotify();
const deliveryMethodFk = ref(null);
const postcodesOptions = ref([]);
const agencyModesOptions = ref([]);
const deliveryMethods = ref([]);
const formData = reactive({});
const agencyFilter = ref({
fields: ['id', 'name'],
where: {
deliveryMethodFk: null,
},
order: 'name ASC',
limit: 30,
});
const arrayData = useArrayData('ZoneDeliveryDays', {
url: 'Zones/getEvents',
@ -47,25 +38,11 @@ watch(
if (val === 'pickUp') filter = { where: { code: 'PICKUP' } };
else filter = { where: { code: { inq: ['DELIVERY', 'AGENCY'] } } };
const deliveryMethods = await fetchDeliveryMethods(filter);
agencyFilter.value.where = {
deliveryMethodFk: { inq: deliveryMethods },
};
await fetchAgencyModes(agencyFilter.value);
deliveryMethods.value = await fetchDeliveryMethods(filter);
},
{ immediate: true }
);
const fetchAgencyModes = async (filter) => {
try {
const params = { filter: JSON.stringify(filter) };
const { data } = await axios.get('AgencyModes/isActive', { params });
agencyModesOptions.value = data;
} catch (err) {
console.error('Error fetching agency modes: ', err);
}
};
const fetchData = async (params) => {
try {
const { data } = params
@ -94,12 +71,6 @@ onMounted(async () => {
</script>
<template>
<FetchData
url="Postcodes/location"
:filter="{ fields: ['geoFk', 'code', 'townFk'], order: 'code, townFk' }"
@on-fetch="(data) => (postcodesOptions = data)"
auto-load
/>
<QForm @submit="onSubmit()" class="q-pa-md">
<div class="column q-gutter-y-sm">
<QRadio
@ -119,9 +90,12 @@ onMounted(async () => {
v-if="deliveryMethodFk === 'delivery'"
:label="t('deliveryPanel.postcode')"
v-model="formData.geoFk"
:options="postcodesOptions"
url="Postcodes/location"
:fields="['geoFk', 'code', 'townFk']"
sort-by="code, townFk"
option-value="geoFk"
option-label="code"
option-filter="code"
hide-selected
dense
outlined
@ -148,7 +122,12 @@ onMounted(async () => {
)
"
v-model="formData.agencyModeFk"
:options="agencyModesOptions"
url="AgencyModes/isActive"
:fields="['id', 'name']"
:where="{
deliveryMethodFk: { inq: deliveryMethods },
}"
sort-by="name ASC"
option-value="id"
option-label="name"
hide-selected