feat: vnSelect exprBuilder

This commit is contained in:
Javier Segarra 2024-09-19 01:10:14 +02:00
parent e40f216e33
commit ccfe61d777
2 changed files with 18 additions and 13 deletions

View File

@ -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;

View File

@ -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 } }],
});
</script>
<template>
<FetchData
@ -109,11 +109,10 @@ const filter = ref({
:params="{
departmentCodes: ['VT', 'shopping'],
}"
:where="filter"
:fields="['id', 'nickname']"
sort-by="nickname ASC"
:rules="validate('client.salesPersonFk')"
@filter="handleSalesModelValue"
:expr-builder="exprBuilder"
emit-value
auto-load
>