2024-06-20 17:22:46 +02:00
|
|
|
import { defineComponent, onMounted, ref, watch, computed, onBeforeUnmount, PropType } from 'vue'
|
2024-01-30 14:00:48 +01:00
|
|
|
import { tools } from '@store/Modules/tools'
|
|
|
|
|
import { useUserStore } from '@store/UserStore'
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore'
|
|
|
|
|
import { useProducts } from '@store/Products'
|
|
|
|
|
import { useI18n } from '@/boot/i18n'
|
|
|
|
|
import { toolsext } from '@store/Modules/toolsext'
|
|
|
|
|
import { useQuasar } from 'quasar'
|
|
|
|
|
import { costanti } from '@costanti'
|
|
|
|
|
|
|
|
|
|
import { shared_consts } from '@/common/shared_vuejs'
|
|
|
|
|
import { CProductCard } from '@src/components/CProductCard'
|
2024-05-09 23:36:58 +02:00
|
|
|
import { CMySelect } from '@src/components/CMySelect'
|
2024-06-20 17:22:46 +02:00
|
|
|
import { CContainerCatalogoCard } from '@src/components/CContainerCatalogoCard'
|
2024-01-30 14:00:48 +01:00
|
|
|
import { CSelectUserActive } from '@src/components/CSelectUserActive'
|
2024-06-20 17:22:46 +02:00
|
|
|
import { ICatalogo, IProduct, ISearchList } from 'model'
|
2024-05-09 23:36:58 +02:00
|
|
|
|
2024-07-31 15:02:30 +02:00
|
|
|
import html2canvas from 'html2canvas'
|
|
|
|
|
// import { VueHtmlToPaper } from 'vue-html-to-paper'
|
|
|
|
|
import html2pdf from 'html2pdf.js'
|
|
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
import { fieldsTable } from '@store/Modules/fieldsTable'
|
2024-01-30 14:00:48 +01:00
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'Catalogo',
|
2024-06-20 17:22:46 +02:00
|
|
|
components: { CContainerCatalogoCard, CProductCard, CSelectUserActive, CMySelect },
|
2024-07-03 13:22:57 +02:00
|
|
|
props: {
|
2024-06-20 17:22:46 +02:00
|
|
|
optcatalogo: {
|
|
|
|
|
type: Object as PropType<ICatalogo>,
|
|
|
|
|
required: false,
|
|
|
|
|
default: () => ({
|
|
|
|
|
//++AddCATALOGO_FIELDS
|
|
|
|
|
productTypes: [0],
|
|
|
|
|
excludeproductTypes: [],
|
|
|
|
|
formato: [],
|
|
|
|
|
Categoria: [],
|
|
|
|
|
Editore: [],
|
2024-07-31 15:02:30 +02:00
|
|
|
pdf: false,
|
2024-06-20 17:22:46 +02:00
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
setup(props) {
|
2024-01-30 14:00:48 +01:00
|
|
|
const userStore = useUserStore()
|
|
|
|
|
const globalStore = useGlobalStore()
|
|
|
|
|
const productStore = useProducts()
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const $q = useQuasar()
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
|
|
const search = ref('')
|
2024-05-09 23:36:58 +02:00
|
|
|
const optauthors = ref(<any>[])
|
2024-05-08 16:07:42 +02:00
|
|
|
|
2024-07-31 15:02:30 +02:00
|
|
|
const pdfContent = ref(null);
|
|
|
|
|
|
|
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
const filter = ref(<any>{
|
|
|
|
|
author: '',
|
2024-07-03 13:22:57 +02:00
|
|
|
sort: 1,
|
2024-05-04 14:49:09 +02:00
|
|
|
publisher: '',
|
|
|
|
|
type: '',
|
|
|
|
|
ageGroup: ''
|
|
|
|
|
})
|
2024-01-30 14:00:48 +01:00
|
|
|
|
|
|
|
|
const cosa = ref(0)
|
|
|
|
|
const cat = ref('')
|
2024-05-04 14:49:09 +02:00
|
|
|
const idGasSel = ref('')
|
2024-01-30 14:00:48 +01:00
|
|
|
const loadpage = ref(false)
|
|
|
|
|
const refreshpage = ref(false)
|
2024-05-04 14:49:09 +02:00
|
|
|
const show_hide = ref(false)
|
2024-01-30 14:00:48 +01:00
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
const mycolumns = ref([])
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
const tabvisu = ref('categorie')
|
|
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
const searchList = ref([] as ISearchList[])
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
const arrProducts = ref<any>([])
|
|
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
const numRecLoaded = ref(0)
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
// Create a ref for the component to fix
|
|
|
|
|
const componentToFixRef = ref(<any>null);
|
|
|
|
|
|
|
|
|
|
const isFixed = ref(false);
|
|
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
const labelcombo = computed(() => (item: any) => {
|
|
|
|
|
let lab = item.label
|
|
|
|
|
if (item.showcount)
|
|
|
|
|
lab += ' (' + valoriopt.value(item, false, false).length + ')'
|
|
|
|
|
return lab
|
|
|
|
|
})
|
|
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
const arrLoaded = computed(() => {
|
|
|
|
|
if (arrProducts.value && numRecLoaded.value)
|
|
|
|
|
return arrProducts.value.slice(0, numRecLoaded.value)
|
|
|
|
|
else {
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
// Register the scroll event on component mount
|
|
|
|
|
const handleScroll = () => {
|
|
|
|
|
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
|
|
|
|
|
|
|
|
// Set a threshold value based on how much scroll is needed to fix the components
|
|
|
|
|
const threshold = 300;
|
|
|
|
|
|
|
|
|
|
// Update the isFixed ref based on the scroll position
|
|
|
|
|
isFixed.value = scrollTop > threshold;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
watch(() => cat.value, (newval, oldval) => {
|
2024-06-19 00:21:06 +02:00
|
|
|
|
|
|
|
|
if (cat.value) {
|
2024-07-31 15:02:30 +02:00
|
|
|
if (loadpage.value)
|
|
|
|
|
tools.setCookie(tools.COOK_CATEGORIA, cat.value.toString())
|
2024-06-20 17:22:46 +02:00
|
|
|
filter.value.author = '' // disattivo il filtro autore
|
|
|
|
|
resetSearch()
|
2024-06-19 00:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
calcArrProducts()
|
|
|
|
|
})
|
2024-05-04 14:49:09 +02:00
|
|
|
|
|
|
|
|
watch(() => idGasSel.value, (newval, oldval) => {
|
|
|
|
|
calcArrProducts()
|
|
|
|
|
})
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
watch(() => getSearchText(), (newval, oldval) => {
|
2024-01-30 14:00:48 +01:00
|
|
|
calcArrProducts()
|
|
|
|
|
if (tools.scrollTop() > 300) {
|
|
|
|
|
tools.scrollToTopValue(300)
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-05-09 23:36:58 +02:00
|
|
|
watch(() => filter.value.author, (newval, oldval) => {
|
|
|
|
|
|
2024-06-19 00:21:06 +02:00
|
|
|
// Se filtroAuthor attivato, allora evito il filtro per Categoria
|
|
|
|
|
if (filter.value.author) {
|
|
|
|
|
cat.value = '' // disattivo il filtro categoria
|
2024-07-31 15:02:30 +02:00
|
|
|
if (loadpage.value)
|
|
|
|
|
tools.setCookie(tools.COOK_CATEGORIA, '')
|
2024-06-20 17:22:46 +02:00
|
|
|
resetSearch()
|
2024-06-19 00:21:06 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
calcArrProducts()
|
|
|
|
|
if (tools.scrollTop() > 300) {
|
|
|
|
|
tools.scrollToTopValue(300)
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-01-30 14:00:48 +01:00
|
|
|
|
2024-07-03 13:22:57 +02:00
|
|
|
watch(() => filter.value.sort, (newval, oldval) => {
|
|
|
|
|
|
|
|
|
|
calcArrProducts()
|
|
|
|
|
if (tools.scrollTop() > 300) {
|
|
|
|
|
tools.scrollToTopValue(300)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
watch(() => cosa.value, (newval, oldval) => {
|
2024-07-31 15:02:30 +02:00
|
|
|
if (oldval !== 0) {
|
|
|
|
|
tools.setCookie(tools.COOK_COSA_PRODOTTI, cosa.value.toString())
|
|
|
|
|
if (cosa.value !== shared_consts.PROD.TUTTI) {
|
|
|
|
|
cat.value = ''
|
|
|
|
|
if (loadpage.value)
|
|
|
|
|
tools.setCookie(tools.COOK_CATEGORIA, '')
|
|
|
|
|
}
|
|
|
|
|
calcArrProducts()
|
|
|
|
|
}
|
2024-01-30 14:00:48 +01:00
|
|
|
})
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
function resetSearch() {
|
|
|
|
|
const mialista = getSearchList()
|
|
|
|
|
if (mialista && mialista.value && mialista.value.hasOwnProperty('name')) {
|
|
|
|
|
mialista.value = null
|
2024-07-03 13:22:57 +02:00
|
|
|
}
|
2024-06-20 17:22:46 +02:00
|
|
|
search.value = ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSearchList() {
|
|
|
|
|
const mylist = searchList.value.find((rec: any) => rec.table === 'products' && rec.key === 'titolo')
|
|
|
|
|
|
|
|
|
|
return mylist
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getSearchText(): string {
|
|
|
|
|
const lista = getSearchList()
|
|
|
|
|
return lista && lista.value && lista.value.hasOwnProperty('name') ? lista.value.name : ''
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
function calcArrProducts() {
|
2024-05-04 14:49:09 +02:00
|
|
|
// console.log('calcArrProducts')
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
const searchtext = getSearchText()
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
refreshpage.value = true
|
2024-05-09 23:36:58 +02:00
|
|
|
let arrprod = productStore.getProducts(cosa.value) || [];
|
|
|
|
|
let filtroAuthor = filter.value.author || '';
|
2024-06-19 00:21:06 +02:00
|
|
|
|
2024-07-03 13:22:57 +02:00
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
//++AddCATALOGO_FIELDS
|
|
|
|
|
|
|
|
|
|
let filtroProductTypes = props.optcatalogo.productTypes || [0]
|
|
|
|
|
let filtroExcludeProductTypes = props.optcatalogo.excludeproductTypes || [0]
|
|
|
|
|
let boolfiltroVuotoProductTypes = (filtroProductTypes.length === 0 || (filtroProductTypes.length === 1 && (filtroProductTypes[0] === 0)))
|
|
|
|
|
let boolfiltroVuotoExcludeProductTypes = filtroExcludeProductTypes.length === 0
|
|
|
|
|
|
2024-07-03 13:22:57 +02:00
|
|
|
let filtroPublishers = props.optcatalogo.Editore || []
|
|
|
|
|
let boolfiltroVuotoEditore = (filtroPublishers.length === 0)
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
//console.log('filtroVersione', filtroProductTypes)
|
|
|
|
|
|
|
|
|
|
let catstr = cat.value || ''
|
2024-06-19 00:21:06 +02:00
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
let gasselstr = ''
|
|
|
|
|
if (cosa.value === shared_consts.PROD.GAS) {
|
2024-05-09 23:36:58 +02:00
|
|
|
gasselstr = idGasSel.value || '';
|
2024-05-04 14:49:09 +02:00
|
|
|
}
|
2024-06-20 17:22:46 +02:00
|
|
|
let lowerSearchText = (searchtext || '').toLowerCase().trim();
|
2024-05-09 23:36:58 +02:00
|
|
|
lowerSearchText = lowerSearchText.replace(/[-@:=]/g, '');
|
2024-07-03 13:22:57 +02:00
|
|
|
if ((!lowerSearchText || (lowerSearchText && lowerSearchText.length < 2)) && !catstr && boolfiltroVuotoProductTypes && boolfiltroVuotoExcludeProductTypes && boolfiltroVuotoEditore && !filtroAuthor && (!gasselstr && (cosa.value !== shared_consts.PROD.GAS))) {
|
2024-01-30 14:00:48 +01:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
arrprod = arrprod.filter((product: IProduct) => {
|
2024-05-04 14:49:09 +02:00
|
|
|
if (product && product.productInfo) {
|
2024-05-09 23:36:58 +02:00
|
|
|
let lowerName = (product.productInfo.name || '').toLowerCase();
|
|
|
|
|
let hasCategoria = !catstr || (catstr && (product.productInfo.idCatProds || []).includes(catstr));
|
|
|
|
|
let hasAuthor = !filtroAuthor || (filtroAuthor && (product.productInfo.idAuthors || []).includes(filtroAuthor));
|
2024-05-04 14:49:09 +02:00
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
let hasProductTypes = true
|
2024-07-03 13:22:57 +02:00
|
|
|
let hasPublished = true
|
2024-06-20 17:22:46 +02:00
|
|
|
let hasExcludeProductTypes = false
|
|
|
|
|
|
|
|
|
|
//++AddCATALOGO_FIELDS
|
|
|
|
|
|
|
|
|
|
if (props.optcatalogo && !boolfiltroVuotoProductTypes) {
|
|
|
|
|
// check if productInfo.productTypes array includes some item in props.optcatalogo.ProductTypes array
|
|
|
|
|
hasProductTypes = !props.optcatalogo.productTypes || (props.optcatalogo.productTypes && (product.productInfo.productTypes || []).some((item: any) => props.optcatalogo.productTypes.includes(item)))
|
|
|
|
|
}
|
2024-07-03 13:22:57 +02:00
|
|
|
if (props.optcatalogo && !boolfiltroVuotoEditore) {
|
|
|
|
|
hasPublished = !props.optcatalogo.Editore || (props.optcatalogo.Editore && props.optcatalogo.Editore.includes(product.productInfo.idPublisher!))
|
|
|
|
|
}
|
2024-06-20 17:22:46 +02:00
|
|
|
|
|
|
|
|
if (props.optcatalogo && !boolfiltroVuotoExcludeProductTypes) {
|
|
|
|
|
// check if productInfo.productTypes array exclude some item in props.optcatalogo.ProductTypes array
|
|
|
|
|
hasExcludeProductTypes = !props.optcatalogo.excludeproductTypes || (props.optcatalogo.excludeproductTypes && (product.productInfo.productTypes || []).every((item: any) => props.optcatalogo.excludeproductTypes.includes(item)))
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
let productgassel = true
|
|
|
|
|
if (gasselstr || (cosa.value === shared_consts.PROD.GAS)) {
|
|
|
|
|
productgassel = (product.idGasordine === gasselstr)
|
|
|
|
|
}
|
2024-01-30 14:00:48 +01:00
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
// Use a regular expression to match whole words
|
|
|
|
|
let codeMatch = new RegExp(`\\b${lowerSearchText}\\b`, 'i');
|
2024-05-09 23:36:58 +02:00
|
|
|
// let nameMatch = new RegExp(`\\b(?=.*\\b${lowerSearchText.split(/\s+/).map(word => `(${word})\\b`).join('.*\\b')}\\b)`, 'i');
|
2024-01-30 14:00:48 +01:00
|
|
|
|
2024-05-08 16:07:42 +02:00
|
|
|
// 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));
|
2024-01-30 14:00:48 +01:00
|
|
|
|
2024-07-03 13:22:57 +02:00
|
|
|
return (codeMatch.test(product.productInfo.code || '') || allWordsPresent) && hasCategoria && hasAuthor && productgassel && hasProductTypes && hasPublished && !hasExcludeProductTypes;
|
2024-05-09 23:36:58 +02:00
|
|
|
} else {
|
|
|
|
|
console.error('product or product.productInfo is null');
|
|
|
|
|
return false;
|
2024-05-04 14:49:09 +02:00
|
|
|
}
|
2024-01-30 14:00:48 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-03 13:22:57 +02:00
|
|
|
console.log('filter.value.sort', filter.value.sort)
|
|
|
|
|
// sort using filter.value.sort :
|
|
|
|
|
if (filter.value.sort === costanti.SORT_PUBDATE) {
|
|
|
|
|
|
|
|
|
|
arrprod = arrprod.sort((a: IProduct, b: IProduct) => {
|
|
|
|
|
return b.productInfo.date_publishing_ts - a.productInfo.date_publishing_ts
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
} else if (filter.value.sort === costanti.SORT_ALPHA) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
arrProducts.value = arrprod
|
2024-05-04 14:49:09 +02:00
|
|
|
loaddata()
|
2024-01-30 14:00:48 +01:00
|
|
|
refreshpage.value = false
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
/*function getProducts() {
|
|
|
|
|
let arrprod = productStore.getProducts(cosa.value)
|
|
|
|
|
if (!search.value) {
|
|
|
|
|
return arrprod
|
|
|
|
|
}
|
2024-07-31 15:02:30 +02:00
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
let lowerSearchText = search.value.toLowerCase();
|
|
|
|
|
let catstr = cat.value;
|
2024-07-31 15:02:30 +02:00
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
return arrprod.filter((product: IProduct) => {
|
|
|
|
|
let lowerName = product.productInfo.name!.toLowerCase();
|
|
|
|
|
const hasCategoria = !catstr || (catstr && product.productInfo.idCatProds?.includes(catstr));
|
|
|
|
|
return (product.productInfo.code!.includes(search.value) || lowerName.includes(lowerSearchText)) && hasCategoria
|
|
|
|
|
});
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
async function mounted() {
|
|
|
|
|
loadpage.value = false
|
|
|
|
|
await productStore.loadProducts()
|
2024-05-09 23:36:58 +02:00
|
|
|
|
|
|
|
|
mycolumns.value = fieldsTable.getArrColsByTable('products')
|
|
|
|
|
|
|
|
|
|
searchList.value = [
|
|
|
|
|
{
|
|
|
|
|
label: 'Ricerca',
|
|
|
|
|
table: 'products',
|
|
|
|
|
key: 'titolo',
|
|
|
|
|
type: costanti.FieldType.select_by_server,
|
|
|
|
|
value: '',
|
2024-06-20 17:22:46 +02:00
|
|
|
// addall: true,
|
2024-05-09 23:36:58 +02:00
|
|
|
arrvalue: [],
|
|
|
|
|
useinput: true,
|
|
|
|
|
filter: null,
|
|
|
|
|
tablesel: 'products',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
optauthors.value = productStore.getAuthors()
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
//++Todo: Per ora visualizzo solo il "Negozio" e non i GAS...
|
|
|
|
|
cosa.value = shared_consts.PROD.BOTTEGA
|
|
|
|
|
|
2024-07-31 15:02:30 +02:00
|
|
|
cat.value = tools.getCookie(tools.COOK_CATEGORIA, '')
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
//cosa.value = tools.getCookie(tools.COOK_COSA_PRODOTTI, shared_consts.PROD.GAS, true)
|
|
|
|
|
//if (cosa.value === shared_consts.PROD.TUTTI)
|
|
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
// Inizializza
|
|
|
|
|
loadpage.value = true
|
|
|
|
|
window.addEventListener('scroll', handleScroll);
|
|
|
|
|
|
|
|
|
|
calcArrProducts()
|
2024-05-04 14:49:09 +02:00
|
|
|
|
|
|
|
|
loaddata()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loaddata() {
|
|
|
|
|
numRecLoaded.value = 20
|
2024-01-30 14:00:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove the event listener on component destroy
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
window.removeEventListener('scroll', handleScroll);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function getCatProds() {
|
|
|
|
|
let arrcat = productStore.getCatProds(cosa.value)
|
|
|
|
|
let riscat: any = [{ label: 'Tutti', value: '', icon: undefined, color: undefined }]
|
|
|
|
|
for (const rec of arrcat) {
|
|
|
|
|
riscat.push({ label: rec.name, value: rec._id, icon: rec.icon, color: rec.color })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return riscat
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-04 14:49:09 +02:00
|
|
|
|
|
|
|
|
function onLoadScroll(index: number, done: any) {
|
|
|
|
|
if (index >= 1) {
|
|
|
|
|
if (numRecLoaded.value < arrProducts.value.length) {
|
|
|
|
|
|
|
|
|
|
const step = 10
|
|
|
|
|
let mynrec = numRecLoaded.value + step
|
|
|
|
|
|
|
|
|
|
if (mynrec > arrProducts.value.length)
|
|
|
|
|
mynrec = arrProducts.value.length
|
|
|
|
|
|
|
|
|
|
numRecLoaded.value = mynrec
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
done()
|
|
|
|
|
} else {
|
|
|
|
|
done(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-09 23:36:58 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-20 17:22:46 +02:00
|
|
|
/*function searchval(newval: any, table: any, tablesel: any) {
|
2024-05-09 23:36:58 +02:00
|
|
|
console.log('REFRR searchval', newval, table, 'tablesel', tablesel)
|
2024-06-20 17:22:46 +02:00
|
|
|
if (newval) {
|
|
|
|
|
if (newval.hasOwnProperty('name')) {
|
|
|
|
|
search.value = newval.name
|
|
|
|
|
}
|
2024-06-19 00:21:06 +02:00
|
|
|
} else {
|
2024-06-20 17:22:46 +02:00
|
|
|
resetSearch()
|
2024-05-09 23:36:58 +02:00
|
|
|
}
|
2024-06-20 17:22:46 +02:00
|
|
|
}*/
|
2024-05-09 23:36:58 +02:00
|
|
|
|
|
|
|
|
const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean) => {
|
|
|
|
|
// console.log('valoriopt', item.table)
|
|
|
|
|
return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter)
|
|
|
|
|
})
|
|
|
|
|
|
2024-07-31 15:02:30 +02:00
|
|
|
const loadImage = (src) => {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const img = new Image()
|
|
|
|
|
img.onload = () => resolve(img)
|
|
|
|
|
img.onerror = reject
|
|
|
|
|
img.src = src
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const generatePDF = async () => {
|
|
|
|
|
$q.loading.show({
|
|
|
|
|
message: 'Caricamento immagini e generazione PDF in corso...'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
const element = document.getElementById('pdf-content')
|
|
|
|
|
const opt = {
|
|
|
|
|
margin: 1,
|
|
|
|
|
filename: 'catalogo_libri.pdf',
|
|
|
|
|
image: { type: 'jpeg', quality: 0.98 },
|
|
|
|
|
html2canvas: { scale: 2, useCORS: true },
|
|
|
|
|
jsPDF: { unit: 'in', format: 'a4', orientation: 'portrait' }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await html2pdf().from(element).set(opt).save()
|
|
|
|
|
|
|
|
|
|
$q.loading.hide()
|
|
|
|
|
$q.notify({
|
|
|
|
|
color: 'positive',
|
|
|
|
|
message: 'PDF generato con successo!',
|
|
|
|
|
icon: 'check'
|
|
|
|
|
})
|
|
|
|
|
} catch (error) {
|
|
|
|
|
$q.loading.hide()
|
|
|
|
|
$q.notify({
|
|
|
|
|
color: 'negative',
|
|
|
|
|
message: 'Errore nella generazione del PDF',
|
|
|
|
|
icon: 'error'
|
|
|
|
|
})
|
|
|
|
|
console.error('Errore nella generazione del PDF:', error)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-09 23:36:58 +02:00
|
|
|
|
2024-01-30 14:00:48 +01:00
|
|
|
onMounted(mounted)
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
userStore,
|
|
|
|
|
costanti,
|
|
|
|
|
tools,
|
|
|
|
|
toolsext,
|
|
|
|
|
search,
|
|
|
|
|
cosa,
|
|
|
|
|
shared_consts,
|
|
|
|
|
getCatProds,
|
|
|
|
|
cat,
|
2024-05-04 14:49:09 +02:00
|
|
|
idGasSel,
|
2024-01-30 14:00:48 +01:00
|
|
|
productStore,
|
|
|
|
|
t,
|
|
|
|
|
loadpage,
|
|
|
|
|
refreshpage,
|
|
|
|
|
componentToFixRef,
|
|
|
|
|
isFixed,
|
|
|
|
|
arrProducts,
|
2024-05-04 14:49:09 +02:00
|
|
|
show_hide,
|
|
|
|
|
onLoadScroll,
|
|
|
|
|
numRecLoaded,
|
|
|
|
|
arrLoaded,
|
|
|
|
|
filter,
|
2024-05-09 23:36:58 +02:00
|
|
|
optauthors,
|
|
|
|
|
filterFn,
|
|
|
|
|
selauthor,
|
|
|
|
|
searchList,
|
|
|
|
|
fieldsTable,
|
|
|
|
|
valoriopt,
|
|
|
|
|
labelcombo,
|
|
|
|
|
mycolumns,
|
2024-06-20 17:22:46 +02:00
|
|
|
tabvisu,
|
2024-07-03 13:22:57 +02:00
|
|
|
getSearchText,
|
2024-07-31 15:02:30 +02:00
|
|
|
generatePDF,
|
|
|
|
|
pdfContent,
|
2024-01-30 14:00:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|