- fix RIS in pendenti, se troppi msg, non compariva piu
- cataloghi, ricerca pickup
This commit is contained in:
@@ -11,13 +11,16 @@ import { costanti } from '@costanti'
|
||||
|
||||
import { shared_consts } from '@/common/shared_vuejs'
|
||||
import { CProductCard } from '@src/components/CProductCard'
|
||||
import { CMySelect } from '@src/components/CMySelect'
|
||||
import { CCatalogoCard } from '@src/components/CCatalogoCard'
|
||||
import { CSelectUserActive } from '@src/components/CSelectUserActive'
|
||||
import { IProduct } from '@src/model'
|
||||
import { IProduct, ISearchList } from 'model'
|
||||
|
||||
import { fieldsTable } from '@store/Modules/fieldsTable'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Catalogo',
|
||||
components: { CCatalogoCard, CProductCard, CSelectUserActive },
|
||||
components: { CCatalogoCard, CProductCard, CSelectUserActive, CMySelect },
|
||||
props: {},
|
||||
setup() {
|
||||
const userStore = useUserStore()
|
||||
@@ -28,6 +31,7 @@ export default defineComponent({
|
||||
const { t } = useI18n()
|
||||
|
||||
const search = ref('')
|
||||
const optauthors = ref(<any>[])
|
||||
|
||||
const filter = ref(<any>{
|
||||
author: '',
|
||||
@@ -43,16 +47,27 @@ export default defineComponent({
|
||||
const refreshpage = ref(false)
|
||||
const show_hide = ref(false)
|
||||
|
||||
const mycolumns = ref([])
|
||||
|
||||
const searchList = ref([] as ISearchList[])
|
||||
|
||||
const arrProducts = ref<any>([])
|
||||
|
||||
const numRecLoaded = ref(0)
|
||||
|
||||
|
||||
// Create a ref for the component to fix
|
||||
const componentToFixRef = ref(<any>null);
|
||||
|
||||
const isFixed = ref(false);
|
||||
|
||||
const labelcombo = computed(() => (item: any) => {
|
||||
let lab = item.label
|
||||
if (item.showcount)
|
||||
lab += ' (' + valoriopt.value(item, false, false).length + ')'
|
||||
return lab
|
||||
})
|
||||
|
||||
|
||||
const arrLoaded = computed(() => {
|
||||
if (arrProducts.value && numRecLoaded.value)
|
||||
return arrProducts.value.slice(0, numRecLoaded.value)
|
||||
@@ -86,6 +101,13 @@ export default defineComponent({
|
||||
tools.scrollToTopValue(300)
|
||||
}
|
||||
})
|
||||
watch(() => filter.value.author, (newval, oldval) => {
|
||||
|
||||
calcArrProducts()
|
||||
if (tools.scrollTop() > 300) {
|
||||
tools.scrollToTopValue(300)
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => cosa.value, (newval, oldval) => {
|
||||
tools.setCookie(tools.COOK_COSA_PRODOTTI, cosa.value.toString())
|
||||
@@ -98,21 +120,24 @@ export default defineComponent({
|
||||
// console.log('calcArrProducts')
|
||||
|
||||
refreshpage.value = true
|
||||
let arrprod = productStore.getProducts(cosa.value)
|
||||
let catstr = cat.value;
|
||||
let arrprod = productStore.getProducts(cosa.value) || [];
|
||||
let catstr = cat.value || '';
|
||||
let filtroAuthor = filter.value.author || '';
|
||||
let gasselstr = ''
|
||||
if (cosa.value === shared_consts.PROD.GAS) {
|
||||
gasselstr = idGasSel.value
|
||||
gasselstr = idGasSel.value || '';
|
||||
}
|
||||
let lowerSearchText = search.value.toLowerCase().trim();
|
||||
if ((!lowerSearchText || (lowerSearchText && lowerSearchText.length < 2)) && !catstr && (!gasselstr && (cosa.value !== shared_consts.PROD.GAS))) {
|
||||
let lowerSearchText = (search.value || '').toLowerCase().trim();
|
||||
lowerSearchText = lowerSearchText.replace(/[-@:=]/g, '');
|
||||
if ((!lowerSearchText || (lowerSearchText && lowerSearchText.length < 2)) && !catstr && !filtroAuthor && (!gasselstr && (cosa.value !== shared_consts.PROD.GAS))) {
|
||||
|
||||
} else {
|
||||
|
||||
arrprod = arrprod.filter((product: IProduct) => {
|
||||
if (product && product.productInfo) {
|
||||
let lowerName = product.productInfo.name!.toLowerCase();
|
||||
let hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr));
|
||||
let lowerName = (product.productInfo.name || '').toLowerCase();
|
||||
let hasCategoria = !catstr || (catstr && (product.productInfo.idCatProds || []).includes(catstr));
|
||||
let hasAuthor = !filtroAuthor || (filtroAuthor && (product.productInfo.idAuthors || []).includes(filtroAuthor));
|
||||
|
||||
let productgassel = true
|
||||
if (gasselstr || (cosa.value === shared_consts.PROD.GAS)) {
|
||||
@@ -121,12 +146,15 @@ export default defineComponent({
|
||||
|
||||
// Use a regular expression to match whole words
|
||||
let codeMatch = new RegExp(`\\b${lowerSearchText}\\b`, 'i');
|
||||
let nameMatch = new RegExp(`\\b(?=.*\\b${lowerSearchText.split(/\s+/).map(word => `(${word})\\b`).join('.*\\b')}\\b)`, 'i');
|
||||
// let nameMatch = new RegExp(`\\b(?=.*\\b${lowerSearchText.split(/\s+/).map(word => `(${word})\\b`).join('.*\\b')}\\b)`, 'i');
|
||||
|
||||
// Check if all words in lowerSearchText are present in lowerName
|
||||
let allWordsPresent = lowerSearchText.split(/\s+/).every(word => new RegExp(`\\b${word}\\b`, 'i').test(lowerName));
|
||||
|
||||
return (codeMatch.test(product.productInfo.code!) || allWordsPresent) && hasCategoria && productgassel;
|
||||
return (codeMatch.test(product.productInfo.code || '') || allWordsPresent) && hasCategoria && hasAuthor && productgassel;
|
||||
} else {
|
||||
console.error('product or product.productInfo is null');
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -136,6 +164,7 @@ export default defineComponent({
|
||||
refreshpage.value = false
|
||||
}
|
||||
|
||||
|
||||
/*function getProducts() {
|
||||
let arrprod = productStore.getProducts(cosa.value)
|
||||
if (!search.value) {
|
||||
@@ -155,6 +184,26 @@ export default defineComponent({
|
||||
async function mounted() {
|
||||
loadpage.value = false
|
||||
await productStore.loadProducts()
|
||||
|
||||
mycolumns.value = fieldsTable.getArrColsByTable('products')
|
||||
|
||||
searchList.value = [
|
||||
{
|
||||
label: 'Ricerca',
|
||||
table: 'products',
|
||||
key: 'titolo',
|
||||
type: costanti.FieldType.select_by_server,
|
||||
value: '',
|
||||
addall: true,
|
||||
arrvalue: [],
|
||||
useinput: true,
|
||||
filter: null,
|
||||
tablesel: 'products',
|
||||
},
|
||||
]
|
||||
|
||||
optauthors.value = productStore.getAuthors()
|
||||
|
||||
cosa.value = tools.getCookie(tools.COOK_COSA_PRODOTTI, shared_consts.PROD.GAS, true)
|
||||
if (cosa.value === shared_consts.PROD.TUTTI)
|
||||
cosa.value = shared_consts.PROD.GAS
|
||||
@@ -207,6 +256,42 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
|
||||
function filterFn(val: any, update: any, abort: any) {
|
||||
update(() => {
|
||||
const needle = val.toLowerCase();
|
||||
optauthors.value = productStore.getAuthors().filter(v => {
|
||||
const authorName = v.label.toLowerCase();
|
||||
const wordsToSearch = needle.split(' ');
|
||||
return wordsToSearch.every((word: any) => {
|
||||
if (word.length > 1) {
|
||||
return authorName.includes(word);
|
||||
} else {
|
||||
return authorName.split(' ').some((namePart: any) => namePart.startsWith(word));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function selauthor(id: string, value: string) {
|
||||
filter.value.author = id
|
||||
}
|
||||
|
||||
function searchval(newval: any, table: any, tablesel: any) {
|
||||
console.log('REFRR searchval', newval, table, 'tablesel', tablesel)
|
||||
if (newval === '') {
|
||||
search.value = ''
|
||||
} else {
|
||||
search.value = newval.name
|
||||
}
|
||||
}
|
||||
|
||||
const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean) => {
|
||||
// console.log('valoriopt', item.table)
|
||||
return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter)
|
||||
})
|
||||
|
||||
|
||||
onMounted(mounted)
|
||||
|
||||
return {
|
||||
@@ -232,6 +317,15 @@ export default defineComponent({
|
||||
numRecLoaded,
|
||||
arrLoaded,
|
||||
filter,
|
||||
optauthors,
|
||||
filterFn,
|
||||
selauthor,
|
||||
searchList,
|
||||
fieldsTable,
|
||||
searchval,
|
||||
valoriopt,
|
||||
labelcombo,
|
||||
mycolumns,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -167,21 +167,73 @@
|
||||
></q-toggle>
|
||||
</div>
|
||||
|
||||
<div class="col" v-for="(item, index) in searchList" :key="index">
|
||||
|
||||
<CMySelect
|
||||
:col="fieldsTable.getColByColumns(mycolumns, item.key)"
|
||||
v-if="
|
||||
item.type === costanti.FieldType.select ||
|
||||
item.type === costanti.FieldType.select_by_server
|
||||
"
|
||||
:label="
|
||||
item.value && item.value._id > 0 ? undefined : labelcombo(item)
|
||||
"
|
||||
v-model:value="item.value"
|
||||
@update:value="searchval(item.value, item.table, tablesel)"
|
||||
:addall="item.addall"
|
||||
:addnone="item.addnone"
|
||||
:addlast="true"
|
||||
:tablesel="
|
||||
item.type === costanti.FieldType.select_by_server
|
||||
? item.tablesel
|
||||
: ''
|
||||
"
|
||||
:pickup="item.type === costanti.FieldType.select_by_server"
|
||||
:label-color="$q.dark.isActive ? 'white' : 'black'"
|
||||
myclass="comboselector"
|
||||
color="primary"
|
||||
|
||||
:dense="true"
|
||||
:icon_alternative="item.icon"
|
||||
:optval="fieldsTable.getKeyByTable(item.table)"
|
||||
:optlab="fieldsTable.getLabelByTable(item.table)"
|
||||
:options="valoriopt(item, false)"
|
||||
:filter="item.filter"
|
||||
:filter_extra="item.filter_extra"
|
||||
style="font-size: 0.8rem !important"
|
||||
:useinput="
|
||||
item.useinput &&
|
||||
item.type !== costanti.FieldType.select_by_server
|
||||
"
|
||||
>
|
||||
</CMySelect>
|
||||
</div>
|
||||
|
||||
<q-toolbar>
|
||||
<q-input
|
||||
v-model="search"
|
||||
debounce="300"
|
||||
placeholder="Cerca libri..."
|
||||
dense
|
||||
/>
|
||||
<q-select
|
||||
class="full-width"
|
||||
v-model="filter.author"
|
||||
:options="authors"
|
||||
:options="optauthors"
|
||||
label="Autore"
|
||||
placeholder="Tutti"
|
||||
dense
|
||||
/>
|
||||
<q-select
|
||||
emit-value
|
||||
map-options
|
||||
use-input
|
||||
hide-selected
|
||||
fill-input
|
||||
stack-label
|
||||
filled
|
||||
@filter="filterFn"
|
||||
>
|
||||
<template v-slot:append>
|
||||
<q-icon
|
||||
v-if="filter.author !== ''"
|
||||
class="cursor-pointer"
|
||||
name="clear"
|
||||
@click.stop.prevent="filter.author = ''"
|
||||
/> </template
|
||||
></q-select>
|
||||
<!--<q-select
|
||||
v-model="filter.publisher"
|
||||
:options="publishers"
|
||||
label="Editore"
|
||||
@@ -201,7 +253,7 @@
|
||||
label="Fascia d'età"
|
||||
placeholder="Tutte"
|
||||
dense
|
||||
/>
|
||||
/>-->
|
||||
</q-toolbar>
|
||||
|
||||
<div class="row justify-around">
|
||||
@@ -237,6 +289,7 @@
|
||||
quante_col: 'c2',
|
||||
in_3d: false,
|
||||
}"
|
||||
@selauthor="selauthor"
|
||||
/>
|
||||
<CProductCard
|
||||
v-else-if="product.active || show_hide"
|
||||
|
||||
Reference in New Issue
Block a user