- aggiunto filtro nella lista producttable

- ora compare il bottone aggiungi alla lista solo se non è presente.
This commit is contained in:
Surya Paolo
2025-06-25 17:48:21 +02:00
parent bfc6ec04f6
commit 99fab39c4b
14 changed files with 162 additions and 66 deletions

View File

@@ -79,7 +79,7 @@ export default defineComponent({
type: Object,
required: false,
default: () => ({}),
}
},
},
setup(props, { emit }) {
// Copia locale della lista_prodotti per manipolazione interna
@@ -91,6 +91,8 @@ export default defineComponent({
const $q = useQuasar();
const searchText = ref('');
const arrordersCart = ref(<IOrderCart[]>[]);
const globalStore = useGlobalStore();
@@ -149,6 +151,10 @@ export default defineComponent({
),
{ deep: true };
watch(() => searchText.value, () => {
searchProducts();
});
const allColumns = ref([]);
const isVisibleEditBtn = ref(false);
@@ -874,7 +880,14 @@ export default defineComponent({
function isEditColumn(name: string): boolean {
const column = allColumns.value.find((col) => col.name === name);
return column ? column.edit : false;
};
}
const faiConfronto = () => {
return (
Array.isArray(props.lista_prod_confronto) &&
props.lista_prod_confronto.length > 0
);
}
// 3. Funzione per verificare se una colonna è visibile (isColumnVisible)
const isColumnVisible = (column: string, real?: boolean, element?: any) => {
@@ -891,20 +904,40 @@ export default defineComponent({
(!props.optcatalogo.showListaArgomenti ||
(props.optcatalogo.showListaArgomenti && !isEditColumn(column)));
if (props.options?.showbuttAdd && column === 'addtolist'
&& (!element || !props.lista_prod_confronto.some((prod: any) => prod._id === element?._id))
if (
props.options?.showbuttAdd &&
column === 'addtolist' &&
(!element ||
!props.lista_prod_confronto.some((prod: any) => prod._id === element?._id))
) {
if (tools.isCollaboratore())
ok = true
if (tools.isCollaboratore()) ok = true;
}
if (!props.options?.showbuttAdd && column === 'addtolist' && (element && props.lista_prod_confronto.some((prod: any) => prod._id === element?._id))) {
ok = false
if (column === 'addtolist') {
if (!faiConfronto()) {
ok = false
}
}
return selectedColumns.value.includes(column) && ok;
};
function isElementVisible(col: string, element: any) {
let ok = true
if (col === 'addtolist') {
if (
props.options?.showbuttAdd &&
element &&
props.lista_prod_confronto.some((prod: any) => prod._id === element?._id)
) {
ok = false;
}
}
return ok
}
const getColumnLabelByName = (name: string): string => {
const column = allColumns.value.find((col) => col.name === name);
return column ? column.label : '';
@@ -1118,7 +1151,7 @@ export default defineComponent({
}
function addtolist(element) {
emit('addtolist', element)
emit('addtolist', element);
}
function getFieldClick(element: any, field: any): (() => void) | null {
@@ -1242,6 +1275,41 @@ export default defineComponent({
updateProduct(element);
}
function searchProducts() {
console.log('searchProducts');
if (!searchText.value) {
internalProducts.value = [...props.lista_prodotti];
return;
}
// Funzione per "escapare" i caratteri speciali nelle regex
const escapeRegex = (w: any) => {
return w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/#/g, '\\#');
};
// Escape del testo di ricerca per evitare conflitti con caratteri speciali
const searchTextEscaped = escapeRegex(searchText.value.toLowerCase());
const searchRegex = new RegExp(searchTextEscaped, 'i');
internalProducts.value = props.lista_prodotti.filter((prod: any) => {
// Controllo se il titolo corrisponde alla regex
const titleMatch = searchRegex.test(`${prod.productInfo?.name}`);
// Controllo se uno degli autori corrisponde alla regex
const authorMatch =
prod.productInfo?.authors &&
prod.productInfo.authors.some((author: IAuthor) =>
searchRegex.test(`${author.name} ${author.surname}`)
);
// Controllo se il codice corrisponde alla regex
const codeMatch = searchRegex.test(`${prod.productInfo?.code}`);
return titleMatch || authorMatch || codeMatch;
});
}
onMounted(mounted);
return {
@@ -1292,6 +1360,9 @@ export default defineComponent({
addtoCart,
arrordersCart,
addtolist,
searchProducts,
searchText,
isElementVisible,
};
},
});