- Ricerca Titolo per nome o autore o ISBN o codice articolo

This commit is contained in:
Surya Paolo
2025-03-31 23:55:53 +02:00
parent 7624f16723
commit 61c1dc3d0d
67 changed files with 760 additions and 1618 deletions

View File

@@ -14,11 +14,13 @@ import { shared_consts } from '@src/common/shared_vuejs'
import { CProductCard } from '@src/components/CProductCard'
import { CMySelect } from '@src/components/CMySelect'
import { CProductTable } from '@src/components/CProductTable'
import { CContainerCatalogoCard } from '@src/components/CContainerCatalogoCard'
import { CSelectUserActive } from '@src/components/CSelectUserActive'
import type {
IOptCatalogo, IDimensioni, IFilterCatalogo,
IMyScheda, IProdView, IProduct, ISchedaSingola, ISearchList, ICatalog, IImg
IMyScheda, IProdView, IProduct, ISchedaSingola, ISearchList, ICatalog, IImg,
IText
} from 'model';
import {
IMyPage,
@@ -28,10 +30,11 @@ import {
import { fieldsTable } from '@store/Modules/fieldsTable'
import { useCatalogStore } from '@src/store/CatalogStore'
import { Catalogo } from '.';
export default defineComponent({
name: 'Catalogo',
components: { CContainerCatalogoCard, CProductCard, CSelectUserActive, CMySelect },
components: { CContainerCatalogoCard, CProductCard, CSelectUserActive, CMySelect, CProductTable },
emits: ['update:modelValue', 'updateCatalogo'],
props: {
modelValue: {
@@ -98,7 +101,7 @@ export default defineComponent({
const catalogStore = useCatalogStore()
const tabvisu = ref('categorie')
const tabcatalogo = ref('visu')
const tabcatalogo = ref()
const searchList = ref([] as ISearchList[])
@@ -112,6 +115,10 @@ export default defineComponent({
const isFixed = ref(false);
watch(() => tabcatalogo.value, () => {
tools.setCookie('TAB_CAT', tabcatalogo.value)
})
const labelcombo = computed(() => (item: any) => {
let lab = item.label
if (item.showcount)
@@ -150,10 +157,37 @@ export default defineComponent({
})
function getTextSostituito(testo: IText) {
const replacements = {
'{titolo_catalogo}': getTitoloCatalogo() || '',
};
// Esegue le sostituzioni
let result = testo.contenuto;
for (const [key, value] of Object.entries(replacements)) {
result = result.replace(new RegExp(key, 'g'), value);
}
return result
}
const getTitoloPagina = computed(() => (product: IProduct, recscheda: ISchedaSingola) => {
let testo = getTextSostituito(recscheda.scheda!.dimensioni.pagina?.testo_title)
return testo
})
const getCatalogoByMyPage = computed(() => {
return catalogStore.catalogs?.find((catalog: ICatalog) => catalog.idPageAssigned === props.idPage)
})
const lista_prodotti = computed(() => {
const arr = catalogStore.catalogs?.find((catalog: ICatalog) => catalog.idPageAssigned === props.idPage)
return arr?.lista_prodotti
})
const ispageCatalogata = computed(() => {
return !!getCatalogoByMyPage.value
})
@@ -432,13 +466,13 @@ export default defineComponent({
filtroProductTypes: number[],
filtroExcludeProductTypes: number[],
editore: string[],
idCollane: string[],
idCollane: number[],
arrargomstr: any[],
catstr: string,
gasselstr: string,
cosaValue: any,
sortField?: string,
sortDir?: string
sortDir?: number
): IProduct[] {
const lowerSearchTexts = Array.isArray(searchtext)
? searchtext.map((text: string) => text.toLowerCase().trim().replace(/[-@:=]/g, ''))
@@ -449,9 +483,9 @@ export default defineComponent({
const boolfiltroVuotoExcludeProductTypes = filtroExcludeProductTypes.length === 0;
const boolfiltroVuotoEditore = editore.length === 0;
const boolfiltroVuotoCollane = idCollane.length === 0;
const boolfiltroVuotoArgomenti = arrargomstr.length === 0;
// const boolfiltroVuotoArgomenti = arrargomstr.length === 0;
return products
const arrris = products
.filter((product: IProduct) => {
if (!product || !product.productInfo) {
console.error('product or product.productInfo is null');
@@ -512,9 +546,9 @@ export default defineComponent({
productgassel &&
hasProductTypes &&
(
hasPublished ||
hasCollana ||
hasCategoria ||
hasPublished &&
hasCollana &&
hasCategoria &&
hasArgomentiCat
)
&&
@@ -522,11 +556,19 @@ export default defineComponent({
);
})
.sort((a, b) => getProductsSorted([a, b], sortField, sortDir)[0] === a ? -1 : 1);
console.log(' Filtro=' + arrargomstr)
console.log(' idCollane=' + idCollane)
console.log('PRODOTTI FILTRATI:', arrris.length)
return arrris
}
function calcArrProducts() {
function calcArrProducts(generalista?: boolean) {
console.log('calcArrProducts (generalista=' + generalista + ')')
const searchtext = getSearchText();
let arrprod = productStore.getProducts(cosa.value) || [];
let arrprod = [];
const filtroAuthor = filter.value.author || '';
const filtroProductTypes = optcatalogo.value.productTypes || [0];
const filtroExcludeProductTypes = optcatalogo.value.excludeproductTypes || [0];
@@ -540,29 +582,52 @@ export default defineComponent({
const catstr = cat.value || '';
const gasselstr = cosa.value === shared_consts.PROD.GAS ? idGasSel.value || '' : '';
arrprod = filterProducts(
arrprod,
searchtext,
filtroAuthor,
filtroProductTypes,
filtroExcludeProductTypes,
filtroPublishers,
filtroCollane,
arrargomstr,
catstr,
gasselstr,
cosa.value,
filter.value.sort_field,
filter.value.sort_dir
);
let salva = false
// Se nel catalogo è stato già generato, allora gli passo quello.
const trovatocatalogo = getCatalogoByMyPage.value
if (trovatocatalogo.lista_prodotti.length === 0) {
generalista = true
}
if (!generalista && (trovatocatalogo.lista_prodotti.length > 0)) {
arrprod = trovatocatalogo.lista_prodotti
} else {
arrprod = productStore.getProducts(cosa.value)
arrprod = filterProducts(
arrprod,
searchtext,
filtroAuthor,
filtroProductTypes,
filtroExcludeProductTypes,
filtroPublishers,
filtroCollane,
arrargomstr,
catstr,
gasselstr,
cosa.value,
filter.value.sort_field,
filter.value.sort_dir
);
salva = true
}
arrProducts.value = arrprod;
console.log('arrprod', arrprod)
populateDataWithlinkIdTemplate();
generatearrProdToViewSorted();
generatearrProdToViewSorted(!generalista, salva);
loaddata();
refreshpage.value = false;
}
function generaListaLibri() {
calcArrProducts(true)
}
function getProductsFilteredByScheda(scheda: IMyScheda): IProduct[] {
let arrprod = productStore.getProducts(cosa.value) || [];
const filtroAuthor = filter.value.author || '';
@@ -578,21 +643,27 @@ export default defineComponent({
const catstr = cat.value || '';
const gasselstr = cosa.value === shared_consts.PROD.GAS ? idGasSel.value || '' : '';
arrprod = filterProducts(
arrprod,
scheda.arrProdottiSpeciali || [],
filtroAuthor,
filtroProductTypes,
filtroExcludeProductTypes,
filtroPublishers,
filtroCollane,
arrargomstr,
catstr,
gasselstr,
cosa.value,
scheda?.sort_field,
scheda?.sort_dir
);
const trovatocatalogo = getCatalogoByMyPage.value
if (trovatocatalogo.lista_prodotti.length > 0) {
arrprod = trovatocatalogo.lista_prodotti
} else {
arrprod = filterProducts(
arrprod,
scheda.arrProdottiSpeciali || [],
filtroAuthor,
filtroProductTypes,
filtroExcludeProductTypes,
filtroPublishers,
filtroCollane,
arrargomstr,
catstr,
gasselstr,
cosa.value,
scheda?.sort_field,
scheda?.sort_dir
);
}
return arrprod;
}
@@ -671,22 +742,31 @@ export default defineComponent({
}
}
function generatearrProdToViewSorted() {
// console.log('generatearrProdToViewSorted...')
function generatearrProdToViewSorted(usaprodottiSalvati?: boolean, salva?: boolean) {
console.log('generatearrProdToViewSorted... usaprodottiSalvati=', usaprodottiSalvati, ' salva=', salva)
try {
// Svuota
arrProdToView.value = []
// gia filtrati
const arrGeneraleProdotti = arrProducts.value;
const trovatocatalogo = getCatalogoByMyPage.value
let arrGeneraleProdotti = []
if (usaprodottiSalvati) {
} else {
arrGeneraleProdotti = arrProducts.value;
}
let indprod = 0
const indprodGenerale = 0
let indtotale = 0
let arrprod = []
for (const recscheda of optcatalogo.value.arrSchede!) {
if (recscheda && recscheda.scheda) {
const schedePerRiga = recscheda.scheda.numschede_perRiga || 1
@@ -695,17 +775,21 @@ export default defineComponent({
let arrProdFiltrati: IProduct[] = []
if (recscheda.scheda.productTypes!.length > 0) {
// Filtra i prodotti in base ai filtri impostati !
arrProdFiltrati = getProductsFilteredByScheda(recscheda.scheda)
indprod = 0
if (usaprodottiSalvati && trovatocatalogo.lista_prodotti.length > 0) {
arrProdFiltrati = trovatocatalogo.lista_prodotti
} else {
if (recscheda.scheda.sort_field!) {
arrProdFiltrati = getProductsSorted(arrGeneraleProdotti, recscheda.scheda.sort_field, recscheda.scheda.sort_dir);
if (recscheda.scheda.productTypes!.length > 0) {
// Filtra i prodotti in base ai filtri impostati !
arrProdFiltrati = getProductsFilteredByScheda(recscheda.scheda)
indprod = 0
} else {
indprod = indprodGenerale
arrProdFiltrati = arrGeneraleProdotti
if (recscheda.scheda.sort_field!) {
arrProdFiltrati = getProductsSorted(arrGeneraleProdotti, recscheda.scheda.sort_field, recscheda.scheda.sort_dir);
indprod = 0
} else {
indprod = indprodGenerale
arrProdFiltrati = arrGeneraleProdotti
}
}
}
@@ -737,6 +821,8 @@ export default defineComponent({
// console.log('RANKING: ', result.myrec.indiceRanking!)
arrprod.push(result.myrec)
recscheda.arrProdToShow[pagina][riga][col] = result.myrec
indadded++
@@ -772,6 +858,13 @@ export default defineComponent({
// console.log(' FINE - generatearrProdToViewSorted !')
if (!usaprodottiSalvati && salva) {
trovatocatalogo.lista_prodotti = arrprod
salvaListaProdotti(false)
}
} catch (e) {
console.error('Err', e)
}
@@ -779,6 +872,24 @@ export default defineComponent({
// console.log('Fine...')
}
function salvaListaProdotti(ricarica: boolean) {
// Estrai solo gli ID dei prodotti filtrati
const myarr = [...getCatalogoByMyPage.value.lista_prodotti]
const productIds = myarr.map(product => product._id);
let mydata = {
lista_prodotti: productIds
}
// Salva gli ID dei prodotti nel catalogo
tools.saveFieldToServer($q, 'catalogs', getCatalogoByMyPage.value._id, mydata, true, false)
if (ricarica) {
generatearrProdToViewSorted(true, false);
}
}
function getNextProd() {
const nextRecord = arrProdToView.value.find((rec: any) => !rec.showed)
@@ -810,6 +921,9 @@ export default defineComponent({
async function mounted() {
// console.log('mounted Catalogo')
tabcatalogo.value = tools.getCookie('TAB_CAT', 'visu')
loadpage.value = false
await productStore.loadProducts()
@@ -1119,6 +1233,12 @@ export default defineComponent({
router.push(path)
}
function updateProducts(arr: any) {
getCatalogoByMyPage.value.lista_prodotti = [...arr]
salvaListaProdotti(true)
}
onMounted(mounted)
return {
@@ -1174,6 +1294,10 @@ export default defineComponent({
ispageCatalogata,
naviga,
getTitoloCatalogo,
getTitoloPagina,
generaListaLibri,
lista_prodotti,
updateProducts,
}
}
})