0
0
Fork 0
This commit is contained in:
Joan Sanchez 2023-01-27 09:43:10 +01:00
parent 97a5600841
commit 1b998d453d
3 changed files with 185 additions and 115 deletions

View File

@ -1,6 +1,8 @@
<script setup>
import { ref } from 'vue';
import { ref, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { useArrayData } from 'composables/useArrayData';
// const props = defineProps({
// id: {
// type: String,
@ -8,33 +10,103 @@ import { useArrayData } from 'composables/useArrayData';
// },
// });
const { t } = useI18n();
const arrayData = useArrayData('customers');
const searchText = ref('');
const searchPanel = ref();
const searchParams = ref({});
const searchBackdrop = ref(false);
async function search({ userParams }) {
//const params = userParams;
const params = userParams.value;
await arrayData.apply({ params });
// searchPanel.value.hide();
if (userParams) Object.assign(searchParams.value, userParams.value);
await arrayData.apply({ params: searchParams });
searchPanel.value.hide();
}
async function remove(param) {
delete searchParams.value[param];
await search({ userParams: {} });
}
const tags = computed(() => {
const params = [];
for (const param in searchParams.value) {
params.push({
property: param,
label: param,
value: searchParams.value[param],
});
}
return params;
});
</script>
<template>
<q-form @submit="search">
<q-input id="searchbar" v-model="searchText" label="Search" dark dense standout autofocus>
<q-input id="searchbar" v-model="searchParams.search" label="Search" dark dense standout autofocus>
<template #prepend>
<q-icon name="search" />
</template>
<template #append>
<q-btn icon="label" flat dense>
<q-popup-proxy>
<q-card class="q-pa-md" style="max-width: 300px">
<div class="truncate-chip-labels">
<q-chip
v-for="chip of tags"
:key="chip.label"
@remove="remove(chip.property)"
icon="label"
color="primary"
size="sm"
removable
>
<strong>{{ t(chip.label) }}: </strong>
<span>"{{ chip.value }}"</span>
</q-chip>
</div>
</q-card>
</q-popup-proxy>
</q-btn>
<q-btn @click="searchBackdrop = !searchBackdrop" icon="filter_alt" flat dense>
<q-tooltip>Apply search filters</q-tooltip>
<div class="q-dialog__backdrop fixed-full" v-if="searchBackdrop"></div>
<q-popup-proxy ref="searchPanel" v-model="searchBackdrop" target="#searchbar" no-parent-event fit>
<q-card class="q-pa-md">
<div class="row truncate-chip-labels">
<q-chip
v-for="chip of tags"
:key="chip.label"
@remove="remove(chip.property)"
icon="label"
color="primary"
size="sm"
removable
>
<strong>{{ t(chip.label) }}: </strong>
<span>"{{ chip.value }}"</span>
</q-chip>
</div>
<slot name="panel" :scope="{ search }" />
</q-card>
</q-popup-proxy>
</q-btn>
</template>
</q-input>
</q-form>
</template>
<i18n>
{
"en": {
"phone": "Phone"
},
"es": {
"phone": "Teléfono"
}
}
</i18n>

View File

@ -67,10 +67,10 @@ export function useArrayData(key, userOptions) {
if (append === false) {
store.data = response.data;
}
updateStateParams();
}
}
async function request({ userFilter }) {
if (!store.url) return;
@ -116,6 +116,9 @@ export function useArrayData(key, userOptions) {
order: store.order,
limit: store.limit,
skip: store.skip,
params: [
'a'
],
},
});
}

View File

@ -1,7 +1,10 @@
<script setup>
import { ref } from 'vue';
import { useSession } from 'composables/useSession';
import FetchData from 'components/FetchData.vue';
const session = useSession();
const props = defineProps({
scope: {
type: Object,
@ -9,7 +12,9 @@ const props = defineProps({
},
});
const token = session.getToken();
const userParams = ref({});
async function search() {
const searchFn = props.scope.search;
@ -35,31 +40,11 @@ function setWorkers(data) {
@on-fetch="setWorkers"
auto-load
/>
<q-card class="q-pa-md">
<q-form @submit="search" class="q-gutter-y-md">
<!-- <div class="row truncate-chip-labels">
<q-chip
v-for="chip of tags"
:key="chip.label"
@remove="log('Icecream')"
icon="label"
color="primary"
size="sm"
removable
>
<strong>{{ chip.label }}: </strong>
<span>"{{ chip.value }}"</span>
</q-chip>
</div> -->
<div class="row q-gutter-x-md">
<div class="col">
<q-input
v-model="userParams.search"
label="Search"
hint="Search by id or name"
lazy-rules
autofocus
/>
<q-input v-model="userParams.search" label="Search" hint="Search by id or name" lazy-rules autofocus />
</div>
</div>
<div class="row q-gutter-x-md">
@ -154,5 +139,15 @@ function setWorkers(data) {
<q-btn label="Search" type="submit" color="primary" class="full-width" rounded />
</div>
</q-form>
</q-card>
</template>
<i18n>
{
"en": {
"phone": "Phone"
},
"es": {
"phone": "Teléfono"
}
}
</i18n>