0
0
Fork 0

refs #5673 feat: create VnSelectFilter

This commit is contained in:
Alex Moreno 2023-08-02 15:15:23 +02:00
parent 92e914adad
commit 0cb925abc3
3 changed files with 74 additions and 96 deletions

View File

@ -0,0 +1,58 @@
<script setup>
import { ref, watch, toRefs } from 'vue';
const emit = defineEmits(['update:modelValue', 'update:options']);
const $props = defineProps({
modelValue: {
type: [String, Number],
default: null,
},
options: {
type: Array,
default: () => [],
},
optionLabel: {
type: String,
default: '',
},
});
const updateValue = (newValue) => emit('update:modelValue', newValue);
const updateOptions = (newValue) => emit('update:options', newValue);
const { modelValue } = toRefs($props);
function filterFn(val, update) {
update(
() => {
const needle = val.toLowerCase();
console.log($props.options);
// $props.options.value = options.value.filter(
// (v) => v[$props.optionLabel.value].toLowerCase().indexOf(needle) > -1
// );
updateOptions(
$props.options.filter(
(v) => v[$props.optionLabel].toLowerCase().indexOf(needle) > -1
)
);
},
(ref) => {
ref.setOptionIndex(-1);
ref.moveOptionSelection(1, true);
}
);
}
</script>
<template>
<QSelect
v-model="modelValue"
@update:model-value="updateValue"
:options="options"
:option-label="optionLabel"
v-bind="$attrs"
emit-value
map-options
use-input
@filter="(value, update) => filterFn(value, update)"
/>
</template>

View File

@ -64,6 +64,7 @@ onMounted(async () => {
</QScrollArea> </QScrollArea>
</QDrawer> </QDrawer>
<QPageContainer> <QPageContainer>
<div id="sub-toolbar"></div>
<QPage class="q-pa-md"> <QPage class="q-pa-md">
<RouterView></RouterView> <RouterView></RouterView>
</QPage> </QPage>

View File

@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import FormModel from 'components/FormModel.vue'; import FormModel from 'components/FormModel.vue';
import FetchData from 'components/FetchData.vue'; import FetchData from 'components/FetchData.vue';
import VnSelectFilter from 'components/common/VnSelectFilter.vue';
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
@ -87,66 +88,6 @@ const columns = computed(() => [
optionLabel: 'description', optionLabel: 'description',
}, },
]); ]);
// function filterFn(val, update) {
// if (val === '') {
// update(() => {
// options.value = stringOptions;
// });
// return;
// }
// update(() => {
// const needle = val.toLowerCase();
// options.value = stringOptions.filter((v) => v.toLowerCase().indexOf(needle) > -1);
// });
// }
// const basicFilter = () => {
// return {
// options: claimReasons,
// filterFn: (options, value) => {
// console.log('ENTRY', value);
// const search = value.toLowerCase();
// if (value === '') return claimReasons.value;
// const arr = options.value.filter((row) => {
// const id = row.id;
// const name = row.description.toLowerCase();
// console.log('SEARCH', search, id);
// const idMatches = id == search;
// const nameMatches = name.indexOf(search) > -1;
// return idMatches || nameMatches;
// });
// console.log(arr);
// return arr;
// },
// };
// };
const basicFilter = (options, field) => {
console.log(options, field);
return {
options,
field,
filterFn: (options, value, field) => {
const search = value.toLowerCase();
if (value === '') return options;
return options.value.filter((row) => {
console.log(row);
const id = row.id;
const name = row[field ?? 'name'].toLowerCase();
const idMatches = id == search;
const nameMatches = name.indexOf(search) > -1;
return idMatches || nameMatches;
});
},
};
};
</script> </script>
<template> <template>
<FetchData <FetchData
@ -189,7 +130,7 @@ const basicFilter = (options, field) => {
ref="claimDevelopmentForm" ref="claimDevelopmentForm"
:data-required="{ claimFk: route.params.id }" :data-required="{ claimFk: route.params.id }"
> >
<template #form="{ data, filter }"> <template #form="{ data }">
<QTable <QTable
:columns="columns" :columns="columns"
:rows="data" :rows="data"
@ -202,23 +143,12 @@ const basicFilter = (options, field) => {
> >
<template #body-cell="{ row, col }"> <template #body-cell="{ row, col }">
<QTd auto-width> <QTd auto-width>
<QSelect <VnSelectFilter
:label="col.label" :label="col.label"
v-model="row[col.model]" v-model="row[col.model]"
:options="col.options" :options="col.options"
:option-value="col.optionValue" :option-value="col.optionValue"
:option-label="col.optionLabel" :option-label="col.optionLabel"
emit-value
map-options
use-input
@filter="
(value, update) =>
filter(
value,
update,
basicFilter(col.options, col.optionLabel)
)
"
/> />
</QTd> </QTd>
</template> </template>
@ -232,27 +162,13 @@ const basicFilter = (options, field) => {
<QList dense> <QList dense>
<QItem v-for="col in props.cols" :key="col.name"> <QItem v-for="col in props.cols" :key="col.name">
<QItemSection> <QItemSection>
<QSelect <VnSelectFilter
:label="col.label" :label="col.label"
v-model="props.row[col.model]" v-model="props.row[col.model]"
:options="col.options" :options="col.options"
:option-value="col.optionValue" :option-value="col.optionValue"
:option-label="col.optionLabel" :option-label="col.optionLabel"
emit-value
map-options
use-input
dense dense
@filter="
(value, update) =>
filter(
value,
update,
basicFilter(
col.options,
col.optionLabel
)
)
"
/> />
</QItemSection> </QItemSection>
</QItem> </QItem>
@ -265,14 +181,17 @@ const basicFilter = (options, field) => {
</FormModel> </FormModel>
</div> </div>
</div> </div>
<QPageSticky position="bottom-right" :offset="[25, 100]"> <Teleport to="#sub-toolbar">
<QBtn <QToolbar class="bg-dark text-white justify-end">
fab <div class="row q-gutter-x-sm">
color="primary" <QBtn
icon="delete" color="primary"
@click="claimDevelopmentForm.remove(selected)" icon="delete"
/> @click="claimDevelopmentForm.remove(selected)"
</QPageSticky> />
</div>
</QToolbar>
</Teleport>
<QPageSticky position="bottom-right" :offset="[25, 25]"> <QPageSticky position="bottom-right" :offset="[25, 25]">
<QBtn fab color="primary" icon="add" @click="claimDevelopmentForm.insert()" /> <QBtn fab color="primary" icon="add" @click="claimDevelopmentForm.insert()" />
</QPageSticky> </QPageSticky>