forked from verdnatura/salix-front
Add search filter
This commit is contained in:
parent
827a3a4e5a
commit
ecad464366
|
@ -53,6 +53,14 @@ const props = defineProps({
|
||||||
type: Object,
|
type: Object,
|
||||||
default: null,
|
default: null,
|
||||||
},
|
},
|
||||||
|
staticParams: {
|
||||||
|
type: Array,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
exprBuilder: {
|
||||||
|
type: Function,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -69,8 +77,11 @@ onMounted(() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function search() {
|
async function search() {
|
||||||
|
const staticParams = Object.entries(store.userParams)
|
||||||
|
.filter(([key, value]) => value && (props.staticParams || []).includes(key));
|
||||||
await arrayData.applyFilter({
|
await arrayData.applyFilter({
|
||||||
params: {
|
params: {
|
||||||
|
...Object.fromEntries(staticParams),
|
||||||
search: searchText.value,
|
search: searchText.value,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
import { useStateStore } from 'stores/useStateStore';
|
import { useStateStore } from 'stores/useStateStore';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { onMounted, onUnmounted } from 'vue';
|
import { onMounted, onUnmounted } from 'vue';
|
||||||
import VnPaginate from 'components/ui/VnPaginate.vue';
|
|
||||||
import OrderCatalogItem from 'pages/Order/Card/OrderCatalogItem.vue';
|
|
||||||
import OrderSearchbar from 'pages/Order/Card/OrderSearchbar.vue';
|
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import VnPaginate from 'components/ui/VnPaginate.vue';
|
||||||
|
import VnSearchbar from 'components/ui/VnSearchbar.vue';
|
||||||
|
import OrderCatalogItem from 'pages/Order/Card/OrderCatalogItem.vue';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const stateStore = useStateStore();
|
const stateStore = useStateStore();
|
||||||
|
@ -18,15 +18,24 @@ const catalogParams = {
|
||||||
orderFk: route.params.id,
|
orderFk: route.params.id,
|
||||||
orderBy: JSON.stringify({ field: 'relevancy DESC, name', way: 'ASC', isTag: false }),
|
orderBy: JSON.stringify({ field: 'relevancy DESC, name', way: 'ASC', isTag: false }),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function exprBuilder(param, value) {
|
||||||
|
switch (param) {
|
||||||
|
case 'search':
|
||||||
|
return { 'i.name': { like: `%${value}%` } };
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Teleport to="#searchbar" v-if="stateStore.isHeaderMounted()">
|
<Teleport to="#searchbar" v-if="stateStore.isHeaderMounted()">
|
||||||
<OrderSearchbar
|
<VnSearchbar
|
||||||
data-key="OrderCatalogList"
|
data-key="OrderCatalogList"
|
||||||
url="Orders/CatalogFilter"
|
url="Orders/CatalogFilter"
|
||||||
:limit="50"
|
:limit="50"
|
||||||
:user-params="catalogParams"
|
:user-params="catalogParams"
|
||||||
|
:expr-builder="exprBuilder"
|
||||||
|
:static-params="['orderFk', 'orderBy']"
|
||||||
/>
|
/>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
<Teleport v-if="stateStore.isHeaderMounted()" to="#actions-append">
|
<Teleport v-if="stateStore.isHeaderMounted()" to="#actions-append">
|
||||||
|
|
Loading…
Reference in New Issue