- Import di un file XLS contenente una lista di libri, all'interno di un catalogo.
This commit is contained in:
@@ -23,6 +23,7 @@ import { CSchedaProdotto } from '@src/components/CSchedaProdotto';
|
||||
import { CSearchProduct } from '@src/components/CSearchProduct';
|
||||
import { CMyDialog } from '@src/components/CMyDialog';
|
||||
import { CModifTrafiletto } from '@src/components/CModifTrafiletto';
|
||||
import { CImportListaTitoli } from '@src/components/CImportListaTitoli';
|
||||
|
||||
import { costanti } from '@costanti';
|
||||
import { IAuthor, ICatProd } from 'app/src/model';
|
||||
@@ -47,12 +48,18 @@ export default defineComponent({
|
||||
CLabel,
|
||||
CSchedaProdotto,
|
||||
CModifTrafiletto,
|
||||
CImportListaTitoli,
|
||||
},
|
||||
props: {
|
||||
lista_prodotti: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
canadd: {
|
||||
trype: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
lista_prod_confronto: {
|
||||
type: Array,
|
||||
required: false,
|
||||
@@ -128,6 +135,7 @@ export default defineComponent({
|
||||
const addstr = ref('');
|
||||
|
||||
const showDialogExport = ref(false);
|
||||
const showDialogImport = ref(false);
|
||||
const selectedExportColumns = ref([]);
|
||||
|
||||
const optionscatalogo = ref(<any>{ maxlength: 0 });
|
||||
@@ -138,7 +146,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function riaggiornaListaProdAlGenitore() {
|
||||
emit('update:lista_prodotti', internalProducts.value);
|
||||
aggiornaLista();
|
||||
}
|
||||
|
||||
const editOn = computed({
|
||||
@@ -551,7 +559,8 @@ export default defineComponent({
|
||||
};
|
||||
|
||||
const savedColumns = tools.getCookie(addstr.value + 'selColCat_2');
|
||||
selectedExportColumns.value = tools.getCookie(addstr.value + 'Exp_Columns');
|
||||
const col = tools.getCookie(addstr.value + 'Exp_Columns', null);
|
||||
selectedExportColumns.value = col ? col : [];
|
||||
if (savedColumns) {
|
||||
selectedColumns.value = savedColumns;
|
||||
}
|
||||
@@ -987,13 +996,27 @@ export default defineComponent({
|
||||
persistent: false,
|
||||
})
|
||||
.onOk(() => {
|
||||
internalProducts.value = internalProducts.value.filter(
|
||||
(p: any) => p._id !== product._id
|
||||
);
|
||||
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
|
||||
aggiornaLista(product);
|
||||
});
|
||||
};
|
||||
|
||||
function aggiornaLista(deleteelem: any = null) {
|
||||
const precsearch = searchText.value;
|
||||
|
||||
searchText.value = '';
|
||||
internalProducts.value = [...props.lista_prodotti];
|
||||
|
||||
if (deleteelem) {
|
||||
internalProducts.value = internalProducts.value.filter(
|
||||
(p: any) => p._id !== deleteelem._id
|
||||
);
|
||||
}
|
||||
|
||||
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
|
||||
|
||||
searchText.value = precsearch;
|
||||
}
|
||||
|
||||
// 8. Salvataggio delle colonne selezionate in un cookie
|
||||
const saveSelectedColumns = () => {
|
||||
tools.setCookie(
|
||||
@@ -1031,7 +1054,7 @@ export default defineComponent({
|
||||
// Funzione chiamata alla fine del drag-and-drop
|
||||
const onDragEnd = () => {
|
||||
// console.log("Nuovo ordine:", internalProducts.value);
|
||||
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
|
||||
aggiornaLista();
|
||||
};
|
||||
|
||||
function formatAuthors(authors: IAuthor[] | undefined | null): string {
|
||||
@@ -1096,7 +1119,7 @@ export default defineComponent({
|
||||
return prod;
|
||||
});
|
||||
|
||||
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
|
||||
aggiornaLista();
|
||||
}
|
||||
|
||||
async function updateproductmodif(element: any) {
|
||||
@@ -1184,7 +1207,7 @@ export default defineComponent({
|
||||
emit('rigenera');
|
||||
}
|
||||
|
||||
function addtolist(element) {
|
||||
function addtolist(element: any) {
|
||||
emit('addtolist', element);
|
||||
}
|
||||
|
||||
@@ -1221,13 +1244,9 @@ export default defineComponent({
|
||||
) {
|
||||
saveSelectedColumnsExport(columns);
|
||||
const csvContent = [
|
||||
columns
|
||||
.filter((col) => !columns.find((c) => c.name === col)?.noexp)
|
||||
.map((col) => getColumnLabelByName(col))
|
||||
.join(separatore),
|
||||
columns.map((col) => getColumnLabelByName(col)).join(separatore),
|
||||
...internalProducts.value.map((product: any) => {
|
||||
return columns
|
||||
.filter((col) => !columns.find((c) => c.name === col)?.noexp)
|
||||
.map((col: string) => {
|
||||
const field = { field: col };
|
||||
return field.field === 'pos'
|
||||
@@ -1257,15 +1276,15 @@ export default defineComponent({
|
||||
columns: any[],
|
||||
separatore: string = '\t'
|
||||
) {
|
||||
if (!Array.isArray(columns)) {
|
||||
console.error('Errore: columns non è un array:', columns);
|
||||
return;
|
||||
}
|
||||
saveSelectedColumnsExport(columns);
|
||||
const csvContent = [
|
||||
columns
|
||||
.filter((col) => !columns.find((c) => c.name === col)?.noexp)
|
||||
.map((col) => getColumnLabelByName(col))
|
||||
.join(separatore),
|
||||
columns.map((col) => getColumnLabelByName(col)).join(separatore),
|
||||
...internalProducts.value.map((product: any) => {
|
||||
return columns
|
||||
.filter((col) => !columns.find((c) => c.name === col)?.noexp)
|
||||
.map((col: string) => {
|
||||
const field = { field: col };
|
||||
return field.field === 'pos'
|
||||
@@ -1276,6 +1295,12 @@ export default defineComponent({
|
||||
}),
|
||||
].join('\r\n');
|
||||
|
||||
// Verifica che csvContent non sia vuoto e che abbia un formato valido
|
||||
if (!csvContent || csvContent.trim() === '') {
|
||||
console.error('Errore: csvContent è vuoto o malformato');
|
||||
return;
|
||||
}
|
||||
|
||||
// Creazione del file XLS dopo il CSV
|
||||
exportToXLS(csvContent, title);
|
||||
}
|
||||
@@ -1403,6 +1428,16 @@ export default defineComponent({
|
||||
});
|
||||
}
|
||||
|
||||
function addArrayTitlesToList(myarr: IProduct[]) {
|
||||
console.log('addArrayTitlesToList');
|
||||
|
||||
for (const elem of myarr) {
|
||||
addtolist(elem);
|
||||
}
|
||||
|
||||
showDialogImport.value = false; // chiudi dialog
|
||||
}
|
||||
|
||||
onMounted(mounted);
|
||||
|
||||
return {
|
||||
@@ -1459,8 +1494,10 @@ export default defineComponent({
|
||||
isElementVisible,
|
||||
fabexp,
|
||||
showDialogExport,
|
||||
showDialogImport,
|
||||
selectedExportColumns,
|
||||
allColumnsToExported,
|
||||
addArrayTitlesToList,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user