aggio search
This commit is contained in:
@@ -39,16 +39,24 @@ export default defineComponent({
|
|||||||
const getArrProducts = computed(() => {
|
const getArrProducts = computed(() => {
|
||||||
let arrprod = productStore.getProducts(cosa.value)
|
let arrprod = productStore.getProducts(cosa.value)
|
||||||
let catstr = cat.value;
|
let catstr = cat.value;
|
||||||
if (!search.value && !catstr) {
|
if ((!search.value || (search.value && search.value.length < 2)) && !catstr) {
|
||||||
return arrprod
|
return arrprod
|
||||||
}
|
}
|
||||||
|
|
||||||
let lowerSearchText = search.value.toLowerCase();
|
let lowerSearchText = search.value.toLowerCase();
|
||||||
|
|
||||||
return arrprod.filter((product: IProduct) => {
|
return arrprod.filter((product: IProduct) => {
|
||||||
let lowerName = product.productInfo.name!.toLowerCase()
|
let lowerName = product.productInfo.name!.toLowerCase();
|
||||||
let hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr))
|
let hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr));
|
||||||
return (product.productInfo.code!.includes(search.value) || lowerName.includes(lowerSearchText)) && hasCategoria
|
|
||||||
|
// Use a regular expression to match whole words
|
||||||
|
let codeMatch = new RegExp(`\\b${search.value}\\b`, 'i');
|
||||||
|
let nameMatch = new RegExp(`\\b${lowerSearchText}`, 'i');
|
||||||
|
|
||||||
|
// Check if any word in lowerName starts with lowerSearchText
|
||||||
|
let anyWordStartsWithSearch = lowerName.split(/\s+/).some(word => nameMatch.test(word));
|
||||||
|
|
||||||
|
return (codeMatch.test(product.productInfo.code!) || anyWordStartsWithSearch) && hasCategoria;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -57,10 +65,10 @@ export default defineComponent({
|
|||||||
if (!search.value) {
|
if (!search.value) {
|
||||||
return arrprod
|
return arrprod
|
||||||
}
|
}
|
||||||
|
|
||||||
let lowerSearchText = search.value.toLowerCase();
|
let lowerSearchText = search.value.toLowerCase();
|
||||||
let catstr = cat.value;
|
let catstr = cat.value;
|
||||||
|
|
||||||
return arrprod.filter((product: IProduct) => {
|
return arrprod.filter((product: IProduct) => {
|
||||||
let lowerName = product.productInfo.name!.toLowerCase();
|
let lowerName = product.productInfo.name!.toLowerCase();
|
||||||
const hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr));
|
const hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr));
|
||||||
|
|||||||
@@ -62,6 +62,7 @@
|
|||||||
:dense="tools.isMobile() ? true : false"
|
:dense="tools.isMobile() ? true : false"
|
||||||
:label="t('ecomm.code_o_text_search')"
|
:label="t('ecomm.code_o_text_search')"
|
||||||
v-model="search"
|
v-model="search"
|
||||||
|
debounce="500"
|
||||||
class="q-ml-md"
|
class="q-ml-md"
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
@@ -75,9 +76,9 @@
|
|||||||
:push="cat === reccat.value"
|
:push="cat === reccat.value"
|
||||||
dense
|
dense
|
||||||
:size="tools.isMobile() ? '0.70rem' : '1rem'"
|
:size="tools.isMobile() ? '0.70rem' : '1rem'"
|
||||||
:icon="reccat.icon"
|
:icon="reccat.icon ? reccat.icon : undefined"
|
||||||
:color="reccat.color ? reccat.color : undefined"
|
:color="cat === reccat.value ? 'primary' : undefined"
|
||||||
:text-color="cat === reccat.value ? 'blue' : 'black'"
|
:text-color="cat === reccat.value ? 'white' : 'black'"
|
||||||
rounded
|
rounded
|
||||||
:label="reccat.label"
|
:label="reccat.label"
|
||||||
@click="cat = reccat.value"
|
@click="cat = reccat.value"
|
||||||
|
|||||||
Reference in New Issue
Block a user