diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index e8083dec2..493f094ce 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -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 }); } diff --git a/src/pages/Zone/ZoneDeliveryPanel.vue b/src/pages/Zone/ZoneDeliveryPanel.vue index 1295bb63d..c754d484f 100644 --- a/src/pages/Zone/ZoneDeliveryPanel.vue +++ b/src/pages/Zone/ZoneDeliveryPanel.vue @@ -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 () => {