From ccfe61d777f50b004898b64599c5a68d8d93a2a6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 19 Sep 2024 01:10:14 +0200 Subject: [PATCH] feat: vnSelect exprBuilder --- src/components/common/VnSelect.vue | 6 +++++ src/pages/Customer/Card/CustomerBasicData.vue | 25 +++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index ed842103f..cd5608954 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -38,6 +38,10 @@ const $props = defineProps({ type: [Array], default: () => [], }, + exprBuilder: { + type: Function, + default: null, + }, isClearable: { type: Boolean, default: true, @@ -179,6 +183,8 @@ async function fetchFilter(val) { }, {}); } else defaultWhere = { [key]: getVal(val) }; const where = { ...(val ? defaultWhere : {}), ...$props.where }; + if (typeof $props.exprBuilder === 'function') + Object.assign(where, $props.exprBuilder(key, val)); const fetchOptions = { where, include, limit }; if (fields) fetchOptions.fields = fields; if (sortBy) fetchOptions.order = sortBy; diff --git a/src/pages/Customer/Card/CustomerBasicData.vue b/src/pages/Customer/Card/CustomerBasicData.vue index 3682ecd73..6472a47ff 100644 --- a/src/pages/Customer/Card/CustomerBasicData.vue +++ b/src/pages/Customer/Card/CustomerBasicData.vue @@ -16,19 +16,19 @@ const { t } = useI18n(); const businessTypes = ref([]); const contactChannels = ref([]); const title = ref(); -const handleSalesModelValue = (val) => { - filter.value.and[1] = { - or: [ - { name: val }, - { nickname: { like: '%' + val + '%' } }, - { code: { like: `${val}%` } }, - ], +const handleSalesModelValue = (val) => ({ + or: [ + { name: val }, + { nickname: { like: '%' + val + '%' } }, + { code: { like: `${val}%` } }, + ], +}); + +const exprBuilder = (param, value) => { + return { + and: [{ active: { neq: false } }, handleSalesModelValue(value)], }; }; - -const filter = ref({ - and: [{ active: { neq: false } }], -});