forked from verdnatura/salix-front
fix: refs #6539 VnSelect use url
This commit is contained in:
parent
01ad6d9bea
commit
75f3d4f410
|
@ -22,6 +22,10 @@ const $props = defineProps({
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
optionFilter: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
url: {
|
url: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -59,7 +63,7 @@ const $props = defineProps({
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const requiredFieldRule = (val) => val ?? t('globals.fieldRequired');
|
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 myOptions = ref([]);
|
||||||
const myOptionsOriginal = ref([]);
|
const myOptionsOriginal = ref([]);
|
||||||
const vnSelectRef = ref();
|
const vnSelectRef = ref();
|
||||||
|
@ -109,9 +113,9 @@ async function fetchFilter(val) {
|
||||||
const { fields, sortBy, limit } = $props;
|
const { fields, sortBy, limit } = $props;
|
||||||
let key = optionLabel.value;
|
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 });
|
return dataRef.value.fetch({ fields, where, order: sortBy, limit });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,8 @@ const { t } = useI18n();
|
||||||
const { notify } = useNotify();
|
const { notify } = useNotify();
|
||||||
|
|
||||||
const deliveryMethodFk = ref(null);
|
const deliveryMethodFk = ref(null);
|
||||||
const postcodesOptions = ref([]);
|
const deliveryMethods = ref([]);
|
||||||
const agencyModesOptions = ref([]);
|
|
||||||
const formData = reactive({});
|
const formData = reactive({});
|
||||||
const agencyFilter = ref({
|
|
||||||
fields: ['id', 'name'],
|
|
||||||
where: {
|
|
||||||
deliveryMethodFk: null,
|
|
||||||
},
|
|
||||||
order: 'name ASC',
|
|
||||||
limit: 30,
|
|
||||||
});
|
|
||||||
|
|
||||||
const arrayData = useArrayData('ZoneDeliveryDays', {
|
const arrayData = useArrayData('ZoneDeliveryDays', {
|
||||||
url: 'Zones/getEvents',
|
url: 'Zones/getEvents',
|
||||||
|
@ -47,25 +38,11 @@ watch(
|
||||||
if (val === 'pickUp') filter = { where: { code: 'PICKUP' } };
|
if (val === 'pickUp') filter = { where: { code: 'PICKUP' } };
|
||||||
else filter = { where: { code: { inq: ['DELIVERY', 'AGENCY'] } } };
|
else filter = { where: { code: { inq: ['DELIVERY', 'AGENCY'] } } };
|
||||||
|
|
||||||
const deliveryMethods = await fetchDeliveryMethods(filter);
|
deliveryMethods.value = await fetchDeliveryMethods(filter);
|
||||||
agencyFilter.value.where = {
|
|
||||||
deliveryMethodFk: { inq: deliveryMethods },
|
|
||||||
};
|
|
||||||
await fetchAgencyModes(agencyFilter.value);
|
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ 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) => {
|
const fetchData = async (params) => {
|
||||||
try {
|
try {
|
||||||
const { data } = params
|
const { data } = params
|
||||||
|
@ -94,12 +71,6 @@ onMounted(async () => {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<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">
|
<QForm @submit="onSubmit()" class="q-pa-md">
|
||||||
<div class="column q-gutter-y-sm">
|
<div class="column q-gutter-y-sm">
|
||||||
<QRadio
|
<QRadio
|
||||||
|
@ -119,9 +90,12 @@ onMounted(async () => {
|
||||||
v-if="deliveryMethodFk === 'delivery'"
|
v-if="deliveryMethodFk === 'delivery'"
|
||||||
:label="t('deliveryPanel.postcode')"
|
:label="t('deliveryPanel.postcode')"
|
||||||
v-model="formData.geoFk"
|
v-model="formData.geoFk"
|
||||||
:options="postcodesOptions"
|
url="Postcodes/location"
|
||||||
|
:fields="['geoFk', 'code', 'townFk']"
|
||||||
|
sort-by="code, townFk"
|
||||||
option-value="geoFk"
|
option-value="geoFk"
|
||||||
option-label="code"
|
option-label="code"
|
||||||
|
option-filter="code"
|
||||||
hide-selected
|
hide-selected
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
|
@ -148,7 +122,12 @@ onMounted(async () => {
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
v-model="formData.agencyModeFk"
|
v-model="formData.agencyModeFk"
|
||||||
:options="agencyModesOptions"
|
url="AgencyModes/isActive"
|
||||||
|
:fields="['id', 'name']"
|
||||||
|
:where="{
|
||||||
|
deliveryMethodFk: { inq: deliveryMethods },
|
||||||
|
}"
|
||||||
|
sort-by="name ASC"
|
||||||
option-value="id"
|
option-value="id"
|
||||||
option-label="name"
|
option-label="name"
|
||||||
hide-selected
|
hide-selected
|
||||||
|
|
Loading…
Reference in New Issue