forked from verdnatura/salix-front
feat: refs #6896 new filters
This commit is contained in:
parent
98159de257
commit
adf7c3a139
|
@ -3,12 +3,12 @@ import { computed, ref } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import VnInput from 'components/common/VnInput.vue';
|
|
||||||
import FetchData from 'components/FetchData.vue';
|
import FetchData from 'components/FetchData.vue';
|
||||||
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
import VnFilterPanel from 'src/components/ui/VnFilterPanel.vue';
|
||||||
import VnSelect from 'components/common/VnSelect.vue';
|
import VnSelect from 'components/common/VnSelect.vue';
|
||||||
import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue';
|
import VnFilterPanelChip from 'components/ui/VnFilterPanelChip.vue';
|
||||||
import { useValidator } from 'src/composables/useValidator';
|
import { useValidator } from 'src/composables/useValidator';
|
||||||
|
import VnInput from 'src/components/common/VnInput.vue';
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ const moreFields = ref([]);
|
||||||
const moreFieldsOrder = ref([]);
|
const moreFieldsOrder = ref([]);
|
||||||
const createValue = (val, done) => {
|
const createValue = (val, done) => {
|
||||||
if (val.length > 2) {
|
if (val.length > 2) {
|
||||||
// if (!tagOptions.value.includes(val)) {
|
if (!tagOptions.value.includes(val)) {
|
||||||
// done(tagOptions.value, 'add-unique');
|
done(tagOptions.value, 'add-unique');
|
||||||
// }
|
}
|
||||||
tagValues.value.push({ value: val });
|
tagValues.value.push({ value: val });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -100,22 +100,6 @@ const tagValues = ref([{}]);
|
||||||
const tagOptions = ref([]);
|
const tagOptions = ref([]);
|
||||||
|
|
||||||
const applyTagFilter = (params, search) => {
|
const applyTagFilter = (params, search) => {
|
||||||
// console.log('params: ', params);
|
|
||||||
// if (!selectedTag.value) {
|
|
||||||
// console.log('values: ', selectedTag?.value?.name);
|
|
||||||
|
|
||||||
// params.tagGroups.push(
|
|
||||||
// JSON.stringify({
|
|
||||||
// values: selectedTag?.value?.name,
|
|
||||||
// // tagSelection: {
|
|
||||||
// // ...selectedTag.value,
|
|
||||||
// // orgShowField: selectedTag?.value?.name,
|
|
||||||
// // },
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// search();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
if (!tagValues.value?.length) {
|
if (!tagValues.value?.length) {
|
||||||
params.tagGroups = null;
|
params.tagGroups = null;
|
||||||
search();
|
search();
|
||||||
|
@ -148,14 +132,42 @@ const removeTagChip = (selection, params, search) => {
|
||||||
search();
|
search();
|
||||||
};
|
};
|
||||||
|
|
||||||
const orderByParam = ref(null);
|
const onOrderChange = (value, params) => {
|
||||||
|
const tagObj = JSON.parse(params.orderBy);
|
||||||
const onOrderFieldChange = (value, params, search) => {
|
tagObj.way = value.name;
|
||||||
const orderBy = Object.assign({}, orderByParam.value, { field: value.field });
|
params.orderBy = JSON.stringify(tagObj);
|
||||||
params.orderBy = JSON.stringify(orderBy);
|
|
||||||
search();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onOrderFieldChange = (value, params) => {
|
||||||
|
console.log('value: ', value);
|
||||||
|
console.log('params: ', params);
|
||||||
|
const tagObj = JSON.parse(params.orderBy);
|
||||||
|
switch (value) {
|
||||||
|
case 'Relevancy':
|
||||||
|
tagObj.field = value + ' DESC, name';
|
||||||
|
params.orderBy = JSON.stringify(tagObj);
|
||||||
|
console.log('params: ', params);
|
||||||
|
break;
|
||||||
|
case 'ColorAndPrice':
|
||||||
|
tagObj.field = 'showOrder, price';
|
||||||
|
params.orderBy = JSON.stringify(tagObj);
|
||||||
|
console.log('params: ', params);
|
||||||
|
break;
|
||||||
|
case 'Name':
|
||||||
|
tagObj.field = 'name';
|
||||||
|
params.orderBy = JSON.stringify(tagObj);
|
||||||
|
console.log('params: ', params);
|
||||||
|
break;
|
||||||
|
case 'Price':
|
||||||
|
tagObj.field = 'price';
|
||||||
|
params.orderBy = JSON.stringify(tagObj);
|
||||||
|
console.log('params: ', params);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const _moreFields = ['ASC', 'DESC'];
|
||||||
|
const _moreFieldsTypes = ['Relevancy', 'ColorAndPrice', 'Name', 'Price'];
|
||||||
const setCategoryList = (data) => {
|
const setCategoryList = (data) => {
|
||||||
categoryList.value = (data || [])
|
categoryList.value = (data || [])
|
||||||
.filter((category) => category.display)
|
.filter((category) => category.display)
|
||||||
|
@ -163,8 +175,6 @@ const setCategoryList = (data) => {
|
||||||
...category,
|
...category,
|
||||||
icon: `vn:${(category.icon || '').split('-')[1]}`,
|
icon: `vn:${(category.icon || '').split('-')[1]}`,
|
||||||
}));
|
}));
|
||||||
const _moreFields = ['ASC', 'DESC'];
|
|
||||||
const _moreFieldsTypes = ['Relevancy', 'ColorAndPrice', 'Name', 'Price'];
|
|
||||||
moreFields.value = useLang(_moreFields);
|
moreFields.value = useLang(_moreFields);
|
||||||
moreFieldsOrder.value = useLang(_moreFieldsTypes);
|
moreFieldsOrder.value = useLang(_moreFieldsTypes);
|
||||||
};
|
};
|
||||||
|
@ -195,11 +205,13 @@ const useLang = (values) => {
|
||||||
<VnFilterPanel
|
<VnFilterPanel
|
||||||
:data-key="props.dataKey"
|
:data-key="props.dataKey"
|
||||||
:hidden-tags="['orderFk', 'orderBy']"
|
:hidden-tags="['orderFk', 'orderBy']"
|
||||||
|
:unremovable-params="['orderFk', 'orderBy']"
|
||||||
:expr-builder="exprBuilder"
|
:expr-builder="exprBuilder"
|
||||||
:custom-tags="['tagGroups']"
|
:custom-tags="['tagGroups']"
|
||||||
@remove="clearFilter"
|
@remove="clearFilter"
|
||||||
>
|
>
|
||||||
<template #tags="{ tag, formatFn }">
|
<template #tags="{ tag, formatFn }">
|
||||||
|
{{ console.log('tag: ', tag) }}
|
||||||
<strong v-if="tag.label === 'categoryFk'">
|
<strong v-if="tag.label === 'categoryFk'">
|
||||||
{{ t(selectedCategory?.name || '') }}
|
{{ t(selectedCategory?.name || '') }}
|
||||||
</strong>
|
</strong>
|
||||||
|
@ -293,9 +305,7 @@ const useLang = (values) => {
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
rounded
|
rounded
|
||||||
@update:model-value="
|
@update:model-value="(value) => onOrderChange(value, params)"
|
||||||
(value) => onOrderChange(value, params, searchFn)
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
|
@ -310,9 +320,7 @@ const useLang = (values) => {
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
rounded
|
rounded
|
||||||
@update:model-value="
|
@update:model-value="(value) => onOrderFieldChange(value, params)"
|
||||||
(value) => onOrderFieldChange(value, params, searchFn)
|
|
||||||
"
|
|
||||||
/>
|
/>
|
||||||
</QItemSection>
|
</QItemSection>
|
||||||
</QItem>
|
</QItem>
|
||||||
|
@ -338,14 +346,15 @@ const useLang = (values) => {
|
||||||
:key="value"
|
:key="value"
|
||||||
class="q-mt-md filter-value"
|
class="q-mt-md filter-value"
|
||||||
>
|
>
|
||||||
<VnInput
|
<FetchData
|
||||||
v-if="selectedTag?.isFree"
|
v-if="selectedTag"
|
||||||
v-model="value.value"
|
:url="`Tags/${selectedTag}/filterValue`"
|
||||||
:label="t('params.value')"
|
limit="30"
|
||||||
is-outlined
|
auto-load
|
||||||
class="filter-input"
|
@on-fetch="(data) => (tagOptions = data)"
|
||||||
/>
|
/>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
|
v-if="!selectedTag"
|
||||||
:label="t('params.value')"
|
:label="t('params.value')"
|
||||||
v-model="value.value"
|
v-model="value.value"
|
||||||
:options="tagValue || []"
|
:options="tagValue || []"
|
||||||
|
@ -358,17 +367,31 @@ const useLang = (values) => {
|
||||||
use-input
|
use-input
|
||||||
class="filter-input"
|
class="filter-input"
|
||||||
@new-value="createValue"
|
@new-value="createValue"
|
||||||
>
|
|
||||||
</VnSelect>
|
|
||||||
<FetchData
|
|
||||||
v-if="selectedTag"
|
|
||||||
:url="`Tags/${selectedTag}/filterValue`"
|
|
||||||
limit="30"
|
|
||||||
auto-load
|
|
||||||
@on-fetch="(data) => (tagOptions = data)"
|
|
||||||
/>
|
/>
|
||||||
{{ console.log('selectedTag: ', selectedTag) }}
|
<VnSelect
|
||||||
|
v-else-if="selectedTag === 1"
|
||||||
|
:label="t('params.value')"
|
||||||
|
v-model="value.value"
|
||||||
|
:options="tagOptions || []"
|
||||||
|
option-value="value"
|
||||||
|
option-label="value"
|
||||||
|
dense
|
||||||
|
outlined
|
||||||
|
rounded
|
||||||
|
emit-value
|
||||||
|
use-input
|
||||||
|
class="filter-input"
|
||||||
|
@new-value="createValue"
|
||||||
|
/>
|
||||||
|
<VnInput
|
||||||
|
v-else
|
||||||
|
:label="t('params.value')"
|
||||||
|
v-model="value.value"
|
||||||
|
dense
|
||||||
|
outlined
|
||||||
|
rounded
|
||||||
|
class="filter-input"
|
||||||
|
/>
|
||||||
<QIcon
|
<QIcon
|
||||||
name="delete"
|
name="delete"
|
||||||
class="filter-icon"
|
class="filter-icon"
|
||||||
|
|
Loading…
Reference in New Issue