refactor: enhance order filtering logic and improve code readability
gitea/salix-front/pipeline/pr-master There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-master There was a failure building this commit
Details
This commit is contained in:
parent
504e08d88b
commit
3cf7aeae87
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue';
|
import { ref, computed } 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';
|
||||||
|
@ -34,34 +34,42 @@ const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
const arrayData = useArrayData(props.dataKey);
|
const arrayData = useArrayData(props.dataKey);
|
||||||
|
|
||||||
const categoryList = ref(null);
|
const categoryList = ref(null);
|
||||||
const typeList = ref([]);
|
const typeList = ref([]);
|
||||||
const searchByTag = ref(null);
|
const searchByTag = ref(null);
|
||||||
|
|
||||||
const vnFilterPanelRef = ref();
|
const vnFilterPanelRef = ref();
|
||||||
const orderByList = ref([
|
const orderByListStatic = [
|
||||||
{ id: 'relevancy DESC, name', name: t('params.relevancy'), priority: 999 },
|
{ id: 'relevancy DESC, name', name: t('params.relevancy'), priority: 999 },
|
||||||
{ id: 'showOrder, price', name: t('params.colorAndPrice'), priority: 999 },
|
{ id: 'showOrder, price', name: t('params.colorAndPrice'), priority: 999 },
|
||||||
{ id: 'name', name: t('params.name'), priority: 999 },
|
{ id: 'name', name: t('params.name'), priority: 999 },
|
||||||
{ id: 'price', name: t('params.price'), priority: 999 },
|
{ id: 'price', name: t('params.price'), priority: 999 },
|
||||||
]);
|
];
|
||||||
const orderWayList = ref([
|
const orderWayList = [
|
||||||
{ id: 'ASC', name: t('params.ASC') },
|
{ id: 'ASC', name: t('params.ASC') },
|
||||||
{ id: 'DESC', name: t('params.DESC') },
|
{ id: 'DESC', name: t('params.DESC') },
|
||||||
]);
|
];
|
||||||
const orderBySelected = ref('relevancy DESC, name');
|
const orderBySelected = ref('relevancy DESC, name');
|
||||||
const orderWaySelected = ref('ASC');
|
const orderWaySelected = ref('ASC');
|
||||||
|
const orderByList = computed(() =>
|
||||||
|
orderByListStatic.concat(
|
||||||
|
props.tags.map((tag) => ({
|
||||||
|
...tag,
|
||||||
|
field: tag.id,
|
||||||
|
isTag: true,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
const resetCategory = (params, search) => {
|
function resetCategory(params, search) {
|
||||||
typeList.value = null;
|
typeList.value = null;
|
||||||
params.categoryFk = null;
|
params.categoryFk = null;
|
||||||
params.typeFk = null;
|
params.typeFk = null;
|
||||||
arrayData.store.userFilter = null;
|
arrayData.store.userFilter = null;
|
||||||
search();
|
search();
|
||||||
};
|
}
|
||||||
|
|
||||||
const selectCategory = async (params, category, search) => {
|
async function selectCategory(params, category, search) {
|
||||||
if (vnFilterPanelRef.value.params.categoryFk === category?.id) {
|
if (vnFilterPanelRef.value.params.categoryFk === category?.id) {
|
||||||
resetCategory(params, search);
|
resetCategory(params, search);
|
||||||
return;
|
return;
|
||||||
|
@ -69,16 +77,16 @@ const selectCategory = async (params, category, search) => {
|
||||||
params.typeFk = null;
|
params.typeFk = null;
|
||||||
params.categoryFk = category.id;
|
params.categoryFk = category.id;
|
||||||
await loadTypes(category?.id);
|
await loadTypes(category?.id);
|
||||||
};
|
}
|
||||||
|
|
||||||
const loadTypes = async (id) => {
|
async function loadTypes(id) {
|
||||||
const { data } = await axios.get(`Orders/${route.params.id}/getItemTypeAvailable`, {
|
const { data } = await axios.get(`Orders/${route.params.id}/getItemTypeAvailable`, {
|
||||||
params: { itemCategoryId: id },
|
params: { itemCategoryId: id },
|
||||||
});
|
});
|
||||||
typeList.value = data;
|
typeList.value = data;
|
||||||
};
|
}
|
||||||
|
|
||||||
const applyTags = (tagInfo, params, search) => {
|
function applyTags(tagInfo, params, search) {
|
||||||
if (!tagInfo || !tagInfo.values.length) {
|
if (!tagInfo || !tagInfo.values.length) {
|
||||||
params.tagGroups = null;
|
params.tagGroups = null;
|
||||||
search();
|
search();
|
||||||
|
@ -88,7 +96,7 @@ const applyTags = (tagInfo, params, search) => {
|
||||||
if (!params.tagGroups) params.tagGroups = [];
|
if (!params.tagGroups) params.tagGroups = [];
|
||||||
params.tagGroups.push(tagInfo);
|
params.tagGroups.push(tagInfo);
|
||||||
search();
|
search();
|
||||||
};
|
}
|
||||||
|
|
||||||
async function onSearchByTag(value) {
|
async function onSearchByTag(value) {
|
||||||
if (!value.target.value) return;
|
if (!value.target.value) return;
|
||||||
|
@ -102,16 +110,16 @@ async function onSearchByTag(value) {
|
||||||
searchByTag.value = null;
|
searchByTag.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeTagGroupParam = (params, search, valIndex) => {
|
function removeTagGroupParam(params, search, valIndex) {
|
||||||
if (!valIndex && valIndex !== 0) {
|
if (!valIndex && valIndex !== 0) {
|
||||||
params.tagGroups = null;
|
params.tagGroups = null;
|
||||||
} else {
|
} else {
|
||||||
params.tagGroups.splice(valIndex, 1);
|
params.tagGroups.splice(valIndex, 1);
|
||||||
}
|
}
|
||||||
search();
|
search();
|
||||||
};
|
}
|
||||||
|
|
||||||
const setCategoryList = (data) => {
|
function setCategoryList(data) {
|
||||||
categoryList.value = (data || [])
|
categoryList.value = (data || [])
|
||||||
.filter((category) => category.display)
|
.filter((category) => category.display)
|
||||||
.map((category) => ({
|
.map((category) => ({
|
||||||
|
@ -121,17 +129,22 @@ const setCategoryList = (data) => {
|
||||||
|
|
||||||
vnFilterPanelRef.value.params.categoryFk &&
|
vnFilterPanelRef.value.params.categoryFk &&
|
||||||
loadTypes(vnFilterPanelRef.value.params.categoryFk);
|
loadTypes(vnFilterPanelRef.value.params.categoryFk);
|
||||||
};
|
}
|
||||||
|
|
||||||
const getCategoryClass = (category, params) => {
|
function getCategoryClass(category, params) {
|
||||||
if (category.id === params?.categoryFk) {
|
if (category.id === params?.categoryFk) {
|
||||||
return 'active';
|
return 'active';
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function addOrder(value, field, params) {
|
function addOrder(value, field, params) {
|
||||||
let { orderBy } = params;
|
let { orderBy } = params;
|
||||||
orderBy = JSON.parse(orderBy);
|
orderBy = JSON.parse(orderBy);
|
||||||
|
|
||||||
|
if (field == 'field') {
|
||||||
|
orderBy.isTag = !orderByListStatic.find((tag) => tag.id === value);
|
||||||
|
}
|
||||||
|
|
||||||
orderBy[field] = value;
|
orderBy[field] = value;
|
||||||
params.orderBy = JSON.stringify(orderBy);
|
params.orderBy = JSON.stringify(orderBy);
|
||||||
vnFilterPanelRef.value.search();
|
vnFilterPanelRef.value.search();
|
||||||
|
|
Loading…
Reference in New Issue