434 lines
12 KiB
TypeScript
Executable File
434 lines
12 KiB
TypeScript
Executable File
import type { PropType } from 'vue';
|
|
import { defineComponent, onMounted, ref, watch, computed, onBeforeUnmount, nextTick } from 'vue';
|
|
import { tools } from '@tools';
|
|
import { useUserStore } from '@store/UserStore';
|
|
import { useRouter } from 'vue-router';
|
|
import { useGlobalStore } from '@store/globalStore';
|
|
import { useProducts } from '@store/Products';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { toolsext } from '@store/Modules/toolsext';
|
|
import { useQuasar } from 'quasar';
|
|
import { costanti } from '@costanti';
|
|
|
|
import { shared_consts } from '@src/common/shared_vuejs';
|
|
import { CProductCard } from '@src/components/CProductCard';
|
|
|
|
import { CMyDialog } from '@src/components/CMyDialog';
|
|
import { CMySelect } from '@src/components/CMySelect';
|
|
import { CMyValueDb } from '@src/components/CMyValueDb';
|
|
import { CProductTable } from '@src/components/CProductTable';
|
|
import { CSearchProduct } from '@src/components/CSearchProduct';
|
|
import { CContainerCatalogoCard } from '@src/components/CContainerCatalogoCard';
|
|
import { CSelectUserActive } from '@src/components/CSelectUserActive';
|
|
|
|
import html2pdf from 'html2pdf.js';
|
|
import { PDFDocument } from 'pdf-lib';
|
|
import { saveAs } from 'file-saver';
|
|
|
|
import type {
|
|
IOptCatalogo,
|
|
IDimensioni,
|
|
IFilterCatalogo,
|
|
IProdView,
|
|
IProduct,
|
|
ISearchList,
|
|
ICatalog,
|
|
IImg,
|
|
IText,
|
|
ICollana,
|
|
IOptRigenera,
|
|
IOpAndOr,
|
|
} from 'model';
|
|
import { IMyPage } from 'model';
|
|
|
|
import { fieldsTable } from '@store/Modules/fieldsTable';
|
|
import { useCatalogStore } from '@src/store/CatalogStore';
|
|
|
|
export default defineComponent({
|
|
name: 'RaccoltaCataloghi',
|
|
components: {
|
|
CContainerCatalogoCard,
|
|
CProductCard,
|
|
CSelectUserActive,
|
|
CMySelect,
|
|
CProductTable,
|
|
CSearchProduct,
|
|
CMyDialog,
|
|
CMyValueDb,
|
|
},
|
|
emits: ['update:modelValue', 'updateCatalogo'],
|
|
props: {
|
|
modelValue: {
|
|
type: Object as PropType<IOptCatalogo>,
|
|
required: true,
|
|
},
|
|
idPage: {
|
|
type: String,
|
|
required: false,
|
|
default: '',
|
|
},
|
|
},
|
|
setup(props, { emit }) {
|
|
const userStore = useUserStore();
|
|
const globalStore = useGlobalStore();
|
|
const productStore = useProducts();
|
|
const router = useRouter();
|
|
const $q = useQuasar();
|
|
const { t } = useI18n();
|
|
|
|
const rigeneraLibri = ref(false);
|
|
|
|
const search = ref('');
|
|
const optauthors = ref(<any>[]);
|
|
|
|
const loadpage = ref(false)
|
|
|
|
const pdfContent = ref(null);
|
|
const addnewProd = ref(false);
|
|
|
|
const widthpdf = ref('8.88');
|
|
const heightpdf = ref('12.31');
|
|
const compressionepdf = ref('prepress');
|
|
|
|
const optcatalogo = ref(<IOptCatalogo>{ ...props.modelValue });
|
|
|
|
const getRaccoltaCataloghiByMyPage = computed(() => {
|
|
return catalogStore.raccoltacataloghis?.find((raccolta: IRaccoltaCatalogo) => raccolta.idPageAssigned === props.idPage);
|
|
});
|
|
|
|
|
|
const lista_cataloghi = computed(() => {
|
|
const arr = catalogStore.raccoltacataloghis?.find(
|
|
(raccolta: IRaccoltaCatalogo) => raccolta.idPageAssigned === props.idPage
|
|
);
|
|
return arr?.lista_cataloghi;
|
|
});
|
|
|
|
const ispageCatalogata = computed(() => {
|
|
return !!getRaccoltaCataloghiByMyPage.value;
|
|
});
|
|
|
|
const mycolumns = ref([]);
|
|
|
|
const catalogStore = useCatalogStore();
|
|
|
|
const tabraccolta = ref('lista');
|
|
|
|
const searchList = ref([] as ISearchList[]);
|
|
|
|
const numRecLoaded = ref(0);
|
|
|
|
// Create a ref for the component to fix
|
|
const componentToFixRef = ref(<any>null);
|
|
|
|
const isFixed = ref(false);
|
|
|
|
watch(
|
|
() => tabraccolta.value,
|
|
() => {
|
|
tools.setCookie('RACC_TAB_CAT', tabraccolta.value);
|
|
}
|
|
);
|
|
|
|
const labelcombo = computed(() => (item: any) => {
|
|
let lab = item.label;
|
|
if (item.showcount) lab += ' (' + valoriopt.value(item, false, false).length + ')';
|
|
return lab;
|
|
});
|
|
|
|
const arrLoaded = computed(() => {
|
|
if (arrCataloghi.value && numRecLoaded.value) return arrCataloghi.value.slice(0, numRecLoaded.value);
|
|
else {
|
|
return [];
|
|
}
|
|
});
|
|
|
|
function getTitoloRaccolta(): string {
|
|
const trovatoraccolta = getRaccoltaCataloghiByMyPage.value;
|
|
|
|
return trovatoraccolta ? trovatoraccolta.title : 'Raccolta';
|
|
}
|
|
|
|
function getSfondoImgCatalogo(scheda?: IMyScheda | null, mypage?: IDimensioni): IImg {
|
|
const trovatoraccolta = getRaccoltaCataloghiByMyPage.value;
|
|
|
|
let imagefile = '';
|
|
let fit = 'contain';
|
|
|
|
if (trovatoraccolta) {
|
|
// Poi cerca se c'è l'immagine di sfondo
|
|
const recimg = trovatoraccolta.img_bordata!;
|
|
if (!imagefile && recimg) {
|
|
imagefile = recimg.imagefile!;
|
|
fit = recimg.fit! || 'contain';
|
|
imagefile = imagefile
|
|
? `url("${tools.getDirUpload() + shared_consts.getDirectoryByTable(shared_consts.TABLES_CATALOG) + '/' + trovatoraccolta._id + '/' + imagefile}")`
|
|
: '';
|
|
}
|
|
}
|
|
|
|
if (!imagefile && mypage) {
|
|
imagefile = mypage.imgsfondo!.imagefile!;
|
|
imagefile = imagefile ? `url("${tools.getDirUpload() + costanti.DIR_CATALOGO + imagefile}")` : '';
|
|
fit = mypage.imgsfondo!.fit!;
|
|
}
|
|
|
|
if (!imagefile) {
|
|
let myimg = costanti.CATALOGHI.PAG_SFONDO_DEFAULT;
|
|
// Se non c'è un immagine di sfondo, allora prende quella di default
|
|
imagefile = `url("${tools.getDirUpload() + shared_consts.getDirectoryByTable(shared_consts.TABLES_CATALOG) + '/' + myimg})"`;
|
|
}
|
|
|
|
return { imagefile, fit };
|
|
}
|
|
|
|
function salvaListaRaccolte(ricarica: boolean) {
|
|
// Estrai solo gli ID dei prodotti filtrati
|
|
const myarr = [...getRaccoltaCataloghiByMyPage.value.lista_cataloghi];
|
|
const catalogoIds = myarr.map((catalog) => (catalog._id ? catalog._id : null)).filter((id) => id !== null);
|
|
|
|
let mydata = {
|
|
lista_cataloghi: catalogoIds,
|
|
};
|
|
|
|
// Salva gli ID dei prodotti nel catalogo
|
|
tools.saveFieldToServer($q, 'raccoltacataloghis', getRaccoltaCataloghiByMyPage.value._id, mydata, true, false);
|
|
|
|
}
|
|
|
|
async function mounted() {
|
|
// console.log('mounted Catalogo')
|
|
|
|
if (getRaccoltaCataloghiByMyPage.value) {
|
|
tabraccolta.value = tools.getCookie('RACC_TAB_CAT', 'lista');
|
|
} else {
|
|
tabraccolta.value = 'lista';
|
|
}
|
|
|
|
loadpage.value = false;
|
|
// await productStore.loadProducts(true);
|
|
|
|
mycolumns.value = fieldsTable.getArrColsByTable('raccoltacataloghis');
|
|
|
|
// Inizializza
|
|
loadpage.value = true;
|
|
|
|
calcArrCataloghi();
|
|
}
|
|
|
|
function calcArrCataloghi() {}
|
|
|
|
function loaddata() {
|
|
numRecLoaded.value = 20;
|
|
}
|
|
|
|
function naviga(path: string) {
|
|
router.push(path);
|
|
}
|
|
|
|
function updateRaccolta(arr: any) {
|
|
if (getRaccoltaCataloghiByMyPage.value) {
|
|
getRaccoltaCataloghiByMyPage.value.lista_cataloghi = [...arr];
|
|
|
|
salvaListaRaccolte(true);
|
|
}
|
|
}
|
|
|
|
function addCatalogToList(element: ICatalog, where: string) {
|
|
// console.log('addCatalogToList', element)
|
|
|
|
if (element) {
|
|
// add this record to lista_cataloghi
|
|
if (
|
|
getRaccoltaCataloghiByMyPage.value &&
|
|
element._id && !getRaccoltaCataloghiByMyPage.value.lista_cataloghi?.some((p) => p?._id === element._id)
|
|
) {
|
|
// inserire il record in cima
|
|
const arr = getRaccoltaCataloghiByMyPage.value.lista_cataloghi || [];
|
|
if (where === shared_consts.WHERE_INSERT.ONTOP)
|
|
arr.unshift(element);
|
|
else if (where === shared_consts.WHERE_INSERT.ONBOTTOM)
|
|
arr.push(element)
|
|
|
|
updateRaccolta(arr);
|
|
|
|
addnewProd.value = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
function clickaddNewBook() {
|
|
addnewProd.value = true;
|
|
}
|
|
|
|
function toggleDebug() {
|
|
optcatalogo.value.indebug = !optcatalogo.value.indebug;
|
|
}
|
|
|
|
const preparePDF = (stampa: boolean) => {
|
|
|
|
let addstr = stampa ? ' per la STAMPA' : ''
|
|
$q.dialog({
|
|
message: `Generare il PDF ${addstr}?`,
|
|
ok: {
|
|
label: t('dialog.yes'),
|
|
push: true,
|
|
},
|
|
cancel: {
|
|
label: t('dialog.cancel'),
|
|
},
|
|
title: 'Generazione PDF',
|
|
}).onOk(async () => {
|
|
generaPDF(stampa);
|
|
});
|
|
};
|
|
|
|
async function saveRaccolta() {
|
|
const raccolta = getRaccoltaCataloghiByMyPage.value
|
|
const mydata = {
|
|
table: 'raccoltacataloghis',
|
|
data: raccolta,
|
|
};
|
|
|
|
await globalStore.saveTable(mydata);
|
|
}
|
|
|
|
|
|
async function generaPDF(stampa: boolean) {
|
|
$q.loading.show({
|
|
message: 'Generazione della Raccolta Catalogo in PDF in corso ...',
|
|
});
|
|
|
|
try {
|
|
const options = {
|
|
id_raccolta: getRaccoltaCataloghiByMyPage.value._id,
|
|
stampa,
|
|
metti_online: false,
|
|
dir_out: '/upload/raccolte/',
|
|
}
|
|
const ris = await globalStore.execJoinPDF({options});
|
|
|
|
if (ris) {
|
|
const raccolta = getRaccoltaCataloghiByMyPage.value;
|
|
if (!stampa && ris.raccolta.pdf_generato) {
|
|
raccolta.pdf_generato = ris.raccolta.pdf_generato;
|
|
raccolta.pdf_generato_size = ris.raccolta.pdf_generato_size;
|
|
raccolta.data_generato = tools.getDateNow();
|
|
}
|
|
if (stampa && ris.raccolta.pdf_generato_stampa) {
|
|
raccolta.pdf_generato_stampa = ris.raccolta.pdf_generato_stampa;
|
|
raccolta.pdf_generato_stampa_size = ris.raccolta.pdf_generato_stampa_size;
|
|
raccolta.data_generato_stampa = tools.getDateNow();
|
|
}
|
|
|
|
await saveRaccolta();
|
|
}
|
|
|
|
$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);
|
|
}
|
|
}
|
|
|
|
const pubblicaPDF = async () => {
|
|
const raccolta = getRaccoltaCataloghiByMyPage.value;
|
|
|
|
const ris = await globalStore.execOnlinePDF({ id_raccolta: raccolta._id, stampa: false });
|
|
|
|
if (ris) {
|
|
if (ris.record?.pdf_online) {
|
|
raccolta.pdf_online = ris.record.pdf_online;
|
|
raccolta.data_online = ris.record.data_online;
|
|
}
|
|
|
|
$q.notify({
|
|
color: 'positive',
|
|
message: 'PDF inviato ONLINE!',
|
|
icon: 'check',
|
|
});
|
|
} else {
|
|
$q.loading.hide();
|
|
$q.notify({
|
|
color: 'negative',
|
|
message: "Errore nell'invio del PDF OnLine",
|
|
icon: 'error',
|
|
});
|
|
}
|
|
};
|
|
|
|
const pubblicaPDFStampa = async () => {
|
|
const raccolta = getRaccoltaCataloghiByMyPage.value;
|
|
|
|
const ris = await globalStore.execOnlinePDF({ id_raccolta: raccolta._id, stampa: true });
|
|
|
|
if (ris) {
|
|
if (ris.record.pdf_online_stampa) {
|
|
raccolta.pdf_online_stampa = ris.record.pdf_online_stampa;
|
|
raccolta.data_online_stampa = ris.record.data_online_stampa;
|
|
}
|
|
|
|
await saveRaccolta();
|
|
|
|
$q.notify({
|
|
color: 'positive',
|
|
message: 'PDF STAMPA inviato ONLINE!',
|
|
icon: 'check',
|
|
});
|
|
} else {
|
|
$q.loading.hide();
|
|
$q.notify({
|
|
color: 'negative',
|
|
message: "Errore nell'invio del PDF STAMPA OnLine",
|
|
icon: 'error',
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
onMounted(mounted);
|
|
|
|
return {
|
|
userStore,
|
|
costanti,
|
|
tools,
|
|
toolsext,
|
|
search,
|
|
shared_consts,
|
|
productStore,
|
|
t,
|
|
componentToFixRef,
|
|
isFixed,
|
|
numRecLoaded,
|
|
arrLoaded,
|
|
mycolumns,
|
|
tabraccolta,
|
|
naviga,
|
|
getTitoloRaccolta,
|
|
lista_cataloghi,
|
|
updateRaccolta,
|
|
clickaddNewBook,
|
|
addCatalogToList,
|
|
addnewProd,
|
|
rigeneraLibri,
|
|
getRaccoltaCataloghiByMyPage,
|
|
preparePDF,
|
|
pubblicaPDF,
|
|
pubblicaPDFStampa,
|
|
loadpage,
|
|
ispageCatalogata,
|
|
optcatalogo,
|
|
};
|
|
},
|
|
});
|