- aggiornamento Cataloghi
- Gestione delle versioni del prodotto ("Nuovi","Usati","Epub", ecc..)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { defineComponent, onMounted, ref, watch, computed, onBeforeUnmount } from 'vue'
|
||||
import { defineComponent, onMounted, ref, watch, computed, onBeforeUnmount, PropType } from 'vue'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useRouter } from 'vue-router'
|
||||
@@ -12,17 +12,30 @@ 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 { CContainerCatalogoCard } from '@src/components/CContainerCatalogoCard'
|
||||
import { CSelectUserActive } from '@src/components/CSelectUserActive'
|
||||
import { IProduct, ISearchList } from 'model'
|
||||
import { ICatalogo, IProduct, ISearchList } from 'model'
|
||||
|
||||
import { fieldsTable } from '@store/Modules/fieldsTable'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Catalogo',
|
||||
components: { CCatalogoCard, CProductCard, CSelectUserActive, CMySelect },
|
||||
props: {},
|
||||
setup() {
|
||||
components: { CContainerCatalogoCard, CProductCard, CSelectUserActive, CMySelect },
|
||||
props: {
|
||||
optcatalogo: {
|
||||
type: Object as PropType<ICatalogo>,
|
||||
required: false,
|
||||
default: () => ({
|
||||
//++AddCATALOGO_FIELDS
|
||||
productTypes: [0],
|
||||
excludeproductTypes: [],
|
||||
formato: [],
|
||||
Categoria: [],
|
||||
Editore: [],
|
||||
}),
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const productStore = useProducts()
|
||||
@@ -49,6 +62,8 @@ export default defineComponent({
|
||||
|
||||
const mycolumns = ref([])
|
||||
|
||||
const tabvisu = ref('categorie')
|
||||
|
||||
const searchList = ref([] as ISearchList[])
|
||||
|
||||
const arrProducts = ref<any>([])
|
||||
@@ -67,13 +82,6 @@ export default defineComponent({
|
||||
return lab
|
||||
})
|
||||
|
||||
const getlist = computed(() => {
|
||||
const mylist = searchList.value.find((rec: any) => rec.table === 'products')
|
||||
|
||||
return mylist
|
||||
})
|
||||
|
||||
|
||||
const arrLoaded = computed(() => {
|
||||
if (arrProducts.value && numRecLoaded.value)
|
||||
return arrProducts.value.slice(0, numRecLoaded.value)
|
||||
@@ -96,8 +104,8 @@ export default defineComponent({
|
||||
watch(() => cat.value, (newval, oldval) => {
|
||||
|
||||
if (cat.value) {
|
||||
filter.value.author = '' // disattivo il filtro autore
|
||||
search.value = '' // disattivo anche la ricerca per testo
|
||||
filter.value.author = '' // disattivo il filtro autore
|
||||
resetSearch()
|
||||
}
|
||||
|
||||
calcArrProducts()
|
||||
@@ -107,7 +115,7 @@ export default defineComponent({
|
||||
calcArrProducts()
|
||||
})
|
||||
|
||||
watch(() => search.value, (newval, oldval) => {
|
||||
watch(() => getSearchText(), (newval, oldval) => {
|
||||
calcArrProducts()
|
||||
if (tools.scrollTop() > 300) {
|
||||
tools.scrollToTopValue(300)
|
||||
@@ -118,7 +126,7 @@ export default defineComponent({
|
||||
// Se filtroAuthor attivato, allora evito il filtro per Categoria
|
||||
if (filter.value.author) {
|
||||
cat.value = '' // disattivo il filtro categoria
|
||||
search.value = '' // disattivo anche la ricerca per testo
|
||||
resetSearch()
|
||||
}
|
||||
|
||||
calcArrProducts()
|
||||
@@ -134,22 +142,52 @@ export default defineComponent({
|
||||
calcArrProducts()
|
||||
})
|
||||
|
||||
function resetSearch() {
|
||||
const mialista = getSearchList()
|
||||
if (mialista && mialista.value && mialista.value.hasOwnProperty('name')) {
|
||||
mialista.value = null
|
||||
}
|
||||
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 : ''
|
||||
}
|
||||
|
||||
function calcArrProducts() {
|
||||
// console.log('calcArrProducts')
|
||||
|
||||
const searchtext = getSearchText()
|
||||
|
||||
refreshpage.value = true
|
||||
let arrprod = productStore.getProducts(cosa.value) || [];
|
||||
let filtroAuthor = filter.value.author || '';
|
||||
|
||||
let catstr = cat.value || '';
|
||||
//++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
|
||||
|
||||
//console.log('filtroVersione', filtroProductTypes)
|
||||
|
||||
let catstr = cat.value || ''
|
||||
|
||||
let gasselstr = ''
|
||||
if (cosa.value === shared_consts.PROD.GAS) {
|
||||
gasselstr = idGasSel.value || '';
|
||||
}
|
||||
let lowerSearchText = (search.value || '').toLowerCase().trim();
|
||||
let lowerSearchText = (searchtext || '').toLowerCase().trim();
|
||||
lowerSearchText = lowerSearchText.replace(/[-@:=]/g, '');
|
||||
if ((!lowerSearchText || (lowerSearchText && lowerSearchText.length < 2)) && !catstr && !filtroAuthor && (!gasselstr && (cosa.value !== shared_consts.PROD.GAS))) {
|
||||
if ((!lowerSearchText || (lowerSearchText && lowerSearchText.length < 2)) && !catstr && boolfiltroVuotoProductTypes && boolfiltroVuotoExcludeProductTypes && !filtroAuthor && (!gasselstr && (cosa.value !== shared_consts.PROD.GAS))) {
|
||||
|
||||
} else {
|
||||
|
||||
@@ -159,6 +197,21 @@ export default defineComponent({
|
||||
let hasCategoria = !catstr || (catstr && (product.productInfo.idCatProds || []).includes(catstr));
|
||||
let hasAuthor = !filtroAuthor || (filtroAuthor && (product.productInfo.idAuthors || []).includes(filtroAuthor));
|
||||
|
||||
let hasProductTypes = true
|
||||
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)))
|
||||
}
|
||||
|
||||
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)))
|
||||
}
|
||||
|
||||
let productgassel = true
|
||||
if (gasselstr || (cosa.value === shared_consts.PROD.GAS)) {
|
||||
productgassel = (product.idGasordine === gasselstr)
|
||||
@@ -171,7 +224,7 @@ export default defineComponent({
|
||||
// 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 && hasAuthor && productgassel;
|
||||
return (codeMatch.test(product.productInfo.code || '') || allWordsPresent) && hasCategoria && hasAuthor && productgassel && hasProductTypes && !hasExcludeProductTypes;
|
||||
} else {
|
||||
console.error('product or product.productInfo is null');
|
||||
return false;
|
||||
@@ -214,7 +267,7 @@ export default defineComponent({
|
||||
key: 'titolo',
|
||||
type: costanti.FieldType.select_by_server,
|
||||
value: '',
|
||||
addall: true,
|
||||
// addall: true,
|
||||
arrvalue: [],
|
||||
useinput: true,
|
||||
filter: null,
|
||||
@@ -224,9 +277,12 @@ export default defineComponent({
|
||||
|
||||
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
|
||||
//++Todo: Per ora visualizzo solo il "Negozio" e non i GAS...
|
||||
cosa.value = shared_consts.PROD.BOTTEGA
|
||||
|
||||
//cosa.value = tools.getCookie(tools.COOK_COSA_PRODOTTI, shared_consts.PROD.GAS, true)
|
||||
//if (cosa.value === shared_consts.PROD.TUTTI)
|
||||
|
||||
|
||||
// Inizializza
|
||||
loadpage.value = true
|
||||
@@ -297,14 +353,16 @@ export default defineComponent({
|
||||
filter.value.author = id
|
||||
}
|
||||
|
||||
function searchval(newval: any, table: any, tablesel: any) {
|
||||
/*function searchval(newval: any, table: any, tablesel: any) {
|
||||
console.log('REFRR searchval', newval, table, 'tablesel', tablesel)
|
||||
if (newval === '') {
|
||||
search.value = ''
|
||||
if (newval) {
|
||||
if (newval.hasOwnProperty('name')) {
|
||||
search.value = newval.name
|
||||
}
|
||||
} else {
|
||||
search.value = newval.name
|
||||
resetSearch()
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean) => {
|
||||
// console.log('valoriopt', item.table)
|
||||
@@ -342,10 +400,10 @@ export default defineComponent({
|
||||
selauthor,
|
||||
searchList,
|
||||
fieldsTable,
|
||||
searchval,
|
||||
valoriopt,
|
||||
labelcombo,
|
||||
mycolumns,
|
||||
tabvisu,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user