From f30cbf072a493422c4a240f4ca364e91cc54e0cf Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Wed, 14 May 2025 17:04:18 +0200 Subject: [PATCH] - Assegnazione di linkIdTemplate anche per la "Pagina di Default", in modo che posso da "Templates" cambiare le impostazioni. --- src/common/shared_vuejs.ts | 2 +- .../CContainerCatalogoCard.ts | 2 +- src/components/CMyEditElem/CMyEditElem.ts | 625 +++-- src/components/CMyEditElem/CMyEditElem.vue | 33 + src/components/CProductTable/CProductTable.ts | 2 +- .../CProductTable/CProductTable.vue | 2 +- .../CSearchProduct/CSearchProduct.ts | 9 + src/model/GlobalStore.ts | 3 + src/store/Modules/tools.ts | 4 +- src/store/Products.ts | 2018 +++++++++-------- src/store/globalStore.ts | 38 +- src/views/ecommerce/catalogo/catalogo.ts | 8 + src/views/ecommerce/catalogo/catalogo.vue | 13 +- 13 files changed, 1508 insertions(+), 1251 deletions(-) diff --git a/src/common/shared_vuejs.ts b/src/common/shared_vuejs.ts index 2739ad67..1b2ca847 100755 --- a/src/common/shared_vuejs.ts +++ b/src/common/shared_vuejs.ts @@ -442,7 +442,7 @@ export const shared_consts = { TABLES_DIRECTORY_A_PARTE: ['mygroups'], TABLES_WITH_ADMINS: ['mygroups', 'circuits'], TABLES_DIRECTORY_SINGLE_IMG: ['circuits', 'catalogs', 'raccoltacataloghis'], - TABLES_IMAGEFILE_SINGOLO: ['productInfos'], + TABLES_IMAGEFILE_SINGOLO: ['productInfos', 'products'], TABLES_PER_EDITORI: ['catalogs', 'raccoltacataloghis'], diff --git a/src/components/CContainerCatalogoCard/CContainerCatalogoCard.ts b/src/components/CContainerCatalogoCard/CContainerCatalogoCard.ts index 211d6c49..ca7e3649 100755 --- a/src/components/CContainerCatalogoCard/CContainerCatalogoCard.ts +++ b/src/components/CContainerCatalogoCard/CContainerCatalogoCard.ts @@ -81,7 +81,7 @@ export default defineComponent({ watch(() => props.modelValue, (newVal) => { optcatalogo.value = { ...newVal }; // updateCatalogoPadre() - }, { deep: false }); + }, { deep: true }); function updateCatalogoPadre() { emit('update:modelValue', optcatalogo.value); diff --git a/src/components/CMyEditElem/CMyEditElem.ts b/src/components/CMyEditElem/CMyEditElem.ts index 2e41364a..cceaa023 100755 --- a/src/components/CMyEditElem/CMyEditElem.ts +++ b/src/components/CMyEditElem/CMyEditElem.ts @@ -1,52 +1,75 @@ import type { PropType } from 'vue'; -import { - defineComponent, onMounted, computed, ref, toRef, watch, - nextTick, -} from 'vue' +import { defineComponent, onMounted, computed, ref, toRef, watch, nextTick } from 'vue'; -import type { IOptCatalogo, IColGridTable, IElemText, IElementiScheda, IMyCard, IMyElem, IMyScheda, ISchedaSingola, IText } from '@src/model'; -import { IImgGallery, ILabelValue, IMyPage, IOperators } from '@src/model' -import { useGlobalStore } from '@store/globalStore' +import type { + IOptCatalogo, + IColGridTable, + IElemText, + IElementiScheda, + IMyCard, + IMyElem, + IMyScheda, + ISchedaSingola, + IText, +} from '@src/model'; +import { IImgGallery, ILabelValue, IMyPage, IOperators } from '@src/model'; +import { useGlobalStore } from '@store/globalStore'; -import { CImgTitle } from '@src/components/CImgTitle' -import { CImgPoster } from '@src/components/CImgPoster' -import { CTitle } from '@src/components/CTitle/index' -import { tools } from '@tools' -import { shared_consts } from '@src/common/shared_vuejs' -import { LandingFooter } from '@src/components/LandingFooter' -import { COpenStreetMap } from '@src/components/COpenStreetMap' -import { CCardCarousel } from '@src/components/CCardCarousel' -import { CMyPage } from '@src/components/CMyPage' -import { CMyPageIntro } from '@src/components/CMyPageIntro' -import { CEventsCalendar } from '@src/components/CEventsCalendar' -import { CMyEditor } from '@src/components/CMyEditor' -import { CMySlider } from '@src/components/CMySlider' -import { CMyFieldRec } from '@src/components/CMyFieldRec' -import { CSelectImage } from '@src/components/CSelectImage' -import { CSelectAnimation } from '@src/components/CSelectAnimation' -import { CSelectColor } from '@src/components/CSelectColor' -import { CSelectFontSize } from '@src/components/CSelectFontSize' -import { CMySize } from '@src/components/CMySize' -import { CBorders } from '@src/components/CBorders' -import { CMyDimensioni } from '@src/components/CMyDimensioni' -import { CMyText } from '@src/components/CMyText' +import { CImgTitle } from '@src/components/CImgTitle'; +import { CImgPoster } from '@src/components/CImgPoster'; +import { CTitle } from '@src/components/CTitle/index'; +import { tools } from '@tools'; +import { shared_consts } from '@src/common/shared_vuejs'; +import { LandingFooter } from '@src/components/LandingFooter'; +import { COpenStreetMap } from '@src/components/COpenStreetMap'; +import { CCardCarousel } from '@src/components/CCardCarousel'; +import { CMyPage } from '@src/components/CMyPage'; +import { CMyPageIntro } from '@src/components/CMyPageIntro'; +import { CEventsCalendar } from '@src/components/CEventsCalendar'; +import { CMyEditor } from '@src/components/CMyEditor'; +import { CMySlider } from '@src/components/CMySlider'; +import { CMyFieldRec } from '@src/components/CMyFieldRec'; +import { CSelectImage } from '@src/components/CSelectImage'; +import { CSelectAnimation } from '@src/components/CSelectAnimation'; +import { CSelectColor } from '@src/components/CSelectColor'; +import { CSelectFontSize } from '@src/components/CSelectFontSize'; +import { CMySize } from '@src/components/CMySize'; +import { CBorders } from '@src/components/CBorders'; +import { CMyDimensioni } from '@src/components/CMyDimensioni'; +import { CMyText } from '@src/components/CMyText'; -import MixinMetaTags from '@src/mixins/mixin-metatags' -import MixinBase from '@src/mixins/mixin-base' -import { useQuasar } from 'quasar' -import { useI18n } from 'vue-i18n' -import { emitKeypressEvents } from 'readline' -import { costanti } from '@costanti' -import objectId from '@src/js/objectId' -import { useProducts } from '@src/store/Products' +import MixinMetaTags from '@src/mixins/mixin-metatags'; +import MixinBase from '@src/mixins/mixin-base'; +import { useQuasar } from 'quasar'; +import { useI18n } from 'vue-i18n'; +import { emitKeypressEvents } from 'readline'; +import { costanti } from '@costanti'; +import objectId from '@src/js/objectId'; +import { useProducts } from '@src/store/Products'; export default defineComponent({ name: 'CMyEditElem', components: { - CImgTitle, CTitle, LandingFooter, CEventsCalendar, - CCardCarousel, COpenStreetMap, CMyPage, CMyPageIntro, CMyEditor, CMyFieldRec, - CSelectColor, CSelectFontSize, CSelectImage, CImgPoster, CSelectAnimation, CMySlider, - CMySize, CBorders, CMyDimensioni, CMyText, + CImgTitle, + CTitle, + LandingFooter, + CEventsCalendar, + CCardCarousel, + COpenStreetMap, + CMyPage, + CMyPageIntro, + CMyEditor, + CMyFieldRec, + CSelectColor, + CSelectFontSize, + CSelectImage, + CImgPoster, + CSelectAnimation, + CMySlider, + CMySize, + CBorders, + CMyDimensioni, + CMyText, }, emits: ['saveElem', 'selElemClick', 'toggleSize', 'deleteElem', 'dupPage', 'expPage', 'impPage'], props: { @@ -76,131 +99,130 @@ export default defineComponent({ }, }, setup(props, { emit }) { - const globalStore = useGlobalStore() + const globalStore = useGlobalStore(); - const { setmeta, getsrcbyimg } = MixinMetaTags() - const { setValDb, getValDb } = MixinBase() + const { setmeta, getsrcbyimg } = MixinMetaTags(); + const { setValDb, getValDb } = MixinBase(); + const $q = useQuasar(); + const { t } = useI18n(); - const $q = useQuasar() - const { t } = useI18n() + const animare = ref(0); + const slide = ref(0); + const slide2 = ref(0); + const tabCard = ref(0); + const tabScheda = ref(0); + const tabElemsText = ref('elem0'); + const arrPages = ref([] as any[]); + const disableSave = ref(true); + const enableEdit = ref(true); + const elemChanged = ref(false); + const enableAdd = ref(true); + const tabadd = ref('tools'); + const Products = useProducts(); - const animare = ref(0) - const slide = ref(0) - const slide2 = ref(0) - const tabCard = ref(0) - const tabScheda = ref(0) - const tabElemsText = ref('elem0') - const arrPages = ref([] as any[]) - const disableSave = ref(true) - const enableEdit = ref(true) - const elemChanged = ref(false) - const enableAdd = ref(true) - const tabadd = ref('tools') + const neworder = ref(0); - const Products = useProducts() + const idSchedaDaCopiare = ref(''); - const neworder = ref(0) + const myel = toRef(props, 'myelem'); + const newtype = ref(''); + const visuadd = ref(false); + const direzadd = ref(1); - const idSchedaDaCopiare = ref('') + const selectedClasses = ref([]); - const myel = toRef(props, 'myelem') - const newtype = ref('') - const visuadd = ref(false) - const direzadd = ref(1) - - const selectedClasses = ref([]) - - watch(() => myel.value.order, (value, oldval) => { - mounted() - }) + watch( + () => myel.value.order, + (value, oldval) => { + mounted(); + } + ); function getArrDisciplines() { - return globalStore.disciplines.filter((rec: any) => rec.showinhome) + return globalStore.disciplines.filter((rec: any) => rec.showinhome); } function saveElem(exit?: boolean) { // Save Elem record - const myelem = props.myelem - myelem.order = neworder.value + const myelem = props.myelem; + myelem.order = neworder.value; globalStore.saveMyElem($q, t, myelem).then((ris) => { if (ris) { // OK - disableSave.value = true - emit('saveElem', myelem) + disableSave.value = true; + emit('saveElem', myelem); - if (exit) - elemChanged.value = false + if (exit) elemChanged.value = false; } - }) + }); } function getNewOrderByThisElem() { - const myelem = props.myelem - let neword = 0 + const myelem = props.myelem; + let neword = 0; if (myelem) { - neword = myelem.order! - const recfound = globalStore.getMyElemNextThisElemId(props.idPage, myelem._id) + neword = myelem.order!; + const recfound = globalStore.getMyElemNextThisElemId(props.idPage, myelem._id); if (recfound) { - neword = Math.round((recfound.order! + myelem.order!) / 2) + neword = Math.round((recfound.order! + myelem.order!) / 2); } } - return neword + return neword; } async function addNewElem(elemsel: any, direz: number) { + visuadd.value = false; - visuadd.value = false + let neword = 0; - let neword = 0 + let recfound = null; - let recfound = null - - if (direz === -1) { // Sopra + if (direz === -1) { + // Sopra // ottieni l'elemento precedente, mantenendo l'ordinamento - recfound = globalStore.getMyElemPrecThisElemId(props.idPage, elemsel._id) - } else if (direz === 1) { // Sotto + recfound = globalStore.getMyElemPrecThisElemId(props.idPage, elemsel._id); + } else if (direz === 1) { + // Sotto // ottieni l'elemento precedente, mantenendo l'ordinamento - recfound = globalStore.getMyElemNextThisElemId(props.idPage, elemsel._id) + recfound = globalStore.getMyElemNextThisElemId(props.idPage, elemsel._id); } if (recfound) { // get the middle of the order number between thie 2 elements - neword = Math.round((recfound.order + elemsel.order) / 2) + neword = Math.round((recfound.order + elemsel.order) / 2); } - const newrec = await globalStore.prepareAddNewElem(neword, $q, t, props.myelem, newtype.value) + const newrec = await globalStore.prepareAddNewElem(neword, $q, t, props.myelem, newtype.value); - emit('selElemClick', newrec) + emit('selElemClick', newrec); // emit('updateAll', newrec) } async function dupPage() { - emit('dupPage', null) + emit('dupPage', null); } async function exportPage() { - emit('expPage', null) + emit('expPage', null); } async function importPage() { - emit('impPage', null) + emit('impPage', null); } async function dupElem(order?: number) { + const newrec: IMyElem = tools.jsonCopy(props.myelem); - const newrec: IMyElem = tools.jsonCopy(props.myelem) - - newrec._id = undefined - newrec.order = getNewOrderByThisElem() + newrec._id = undefined; + newrec.order = getNewOrderByThisElem(); if (newrec.type === shared_consts.ELEMTYPE.HTML) { - newrec.containerHtml = 'Copia di ' + newrec.containerHtml + newrec.containerHtml = 'Copia di ' + newrec.containerHtml; } - const mynewelem = await globalStore.addNewElem($q, t, newrec) - - emit('selElemClick', mynewelem) + const mynewelem = await globalStore.addNewElem($q, t, newrec); + emit('selElemClick', mynewelem); } function delElem() { @@ -215,88 +237,81 @@ export default defineComponent({ cancel: true, persistent: false, }).onOk(async () => { - // Save Elem record await globalStore.delMyElem($q, t, props.myelem).then((ris) => { if (ris) { // OK - disableSave.value = true - emit('deleteElem', props.myelem) + disableSave.value = true; + emit('deleteElem', props.myelem); } - }) - }) - + }); + }); } function modifElem() { - disableSave.value = false - elemChanged.value = true - + disableSave.value = false; + elemChanged.value = true; } function modifElemAndSchede() { - modifElem() - - myel.value.catalogo!.aggiorna++ + modifElem(); + myel.value.catalogo!.aggiorna++; } function mounted() { try { - neworder.value = props.myelem.order + neworder.value = props.myelem.order; - arrPages.value = [] - arrPages.value.push({ label: '[Vuoto]', path: '' }) + arrPages.value = []; + arrPages.value.push({ label: '[Vuoto]', path: '' }); for (const page of globalStore.mypage) { - const rec = { // @ts-ignore label: page.title, // @ts-ignore - value: page.idPage - } - arrPages.value.push(rec) + value: page.idPage, + }; + arrPages.value.push(rec); } - if (props.myelem) - newtype.value = props.myelem.type + if (props.myelem) newtype.value = props.myelem.type; if (myel.value.class4) { - selectedClasses.value = myel.value.class4.split(' ').filter(Boolean) + selectedClasses.value = myel.value.class4.split(' ').filter(Boolean); } if (myel.value.catalogo && myel.value.catalogo?.arrSchede) { for (const recscheda of myel.value.catalogo!.arrSchede) { if (recscheda.scheda) { - recscheda.scheda.testo_right_attaccato = tools.resetIText(recscheda.scheda?.testo_right_attaccato) - recscheda.scheda.testo_right = tools.resetIText(recscheda.scheda?.testo_right) - recscheda.scheda.testo_bottom = tools.resetIText(recscheda.scheda?.testo_bottom) + recscheda.scheda.testo_right_attaccato = tools.resetIText(recscheda.scheda?.testo_right_attaccato); + recscheda.scheda.testo_right = tools.resetIText(recscheda.scheda?.testo_right); + recscheda.scheda.testo_bottom = tools.resetIText(recscheda.scheda?.testo_bottom); - if ((!recscheda.scheda?.dimensioni.pagina.dimensioni)) { - recscheda.scheda.dimensioni.pagina = tools.resetRecIPagina(recscheda.scheda?.dimensioni.pagina) + if (!recscheda.scheda?.dimensioni.pagina.dimensioni) { + recscheda.scheda.dimensioni.pagina = tools.resetRecIPagina(recscheda.scheda?.dimensioni.pagina); } if (!recscheda.scheda?.dimensioni?.pagina?.testo_up) { - recscheda.scheda!.dimensioni.pagina.testo_up = tools.resetIText(null) + recscheda.scheda!.dimensioni.pagina.testo_up = tools.resetIText(null); } if (!recscheda.scheda?.dimensioni?.pagina?.testo_title) { - recscheda.scheda!.dimensioni.pagina.testo_title = tools.resetIText(null) + recscheda.scheda!.dimensioni.pagina.testo_title = tools.resetIText(null); } if (!recscheda.scheda?.dimensioni?.pagina?.testo_down) { - recscheda.scheda!.dimensioni.pagina.testo_down = tools.resetIText(null) + recscheda.scheda!.dimensioni.pagina.testo_down = tools.resetIText(null); } if (!recscheda.scheda?.etichette?.novita?.show) { recscheda.scheda.etichette!.novita = { show: false, months: 6, - } + }; recscheda.scheda.etichette!.bestseller = { show: false, quantiFattRaggiunti: 0, - - } + }; } - if ((!recscheda.scheda?.barcode || !recscheda.scheda?.barcode.font)) { + if (!recscheda.scheda?.barcode || !recscheda.scheda?.barcode.font) { recscheda.scheda.barcode = { show: false, format: '', @@ -307,45 +322,49 @@ export default defineComponent({ font: { name: '', size: '11', - } - } + }, + }; } - } } } if (myel.value.catalogo) { if (!myel.value.catalogo.first_page) { - myel.value.catalogo.first_page = tools.resetRecIDimensioni(null) + myel.value.catalogo.first_page = tools.resetRecIDimensioni(null); } - myel.value.catalogo.first_page = tools.resetRecIDimensioni(myel.value.catalogo.first_page) + myel.value.catalogo.first_page = tools.resetRecIDimensioni(myel.value.catalogo.first_page); } if (myel.value.catalogo) { - if (!myel.value.catalogo.last_page) - myel.value.catalogo.last_page = tools.resetRecIDimensioni(null) + if (!myel.value.catalogo.last_page) myel.value.catalogo.last_page = tools.resetRecIDimensioni(null); - myel.value.catalogo.last_page = tools.resetRecIDimensioni(myel.value.catalogo.last_page) + myel.value.catalogo.last_page = tools.resetRecIDimensioni(myel.value.catalogo.last_page); } if (myel.value.catalogo) { if (!myel.value.catalogo.areadistampa) { - myel.value.catalogo.areadistampa = tools.resetRecIAreaDiStampa(null) - myel.value.catalogo.areadistampa.margini = { left: '0.59', top: '0.59', right: '0.59', bottom: '0.28' } + myel.value.catalogo.areadistampa = tools.resetRecIAreaDiStampa(null); + myel.value.catalogo.areadistampa.margini = { left: '0.59', top: '0.59', right: '0.59', bottom: '0.28' }; } - myel.value.catalogo.areadistampa = tools.resetRecIAreaDiStampa(myel.value.catalogo.areadistampa) + myel.value.catalogo.areadistampa = tools.resetRecIAreaDiStampa(myel.value.catalogo.areadistampa); } if (myel.value.catalogo && !myel.value.catalogo.dimensioni_def) { - myel.value.catalogo.dimensioni_def = { pagina: {} } + myel.value.catalogo.dimensioni_def = { + isTemplate: false, + linkIdTemplate: '', + name: '', + pagina: {}, + }; } if (myel.value.catalogo && myel.value.catalogo.dimensioni_def) { - myel.value.catalogo.dimensioni_def.pagina = tools.resetRecIDimensioni(myel.value.catalogo.dimensioni_def.pagina) + myel.value.catalogo.dimensioni_def.pagina = tools.resetRecIDimensioni( + myel.value.catalogo.dimensioni_def.pagina + ); } - } catch (error) { - console.log(error) + console.log(error); } } @@ -355,43 +374,39 @@ export default defineComponent({ } function addNewCard() { - if (!myel.value.listcards) - myel.value.listcards = [] - - myel.value.listcards.push({ _id: objectId(), imagefile: '', alt: '', description: '', vers_img: 0 }) - modifElem() - + if (!myel.value.listcards) myel.value.listcards = []; + myel.value.listcards.push({ _id: objectId(), imagefile: '', alt: '', description: '', vers_img: 0 }); + modifElem(); } function addNewScheda() { + Products.addNewScheda(myel.value.catalogo); - Products.addNewScheda(myel.value.catalogo) - - modifElem() - + modifElem(); } function copyfromTemplate(indscheda: number) { // Estrai l'id da copiare e sostituisci tutto con questo if (!idSchedaDaCopiare.value) { - return false + return false; } - const arrschede: ISchedaSingola[] = globalStore.getMySchede() + const arrschede: ISchedaSingola[] = globalStore.getMySchede(); if (arrschede.length <= 0) { - return false + return false; } - const myschedatocopy = arrschede.find((recscheda: ISchedaSingola) => recscheda.scheda!._id === idSchedaDaCopiare.value) - const schedadest = myel.value.catalogo!.arrSchede![indscheda] + const myschedatocopy = arrschede.find( + (recscheda: ISchedaSingola) => recscheda.scheda!._id === idSchedaDaCopiare.value + ); + const schedadest = myel.value.catalogo!.arrSchede![indscheda]; if (myschedatocopy) { + const newscheda = myschedatocopy.scheda!.name; - const newscheda = myschedatocopy.scheda!.name - - const msg = 'Sostituisci questa scheda (' + schedadest.scheda?.name + ') con "' + newscheda + '" ?' + const msg = 'Sostituisci questa scheda (' + schedadest.scheda?.name + ') con "' + newscheda + '" ?'; $q.dialog({ message: msg, @@ -404,107 +419,100 @@ export default defineComponent({ cancel: true, persistent: false, }).onOk(async () => { - const myschedadest: ISchedaSingola = myel.value.catalogo!.arrSchede![indscheda] - myschedadest.scheda = tools.jsonCopy(myschedatocopy.scheda) - myschedadest.scheda!._id = objectId() - myschedadest.order = 20 - - myschedadest.scheda!.name = myschedadest.scheda!.name + '_copia' - myschedadest.scheda!.isTemplate = false - }) + const myschedadest: ISchedaSingola = myel.value.catalogo!.arrSchede![indscheda]; + myschedadest.scheda = tools.jsonCopy(myschedatocopy.scheda); + myschedadest.scheda!._id = objectId(); + myschedadest.order = 20; + myschedadest.scheda!.name = myschedadest.scheda!.name + '_copia'; + myschedadest.scheda!.isTemplate = false; + }); } } function dupNewScheda(id: string) { - if (!myel.value.catalogo!.arrSchede) - return + if (!myel.value.catalogo!.arrSchede) return; - const myfindscheda = myel.value.catalogo!.arrSchede.find((scheda: ISchedaSingola) => scheda._id === id) + const myfindscheda = myel.value.catalogo!.arrSchede.find((scheda: ISchedaSingola) => scheda._id === id); if (myfindscheda) { - const myscheda = tools.jsonCopy(myfindscheda) - delete myscheda._id - delete myscheda.scheda!._id - myscheda.numPagineMax = 0 - myscheda.order = myscheda.order + 10 - myscheda._id = objectId() - myscheda.scheda!._id = objectId() - myscheda.scheda!.name = myscheda.scheda!.name + '_copia' - myscheda.scheda!.isTemplate = false + const myscheda = tools.jsonCopy(myfindscheda); + delete myscheda._id; + delete myscheda.scheda!._id; + myscheda.numPagineMax = 0; + myscheda.order = myscheda.order + 10; + myscheda._id = objectId(); + myscheda.scheda!._id = objectId(); + myscheda.scheda!.name = myscheda.scheda!.name + '_copia'; + myscheda.scheda!.isTemplate = false; - const bakscheda = [...myel.value.catalogo!.arrSchede] + const bakscheda = [...myel.value.catalogo!.arrSchede]; - myel.value.catalogo!.arrSchede.push(myscheda) - modifElem() + myel.value.catalogo!.arrSchede.push(myscheda); + modifElem(); } - } - function dupNewCard() { - if (!myel.value.listcards) - return + if (!myel.value.listcards) return; - const myfindcard = myel.value.listcards[tabCard.value] + const myfindcard = myel.value.listcards[tabCard.value]; if (myfindcard) { - const mycard = tools.jsonCopy(myfindcard) - delete mycard._id - mycard._id = objectId() + const mycard = tools.jsonCopy(myfindcard); + delete mycard._id; + mycard._id = objectId(); - const bakcard = [...myel.value.listcards] + const bakcard = [...myel.value.listcards]; - myel.value.listcards = [] - myel.value.listcards = [...bakcard, mycard] - modifElem() + myel.value.listcards = []; + myel.value.listcards = [...bakcard, mycard]; + modifElem(); } - - } function addNewElemText() { - if (!myel.value.elemsText) - myel.value.elemsText = [] + if (!myel.value.elemsText) myel.value.elemsText = []; - myel.value.elemsText.push({ _id: objectId(), text: '', color: '#ffffff', class: '', size: '', anim: { name: 'FadeIn', clduration: '', cldelay: '', timingtype: 'ease-in-out' } }) - modifElem() + myel.value.elemsText.push({ + _id: objectId(), + text: '', + color: '#ffffff', + class: '', + size: '', + anim: { name: 'FadeIn', clduration: '', cldelay: '', timingtype: 'ease-in-out' }, + }); + modifElem(); } function getClass() { - let mycl = '' + let mycl = ''; if (props.myelem.align === shared_consts.ALIGNTYPE.CEHTER) { - mycl += ' align_center' + mycl += ' align_center'; } else if (props.myelem.align === shared_consts.ALIGNTYPE.RIGHT) { - mycl += ' align_right' + mycl += ' align_right'; } else if (props.myelem.align === shared_consts.ALIGNTYPE.LEFT) { - mycl += ' align_left' + mycl += ' align_left'; } - return mycl + return mycl; } function showFit() { - if (props.myelem.type) - return [shared_consts.ELEMTYPE.TEXT].includes(props.myelem.type) - else - return false + if (props.myelem.type) return [shared_consts.ELEMTYPE.TEXT].includes(props.myelem.type); + else return false; } function delRecCard(id: string, myel: IMyElem) { // if (props.myelem.type === shared_consts.ELEMTYPE.CARD) { - if (myel.listcards) - myel.listcards = myel.listcards.filter((card: IMyCard) => card._id !== id) + if (myel.listcards) myel.listcards = myel.listcards.filter((card: IMyCard) => card._id !== id); } else if (props.myelem.type === shared_consts.ELEMTYPE.IMGPOSTER) { - if (myel.elemsText) - myel.elemsText = myel.elemsText.filter((rec: IElemText) => rec._id !== id) + if (myel.elemsText) myel.elemsText = myel.elemsText.filter((rec: IElemText) => rec._id !== id); } - } function delRecScheda(id: string, myel: IMyElem) { - - const myscheda = myel.catalogo!.arrSchede!.find((scheda: ISchedaSingola) => scheda._id === id) + const myscheda = myel.catalogo!.arrSchede!.find((scheda: ISchedaSingola) => scheda._id === id); if (myscheda) { $q.dialog({ @@ -518,45 +526,43 @@ export default defineComponent({ cancel: true, persistent: false, }).onOk(async () => { - // - myel.catalogo!.arrSchede = myel.catalogo!.arrSchede!.filter((scheda: ISchedaSingola) => scheda._id !== id) + myel.catalogo!.arrSchede = myel.catalogo!.arrSchede!.filter((scheda: ISchedaSingola) => scheda._id !== id); - modifElem() - }) + modifElem(); + }); } - } function saveFieldElem(rec: any, newval: any, col: IColGridTable) { //console.log('saveFieldElem', rec, 'newval', newval, 'col', col) - const iscatalogo = costanti.CATALOGO_FIELDS.includes(col.name) - const isscheda = costanti.SCHEDA_FIELDS.includes(col.name) - const isIImg = costanti.IMG_FIELDS.includes(col.name) && (col.fieldtype === costanti.FieldType.image) + const iscatalogo = costanti.CATALOGO_FIELDS.includes(col.name); + const isscheda = costanti.SCHEDA_FIELDS.includes(col.name); + const isIImg = costanti.IMG_FIELDS.includes(col.name) && col.fieldtype === costanti.FieldType.image; if (col.fieldtype === costanti.FieldType.image) { if (iscatalogo) { - myel.value.catalogo[col.name] = newval.imagefile + myel.value.catalogo[col.name] = newval.imagefile; //console.log('SALVATO IN', col.name, newval.imagefile, 'RIS', myel.value.catalogo[col.name]) } else if (isscheda) { - rec[col.name] = newval.imagefile + rec[col.name] = newval.imagefile; } else if (isIImg) { if (!rec[col.name]) { - rec[col.name] = {} + rec[col.name] = {}; } - rec[col.name].imagefile = newval.imagefile + rec[col.name].imagefile = newval.imagefile; } else { - myel.value[col.name] = newval.imagefile + myel.value[col.name] = newval.imagefile; } } else { if (iscatalogo) { - myel.value.catalogo[col.name] = newval - console.log('SALVATO IN', col.name, newval, 'RIS', myel.value.catalogo[col.name]) + myel.value.catalogo[col.name] = newval; + console.log('SALVATO IN', col.name, newval, 'RIS', myel.value.catalogo[col.name]); } else if (isscheda) { - rec[col.name] = newval + rec[col.name] = newval; } else { - myel.value[col.name] = newval + myel.value[col.name] = newval; } } } @@ -567,43 +573,45 @@ export default defineComponent({ props.myelem.listcards.forEach((rec: IMyCard) => { if (recpass._id === rec._id) { if (myval.imagefile) { - rec.imagefile = myval.imagefile - rec.vers_img = tools.getGenerateVersionImage() + rec.imagefile = myval.imagefile; + rec.vers_img = tools.getGenerateVersionImage(); } else { - rec.imagefile = myval + rec.imagefile = myval; } } - }) + }); } } else if (props.myelem.type === shared_consts.ELEMTYPE.IMGPOSTER) { if (props.myelem.elemsText) { props.myelem.elemsText.forEach((rec: IElemText) => { if (recpass._id === rec._id) { if (myval.imagefile) { - rec.text = myval.imagefile + rec.text = myval.imagefile; } else { - rec.text = myval + rec.text = myval; } } - }) + }); } - } else if ((props.myelem.type === shared_consts.ELEMTYPE.IMGTITLE) || - (props.myelem.type === shared_consts.ELEMTYPE.IMAGE)) { - myel.value.image = myval - myel.value.vers_img = tools.getGenerateVersionImage() - + } else if ( + props.myelem.type === shared_consts.ELEMTYPE.IMGTITLE || + props.myelem.type === shared_consts.ELEMTYPE.IMAGE + ) { + myel.value.image = myval; + myel.value.vers_img = tools.getGenerateVersionImage(); } - modifElem() - + modifElem(); } function showAnimation() { - return (myel.value.type === shared_consts.ELEMTYPE.IMAGE) - || (myel.value.type === shared_consts.ELEMTYPE.IMGTITLE) - || (myel.value.type === shared_consts.ELEMTYPE.TEXT) - || (myel.value.type === shared_consts.ELEMTYPE.CARD) - || (myel.value.type === shared_consts.ELEMTYPE.HTML) - || (myel.value.type === shared_consts.ELEMTYPE.CAROUSEL_IMGS) + return ( + myel.value.type === shared_consts.ELEMTYPE.IMAGE || + myel.value.type === shared_consts.ELEMTYPE.IMGTITLE || + myel.value.type === shared_consts.ELEMTYPE.TEXT || + myel.value.type === shared_consts.ELEMTYPE.CARD || + myel.value.type === shared_consts.ELEMTYPE.HTML || + myel.value.type === shared_consts.ELEMTYPE.CAROUSEL_IMGS + ); } /*function updateElem(myvalue: any) { @@ -618,10 +626,8 @@ export default defineComponent({ const options = []; let add = ''; - if (widthpx) - add = 'px' + if (widthpx) add = 'px'; for (let i = 0; i <= 700; i += 50) { - options.push({ label: `${i}${add}`, value: `${i}${add}` }); } return options; @@ -630,22 +636,21 @@ export default defineComponent({ function updateSizeWidth(value: any) { // Gestisce l'input dell'utente per un nuovo valore myel.value.widthimg = value; // Aggiorna widthimg con il nuovo valore - modifElem() + modifElem(); } function updateSizeHeight(value: any) { if (value) myel.value.heightimg = value; // Aggiorna widthimg con il nuovo valore - else - myel.value.heightimg = '' - modifElem() + else myel.value.heightimg = ''; + modifElem(); } function toggleSize() { - emit('toggleSize', null) + emit('toggleSize', null); } const orderOptions = computed(() => { - const options = [] + const options = []; for (let i = 0; i <= 100; i += 1) { options.push({ label: i.toString(), value: i }); @@ -659,59 +664,57 @@ export default defineComponent({ }); function addOrder(rec: any) { - neworder.value = rec + neworder.value = rec; } function addProdSpeciale(rec: any) { - neworder.value = rec + neworder.value = rec; } async function moveElem(direz: any) { - const myelem = props.myelem + const myelem = props.myelem; - const elemprec = globalStore.getMyElemPrecThisElemId(props.idPage, myelem._id) - const elemnext = globalStore.getMyElemNextThisElemId(props.idPage, myelem._id) + const elemprec = globalStore.getMyElemPrecThisElemId(props.idPage, myelem._id); + const elemnext = globalStore.getMyElemNextThisElemId(props.idPage, myelem._id); - if (!elemprec || !elemnext) - return false + if (!elemprec || !elemnext) return false; - let neworder = 0 - const oldorder = myelem.order! + let neworder = 0; + const oldorder = myelem.order!; if (direz === -1) { // UP - neworder = elemprec.order! - elemprec.order = oldorder + neworder = elemprec.order!; + elemprec.order = oldorder; if (oldorder === elemprec.order!) { - const elemprec2 = globalStore.getMyElemPrecThisElemId(props.idPage, elemprec._id) + const elemprec2 = globalStore.getMyElemPrecThisElemId(props.idPage, elemprec._id); - neworder = (elemprec2.order! + elemprec.order) / 2 - elemprec.order = Math.round((oldorder + neworder) / 2) + neworder = (elemprec2.order! + elemprec.order) / 2; + elemprec.order = Math.round((oldorder + neworder) / 2); } - await globalStore.saveMyElem($q, t, elemprec) - emit('saveElem', elemprec) + await globalStore.saveMyElem($q, t, elemprec); + emit('saveElem', elemprec); } else if (direz === 1) { // DOWN - neworder = elemnext.order! - elemnext.order = oldorder + neworder = elemnext.order!; + elemnext.order = oldorder; if (oldorder === elemnext.order!) { - const elemnext2 = globalStore.getMyElemNextThisElemId(props.idPage, elemnext._id) + const elemnext2 = globalStore.getMyElemNextThisElemId(props.idPage, elemnext._id); - neworder = (elemnext2.order! + elemnext.order) / 2 - elemnext.order = Math.round((oldorder + neworder) / 2) + neworder = (elemnext2.order! + elemnext.order) / 2; + elemnext.order = Math.round((oldorder + neworder) / 2); } - - await globalStore.saveMyElem($q, t, elemnext) - emit('saveElem', elemnext) + await globalStore.saveMyElem($q, t, elemnext); + emit('saveElem', elemnext); } - myelem.order = neworder - await globalStore.saveMyElem($q, t, myelem) - emit('saveElem', myelem) + myelem.order = neworder; + await globalStore.saveMyElem($q, t, myelem); + emit('saveElem', myelem); } function classiImmagineOptions() { @@ -725,21 +728,18 @@ export default defineComponent({ } function updateClass4(selectedOptions: any) { - // Aggiorna selectedClasses selectedClasses.value = selectedOptions; if (myel.value) { // Imposta myel.class2 come stringa - myel.value.class4 = selectedOptions.join(' '); // Converte l'array in una stringa separata da spazi + myel.value.class4 = selectedOptions.join(' '); // Converte l'array in una stringa separata da spazi - saveElem() + saveElem(); } } - - - onMounted(mounted) + onMounted(mounted); return { tools, @@ -804,7 +804,6 @@ export default defineComponent({ exportPage, importPage, globalStore, - } + }; }, - -}) +}); diff --git a/src/components/CMyEditElem/CMyEditElem.vue b/src/components/CMyEditElem/CMyEditElem.vue index ddb71b0e..a2cf5140 100755 --- a/src/components/CMyEditElem/CMyEditElem.vue +++ b/src/components/CMyEditElem/CMyEditElem.vue @@ -1780,6 +1780,38 @@ label="Pagina di Default" icon="fas fa-play-circle" > + + + + + + +
(cosa: number): ICatProd[] => { - if (cosa === shared_consts.PROD.GAS) - return state.catprods_gas - else if (cosa === shared_consts.PROD.BOTTEGA) - return state.catprods - else - return [...state.catprods, ...state.catprods_gas] - - }, + getCatProds: + (state: IProductsState) => + (cosa: number): ICatProd[] => { + if (cosa === shared_consts.PROD.GAS) return state.catprods_gas; + else if (cosa === shared_consts.PROD.BOTTEGA) return state.catprods; + else return [...state.catprods, ...state.catprods_gas]; + }, getCollane: (state: IProductsState) => (): ICollana[] => { - return state.collane + return state.collane; }, - isDisponibile: (state: IProductsState) => (product: IProduct): boolean => { - return product?.arrvariazioni?.[0]?.quantita > 1 - }, + isDisponibile: + (state: IProductsState) => + (product: IProduct): boolean => { + return product?.arrvariazioni?.[0]?.quantita > 1; + }, - isDisponibilitaOk: (state: IProductsState) => (product: IProduct): boolean => { - return product?.arrvariazioni?.[0]?.quantita > 100 - }, + isDisponibilitaOk: + (state: IProductsState) => + (product: IProduct): boolean => { + return product?.arrvariazioni?.[0]?.quantita > 100; + }, - isQtaLimitata: (state: IProductsState) => (product: IProduct): boolean => { - return product?.arrvariazioni?.[0]?.quantita > 50 && product?.arrvariazioni?.[0]?.quantita < 100 - }, + isQtaLimitata: + (state: IProductsState) => + (product: IProduct): boolean => { + return product?.arrvariazioni?.[0]?.quantita > 50 && product?.arrvariazioni?.[0]?.quantita < 100; + }, - isInEsaurendo: (state: IProductsState) => (product: IProduct): boolean => { - return product?.arrvariazioni?.[0]?.quantita > 0 && product.arrvariazioni?.[0]?.quantita < 50 - }, - isEsaurito: (state: IProductsState) => (product: IProduct): boolean => { - return product?.arrvariazioni?.[0]?.quantita <= 0 && !state.isProssimaUscitaById(product.productInfo.idStatoProdotto) && !state.isPrevenditaById(product.productInfo.idStatoProdotto) - }, + isInEsaurendo: + (state: IProductsState) => + (product: IProduct): boolean => { + return product?.arrvariazioni?.[0]?.quantita > 0 && product.arrvariazioni?.[0]?.quantita < 50; + }, + isEsaurito: + (state: IProductsState) => + (product: IProduct): boolean => { + return ( + product?.arrvariazioni?.[0]?.quantita <= 0 && + !state.isProssimaUscitaById(product.productInfo.idStatoProdotto) && + !state.isPrevenditaById(product.productInfo.idStatoProdotto) + ); + }, - isPubblicatoById: (state: IProductsState) => (idStatoProdotto: number): boolean => { - /* + isPubblicatoById: + (state: IProductsState) => + (idStatoProdotto: number): boolean => { + /* 1 In commercio 3 Ristampa 4 Prossima uscita/pubblicazione @@ -172,235 +211,289 @@ export const useProducts = defineStore('Products', { */ - switch (idStatoProdotto) { - case 1: // In Commercio - case 3: // Ristampa - case 4: // Prossima uscita/pubblicazione - case 6: // In promozione - case 7: // In fase di valutazione - case 8: // 8 Titolo in esaurimento (in attesa Nuova Edizione) - case 9: // In Commercio - case 33: // In commercio (digitale) - case 34: // In prevendita - case 45: // Vendita sito - case 46: // 2023 in commercio - case 47: // Assoluto NO Reso - case 48: // Titolo esaurito - case undefined: - return true; - default: - return false; - } - }, - - isProssimaUscitaById: (state: IProductsState) => (idStatoProdotto: number): boolean => { - // 4 - Prossima uscita - return (idStatoProdotto === 4) - }, - isPrevenditaById: (state: IProductsState) => (idStatoProdotto: number): boolean => { - // 4 - Prossima uscita - // 34 - In Prevendita - return (idStatoProdotto === 34) - }, - isNovitaById: (state: IProductsState) => (date_pub: Date): boolean => { - const sixMonthsAgo = new Date(); - sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6); - return new Date(date_pub).getTime() > sixMonthsAgo.getTime(); - - }, - - isPubblicato: (state: IProductsState) => (productInfo: IProductInfo): boolean => { - return state.isPubblicatoById(productInfo.idStatoProdotto) - }, - - isNovita: (state: IProductsState) => (productInfo: IProductInfo): boolean => { - return state.isNovitaById(productInfo.date_pub) - }, - - isNonVendibile: (state: IProductsState) => (productInfo: IProductInfo): boolean => { - return !state.isPubblicatoById(productInfo.idStatoProdotto) && !state.isProssimaUscitaById(productInfo.idStatoProdotto) - }, - - isProssimaUscita: (state: IProductsState) => (productInfo: IProductInfo): boolean => { - return state.isProssimaUscitaById(productInfo.idStatoProdotto) - }, - - isPrevendita: (state: IProductsState) => (productInfo: IProductInfo): boolean => { - return state.isPrevenditaById(productInfo.idStatoProdotto) - }, - - getDescrStatiProdottoByIdStatoProdotto: (state: IProductsState) => (idStatoProdotto: number): string => { - const ctrec = state.stati_prodotto.find((mystatus: T_Web_StatiProdotto) => mystatus.IdStatoProdotto === idStatoProdotto) - return (ctrec) ? ctrec.Descrizione : '' - }, - - getCasaEditriceByIdPublisher: (state: IProductsState) => (idPublisher: string): string => { - const rectrovato: IPublisher = state.publishers.find((editore: IPublisher) => editore._id === idPublisher) - return (rectrovato) ? rectrovato.name : '' - }, - - - getDescrByIdTipologia: (state: IProductsState) => (idTipologia: number): string => { - const ctrec = state.tipologie.find((mystatus: T_Web_Tipologie) => mystatus.IdTipologia === idTipologia) - return (ctrec) ? ctrec.Descrizione : '' - }, - - getDescrByIdTipoFormato: (state: IProductsState) => (idTipoFormato: number): string => { - const ctrec = state.tipoformato.find((mystatus: T_WEB_TipiFormato) => mystatus.IdTipoFormato === idTipoFormato) - return (ctrec) ? ctrec.Descrizione : '' - }, - - - getArrayidArgomentoByArridCatProds: (state: IProductsState) => (arridCatProds: string[]): string[] => { - const myarr: string[] = [] - for (const idCatProd of arridCatProds) { - const catprod = state.catprods.find((rec: ICatProd) => rec._id === idCatProd) - if (catprod && catprod.idArgomento && !myarr.includes(catprod.idArgomento.toString())) { - myarr.push(catprod.idArgomento.toString()) + switch (idStatoProdotto) { + case 1: // In Commercio + case 3: // Ristampa + case 4: // Prossima uscita/pubblicazione + case 6: // In promozione + case 7: // In fase di valutazione + case 8: // 8 Titolo in esaurimento (in attesa Nuova Edizione) + case 9: // In Commercio + case 33: // In commercio (digitale) + case 34: // In prevendita + case 45: // Vendita sito + case 46: // 2023 in commercio + case 47: // Assoluto NO Reso + case 48: // Titolo esaurito + case undefined: + return true; + default: + return false; } - } - return myarr - }, + }, - getCatProdsByGas: (state: IProductsState) => (idGasOrdine: string): ICatProd[] => { - let arrcat = state.catprods_gas + isProssimaUscitaById: + (state: IProductsState) => + (idStatoProdotto: number): boolean => { + // 4 - Prossima uscita + return idStatoProdotto === 4; + }, + isPrevenditaById: + (state: IProductsState) => + (idStatoProdotto: number): boolean => { + // 4 - Prossima uscita + // 34 - In Prevendita + return idStatoProdotto === 34; + }, + isNovitaById: + (state: IProductsState) => + (date_pub: Date): boolean => { + const sixMonthsAgo = new Date(); + sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6); + return new Date(date_pub).getTime() > sixMonthsAgo.getTime(); + }, - // Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato - if (idGasOrdine) { - arrcat = state.catprods_gas.filter((rec: ICatProd) => { - const arrprod = state.products.filter((prod: IProduct) => { - if (prod.idGasordine === idGasOrdine && prod.productInfo.idCatProds?.includes(rec._id)) { - return true - } + isPubblicato: + (state: IProductsState) => + (productInfo: IProductInfo): boolean => { + return state.isPubblicatoById(productInfo.idStatoProdotto); + }, - }) - return arrprod.length > 0 ? true : false - }) + isNovita: + (state: IProductsState) => + (productInfo: IProductInfo): boolean => { + return state.isNovitaById(productInfo.date_pub); + }, - } else { - return [] - } + isNonVendibile: + (state: IProductsState) => + (productInfo: IProductInfo): boolean => { + return ( + !state.isPubblicatoById(productInfo.idStatoProdotto) && + !state.isProssimaUscitaById(productInfo.idStatoProdotto) + ); + }, + isProssimaUscita: + (state: IProductsState) => + (productInfo: IProductInfo): boolean => { + return state.isProssimaUscitaById(productInfo.idStatoProdotto); + }, - return arrcat - }, + isPrevendita: + (state: IProductsState) => + (productInfo: IProductInfo): boolean => { + return state.isPrevenditaById(productInfo.idStatoProdotto); + }, - getCatProdsStrByCatProds: (state: IProductsState) => (catProds: ICatProd[]): string => { - let mystr = '' - for (const catprod of catProds) { - let myarrcat = null - if (tools.isObject(catprod)) { - myarrcat = catprod + getDescrStatiProdottoByIdStatoProdotto: + (state: IProductsState) => + (idStatoProdotto: number): string => { + const ctrec = state.stati_prodotto.find( + (mystatus: T_Web_StatiProdotto) => mystatus.IdStatoProdotto === idStatoProdotto + ); + return ctrec ? ctrec.Descrizione : ''; + }, + + getCasaEditriceByIdPublisher: + (state: IProductsState) => + (idPublisher: string): string => { + const rectrovato: IPublisher = state.publishers.find((editore: IPublisher) => editore._id === idPublisher); + return rectrovato ? rectrovato.name : ''; + }, + + getDescrByIdTipologia: + (state: IProductsState) => + (idTipologia: number): string => { + const ctrec = state.tipologie.find((mystatus: T_Web_Tipologie) => mystatus.IdTipologia === idTipologia); + return ctrec ? ctrec.Descrizione : ''; + }, + + getDescrByIdTipoFormato: + (state: IProductsState) => + (idTipoFormato: number): string => { + const ctrec = state.tipoformato.find((mystatus: T_WEB_TipiFormato) => mystatus.IdTipoFormato === idTipoFormato); + return ctrec ? ctrec.Descrizione : ''; + }, + + getArrayidArgomentoByArridCatProds: + (state: IProductsState) => + (arridCatProds: string[]): string[] => { + const myarr: string[] = []; + for (const idCatProd of arridCatProds) { + const catprod = state.catprods.find((rec: ICatProd) => rec._id === idCatProd); + if (catprod && catprod.idArgomento && !myarr.includes(catprod.idArgomento.toString())) { + myarr.push(catprod.idArgomento.toString()); + } + } + return myarr; + }, + + getCatProdsByGas: + (state: IProductsState) => + (idGasOrdine: string): ICatProd[] => { + let arrcat = state.catprods_gas; + + // Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato + if (idGasOrdine) { + arrcat = state.catprods_gas.filter((rec: ICatProd) => { + const arrprod = state.products.filter((prod: IProduct) => { + if (prod.idGasordine === idGasOrdine && prod.productInfo.idCatProds?.includes(rec._id)) { + return true; + } + }); + return arrprod.length > 0 ? true : false; + }); } else { - myarrcat = state.catprods.find((rec: ICatProd) => rec._id === catprod) - } - if (myarrcat) { - if (mystr) - mystr += ' - ' - mystr += myarrcat.name - } - } - return mystr - }, - - getSubCatProdsStrBySubCatProds: (state: IProductsState) => (idSubCatProds: string[]): string => { - let mystr = ''; - if (Array.isArray(idSubCatProds) && idSubCatProds.length > 0) { - const names = idSubCatProds.map(id => { - const subCatProd = state.subcatprods.find((rec: ISubCatProd) => rec._id === id); - return subCatProd ? subCatProd.name : ''; - }).filter(name => name !== ''); - - mystr = names.join(' - '); - } - return mystr; - }, - - getTotaleOrdineByOrdId: (state: IProductsState) => (idOrdine: string, idGasordine: string, totale: boolean, mostra_solo_ordini_produttore: boolean, status: number): number => { - - let arrprod = [] - - if (totale) { - arrprod = state.orders.filter((rec: IOrderCart) => { - if (idGasordine && !rec.items?.some(item => item.order && item.order.idGasordine === idGasordine) || (rec.status !== status)) { - return false; // Skip records not matching gasordine condition - } - return true; - }); - - } else { - arrprod = state.orders.filter((rec: IOrderCart) => { - if (idGasordine && !rec.items?.some(item => item.order && item.order.idGasordine === idGasordine) || (rec._id !== idOrdine)) { - return false; // Skip records not matching gasordine condition - } - return true; - }); + return []; } - let subtotalPrice = 0 + return arrcat; + }, - arrprod.forEach((rec: IOrderCart) => { - rec.items?.forEach(item => { - if (item.order && ((mostra_solo_ordini_produttore && (item.order.idGasordine === idGasordine)) || !mostra_solo_ordini_produttore)) { - const qtyparz = item.order.quantity + item.order.quantitypreordered - subtotalPrice += item.order.price * qtyparz + getCatProdsStrByCatProds: + (state: IProductsState) => + (catProds: ICatProd[]): string => { + let mystr = ''; + for (const catprod of catProds) { + let myarrcat = null; + if (tools.isObject(catprod)) { + myarrcat = catprod; + } else { + myarrcat = state.catprods.find((rec: ICatProd) => rec._id === catprod); } - }); - }); + if (myarrcat) { + if (mystr) mystr += ' - '; + mystr += myarrcat.name; + } + } + return mystr; + }, - return subtotalPrice; - }, + getSubCatProdsStrBySubCatProds: + (state: IProductsState) => + (idSubCatProds: string[]): string => { + let mystr = ''; + if (Array.isArray(idSubCatProds) && idSubCatProds.length > 0) { + const names = idSubCatProds + .map((id) => { + const subCatProd = state.subcatprods.find((rec: ISubCatProd) => rec._id === id); + return subCatProd ? subCatProd.name : ''; + }) + .filter((name) => name !== ''); - getCatProdDescrStrByIdCatProd: (state: IProductsState) => (idCatProd: string): string => { - const myfirstcat = state.catprods.find((rec: ICatProd) => rec._id === idCatProd) + mystr = names.join(' - '); + } + return mystr; + }, - if (myfirstcat) { - return myfirstcat.descr_estesa! - } - return '' - }, - getTotaliProdottiByIdCatProd: (state: IProductsState) => (idCatProd: string): number => { - const myfirstcat = state.catprtotali!.find((rec: ICatPrTotali) => rec._id === idCatProd) + getTotaleOrdineByOrdId: + (state: IProductsState) => + ( + idOrdine: string, + idGasordine: string, + totale: boolean, + mostra_solo_ordini_produttore: boolean, + status: number + ): number => { + let arrprod = []; - if (myfirstcat) { - return myfirstcat.quanti! - } - return 0 - }, - - getTotaliProdottiByIdCollana: (state: IProductsState) => (idCollana: string): number => { - const myfirstcat = state.collane.find((rec: ICollaneTotali) => rec._id === idCollana) - - if (myfirstcat) { - return myfirstcat.quanti! - } - return 0 - }, - - - getSubCatProdsByGas: (state: IProductsState) => (idGasOrdine: string, idCatProd: string): ISubCatProd[] => { - let arrcat = state.subcatprods - - // Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato - if (idGasOrdine) { - arrcat = state.subcatprods.filter((rec: ISubCatProd) => { - const arrprod = state.products.filter((prod: IProduct) => { - if (prod.idGasordine === idGasOrdine - && prod.productInfo.idSubCatProds?.includes(rec._id) - && prod.productInfo.idCatProds?.includes(idCatProd) + if (totale) { + arrprod = state.orders.filter((rec: IOrderCart) => { + if ( + (idGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) || + rec.status !== status ) { - return true + return false; // Skip records not matching gasordine condition } + return true; + }); + } else { + arrprod = state.orders.filter((rec: IOrderCart) => { + if ( + (idGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) || + rec._id !== idOrdine + ) { + return false; // Skip records not matching gasordine condition + } + return true; + }); + } - }) - return arrprod.length > 0 ? true : false - }) + let subtotalPrice = 0; - } else { - return [] - } - return arrcat - }, + arrprod.forEach((rec: IOrderCart) => { + rec.items?.forEach((item) => { + if ( + item.order && + ((mostra_solo_ordini_produttore && item.order.idGasordine === idGasordine) || + !mostra_solo_ordini_produttore) + ) { + const qtyparz = item.order.quantity + item.order.quantitypreordered; + subtotalPrice += item.order.price * qtyparz; + } + }); + }); + + return subtotalPrice; + }, + + getCatProdDescrStrByIdCatProd: + (state: IProductsState) => + (idCatProd: string): string => { + const myfirstcat = state.catprods.find((rec: ICatProd) => rec._id === idCatProd); + + if (myfirstcat) { + return myfirstcat.descr_estesa!; + } + return ''; + }, + getTotaliProdottiByIdCatProd: + (state: IProductsState) => + (idCatProd: string): number => { + const myfirstcat = state.catprtotali!.find((rec: ICatPrTotali) => rec._id === idCatProd); + + if (myfirstcat) { + return myfirstcat.quanti!; + } + return 0; + }, + + getTotaliProdottiByIdCollana: + (state: IProductsState) => + (idCollana: string): number => { + const myfirstcat = state.collane.find((rec: ICollaneTotali) => rec._id === idCollana); + + if (myfirstcat) { + return myfirstcat.quanti!; + } + return 0; + }, + + getSubCatProdsByGas: + (state: IProductsState) => + (idGasOrdine: string, idCatProd: string): ISubCatProd[] => { + let arrcat = state.subcatprods; + + // Ottieni le categorie solo per i "products" che hanno come idGasOrdine il valore passato + if (idGasOrdine) { + arrcat = state.subcatprods.filter((rec: ISubCatProd) => { + const arrprod = state.products.filter((prod: IProduct) => { + if ( + prod.idGasordine === idGasOrdine && + prod.productInfo.idSubCatProds?.includes(rec._id) && + prod.productInfo.idCatProds?.includes(idCatProd) + ) { + return true; + } + }); + return arrprod.length > 0 ? true : false; + }); + } else { + return []; + } + return arrcat; + }, getAuthors: (state: IProductsState) => (): any[] => { // Get the list of authors, for the q-select component using state.authors array @@ -413,40 +506,43 @@ export const useProducts = defineStore('Products', { value: '', }, ...state.authors.map((rec: IAuthor) => { - return { label: rec.name + (rec.surname ? ' ' + rec.surname : ''), value: rec._id } + return { label: rec.name + (rec.surname ? ' ' + rec.surname : ''), value: rec._id }; }), - ] - return options + ]; + return options; }, - getNumProdTot: (state: IProductsState) => (): number => { - return state.products.length + return state.products.length; }, - getProducts: (state: IProductsState) => (cosa?: number): IProduct[] => { - if (!!cosa) { - return state.products.filter((rec: IProduct) => { - const hasGasOrdines = rec.idGasordine + getProducts: + (state: IProductsState) => + (cosa?: number): IProduct[] => { + if (!!cosa) { + return state.products.filter((rec: IProduct) => { + const hasGasOrdines = rec.idGasordine; - if ((cosa === shared_consts.PROD.GAS && hasGasOrdines) || - (cosa === shared_consts.PROD.BOTTEGA && (!hasGasOrdines))) { - return true; - } + if ( + (cosa === shared_consts.PROD.GAS && hasGasOrdines) || + (cosa === shared_consts.PROD.BOTTEGA && !hasGasOrdines) + ) { + return true; + } - return false; - }); - } else { - return state.products; - } - }, + return false; + }); + } else { + return state.products; + } + }, updateDataProduct: (state: IProductsState) => (res: any) => { if (res && res.data.product) { // Update product from server - const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id) + const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id); if (indelem >= 0) { - state.products[indelem] = { ...res.data.product } + state.products[indelem] = { ...res.data.product }; /*if (!res.data.orders) { // aggiorna anche tutti i product negli ordini ! @@ -461,210 +557,239 @@ export const useProducts = defineStore('Products', { } } if (res && res.data.orders) { - state.orders = res.data.orders + state.orders = res.data.orders; } - if (res && res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) - state.cart = res.data.cart + if (res && res.data.cart) { + // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) + state.cart = res.data.cart; } - }, - getProductByCode: (state: IProductsState) => (code: string): IProduct => { - if (!code) { - return getRecordProductEmpty() - } + getProductByCode: + (state: IProductsState) => + (code: string): IProduct => { + if (!code) { + return getRecordProductEmpty(); + } - const prod = state.products.find((prod: IProduct) => { - if (prod.productInfo.code === code) - return prod - else - return null - }) - return prod ? prod : getRecordProductEmpty() - }, + const prod = state.products.find((prod: IProduct) => { + if (prod.productInfo.code === code) return prod; + else return null; + }); + return prod ? prod : getRecordProductEmpty(); + }, getCart: (state: IProductsState) => (): ICart => { - return state.cart + return state.cart; }, - getOrdersAllCart: (state: IProductsState) => (idGasordine: string): IOrderCart[] => { - return state.orders.filter((rec: IOrderCart) => { - if ((idGasordine && !rec.items?.some(item => item.order && item.order.idGasordine === idGasordine))) { - return false; // Skip records not matching gasordine condition - } - return true - }) - }, + getOrdersAllCart: + (state: IProductsState) => + (idGasordine: string): IOrderCart[] => { + return state.orders.filter((rec: IOrderCart) => { + if (idGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) { + return false; // Skip records not matching gasordine condition + } + return true; + }); + }, getNumOrders: (state: IProductsState) => (): number => { - return state.orders.length + return state.orders.length; }, - getOrdersCart: (state: IProductsState) => (tipoord: number, hasGasordine: any, idGasordine: string): IOrderCart[] | undefined => { - return state.orders.filter((rec: IOrderCart) => { - if (idGasordine && !rec.items?.some(item => item.order && item.order.idGasordine === idGasordine)) { - return false; // Skip records not matching gasordine condition + getOrdersCart: + (state: IProductsState) => + (tipoord: number, hasGasordine: any, idGasordine: string): IOrderCart[] | undefined => { + return state.orders.filter((rec: IOrderCart) => { + if (idGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) { + return false; // Skip records not matching gasordine condition + } + + if (hasGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine)) { + return false; // Skip records not matching gasordine condition + } + + switch (tipoord) { + case shared_consts.OrderStat.IN_CORSO.value: + return !rec.status || rec.status <= shared_consts.OrderStatus.CHECKOUT_SENT; + case shared_consts.OrderStat.PREPARED.value: + return rec.status === shared_consts.OrderStatus.PREPARED; + case shared_consts.OrderStat.CONFERMATI.value: + return rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED; + case shared_consts.OrderStat.PAGATI.value: + return rec.status === shared_consts.OrderStatus.PAYED; + case shared_consts.OrderStat.DELIVERED.value: + return rec.status === shared_consts.OrderStatus.DELIVERED; + case shared_consts.OrderStat.SHIPPED.value: + return rec.status === shared_consts.OrderStatus.SHIPPED; + case shared_consts.OrderStat.RECEIVED.value: + return rec.status === shared_consts.OrderStatus.RECEIVED; + case shared_consts.OrderStat.COMPLETATI.value: + return rec.status === shared_consts.OrderStatus.COMPLETED; + case shared_consts.OrderStat.CANCELLATI.value: + return rec.status === shared_consts.OrderStatus.CANCELED; + default: + return false; // Invalid tipoord + } + }); + }, + + existProductInCart: + (state: IProductsState) => + (idproduct: string): boolean => { + // console.log('.cart.items', this.cart.items) + if (state.cart.items) { + const ris = state.cart.items + .filter((item: IBaseOrder) => item.order.idProduct === idproduct) + .reduce((sum, rec) => sum + 1, 0); + return ris > 0; } - - if (hasGasordine && !rec.items?.some(item => item.order && item.order.idGasordine)) { - return false; // Skip records not matching gasordine condition + return false; + }, + getOrderProductInCart: + (state: IProductsState) => + (idproduct: string): IOrder | null => { + // console.log('.cart.items', this.cart.items) + if (state.cart.items) { + const ris = state.cart.items.find((item: IBaseOrder) => + item.order ? item.order.idProduct === idproduct : false + ); + return ris ? ris.order : null; } + return null; + }, - switch (tipoord) { - case shared_consts.OrderStat.IN_CORSO.value: - return !rec.status || rec.status <= shared_consts.OrderStatus.CHECKOUT_SENT; - case shared_consts.OrderStat.PREPARED.value: - return rec.status === shared_consts.OrderStatus.PREPARED; - case shared_consts.OrderStat.CONFERMATI.value: - return rec.status === shared_consts.OrderStatus.ORDER_CONFIRMED; - case shared_consts.OrderStat.PAGATI.value: - return rec.status === shared_consts.OrderStatus.PAYED; - case shared_consts.OrderStat.DELIVERED.value: - return rec.status === shared_consts.OrderStatus.DELIVERED; - case shared_consts.OrderStat.SHIPPED.value: - return rec.status === shared_consts.OrderStatus.SHIPPED; - case shared_consts.OrderStat.RECEIVED.value: - return rec.status === shared_consts.OrderStatus.RECEIVED; - case shared_consts.OrderStat.COMPLETATI.value: - return rec.status === shared_consts.OrderStatus.COMPLETED; - case shared_consts.OrderStat.CANCELLATI.value: - return rec.status === shared_consts.OrderStatus.CANCELED; - default: - return false; // Invalid tipoord + getOrderProductInOrdersCart: + (state: IProductsState) => + (idordercart: string, idproduct: string): IOrder | null => { + // console.log('.cart.items', this.cart.items) + if (state.orders) { + const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart); + if (orderscart) { + const ris = orderscart.items!.find((item: IBaseOrder) => item.order.idProduct === idproduct); + return ris ? ris.order : null; + } } - }); - }, + return null; + }, - existProductInCart: (state: IProductsState) => (idproduct: string): boolean => { - // console.log('.cart.items', this.cart.items) - if (state.cart.items) { - const ris = state.cart.items.filter((item: IBaseOrder) => item.order.idProduct === idproduct).reduce((sum, rec) => sum + 1, 0) - return ris > 0 - } - return false - }, - getOrderProductInCart: (state: IProductsState) => (idproduct: string): IOrder | null => { - // console.log('.cart.items', this.cart.items) - if (state.cart.items) { - const ris = state.cart.items.find((item: IBaseOrder) => item.order ? (item.order.idProduct === idproduct) : false) - return ris ? ris.order : null - } - return null - }, - - getOrderProductInOrdersCart: (state: IProductsState) => (idordercart: string, idproduct: string): IOrder | null => { - // console.log('.cart.items', this.cart.items) - if (state.orders) { - const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart) - if (orderscart) { - const ris = orderscart.items!.find((item: IBaseOrder) => item.order.idProduct === idproduct) - return ris ? ris.order : null + getOrdersCartById: + (state: IProductsState) => + (idordercart: string): IOrderCart => { + if (state.orders) { + const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart); + return orderscart ?? getRecordOrdersCartEmpty(); } - } - return null - }, + return getRecordOrdersCartEmpty(); + }, - getOrdersCartById: (state: IProductsState) => (idordercart: string): IOrderCart => { - if (state.orders) { - const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart) - return orderscart ?? getRecordOrdersCartEmpty() - } - return getRecordOrdersCartEmpty() - }, + getSumQtyPreOrderInOrdersCart: + (state: IProductsState) => + (idproduct: string): number => { + let totalQuantity = 0; - getSumQtyPreOrderInOrdersCart: (state: IProductsState) => (idproduct: string): number => { - let totalQuantity = 0; - - if (state.orders) { - const orderscart = state.orders - if (orderscart) { - for (const myord of orderscart) { - if (myord.items) { - for (const item of myord.items) { - if (item.order) { - if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) { - totalQuantity += (item.order.quantitypreordered) || 0; + if (state.orders) { + const orderscart = state.orders; + if (orderscart) { + for (const myord of orderscart) { + if (myord.items) { + for (const item of myord.items) { + if (item.order) { + if ( + item.order.idProduct === idproduct && + item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT + ) { + totalQuantity += item.order.quantitypreordered || 0; + } } } } } } } - } - return totalQuantity - }, + return totalQuantity; + }, - getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => { - let totalQuantity = 0; + getSumQtyOrderProductInOrdersCart: + (state: IProductsState) => + (idproduct: string): number => { + let totalQuantity = 0; - if (state.orders) { - const orderscart = state.orders - if (orderscart) { - for (const myord of orderscart) { - if (myord.items) { - for (const item of myord.items) { - if (item.order) { - if ((item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT)) { - totalQuantity += (item.order.quantity) || 0; + if (state.orders) { + const orderscart = state.orders; + if (orderscart) { + for (const myord of orderscart) { + if (myord.items) { + for (const item of myord.items) { + if (item.order) { + if ( + item.order.idProduct === idproduct && + item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT + ) { + totalQuantity += item.order.quantity || 0; + } } } } } } } - } - return totalQuantity - }, + return totalQuantity; + }, - getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => { - try { - if (state.orders) { - const ris = state.orders.filter((orderscart: IOrderCart) => { - return orderscart.items!.some(item => { - if (item.order) - return (item.order.idProduct === idproduct) - && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT) - }) - }) - // console.log('Ordini ', ris) - return ris ? ris : [] + getOrdersCartByIdProduct: + (state: IProductsState) => + (idproduct: string): IOrderCart[] | [] => { + try { + if (state.orders) { + const ris = state.orders.filter((orderscart: IOrderCart) => { + return orderscart.items!.some((item) => { + if (item.order) + return ( + item.order.idProduct === idproduct && item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT + ); + }); + }); + // console.log('Ordini ', ris) + return ris ? ris : []; + } + } catch (e) { + console.error('Err', e); } - } catch (e) { - console.error('Err', e) - } - return [] - }, + return []; + }, - getOrdersCartInAttesaByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => { - try { - if (state.orders) { - const ris = state.orders.filter((orderscart: IOrderCart) => { - return orderscart.items!.some(item => { - if (item.order) - return (item.order.idProduct === idproduct) - && (item.order.status! <= shared_consts.OrderStatus.CHECKOUT_SENT) - }) - }) - // console.log('Ordini ', ris) - return ris ? ris : [] + getOrdersCartInAttesaByIdProduct: + (state: IProductsState) => + (idproduct: string): IOrderCart[] | [] => { + try { + if (state.orders) { + const ris = state.orders.filter((orderscart: IOrderCart) => { + return orderscart.items!.some((item) => { + if (item.order) + return ( + item.order.idProduct === idproduct && item.order.status! <= shared_consts.OrderStatus.CHECKOUT_SENT + ); + }); + }); + // console.log('Ordini ', ris) + return ris ? ris : []; + } + } catch (e) { + console.error('Err', e); } - } catch (e) { - console.error('Err', e) - } - return [] - }, - + return []; + }, getRecordEmpty: (state: IProductsState) => (): IProduct => { - return getRecordProductEmpty() + return getRecordProductEmpty(); }, - }, actions: { - createOrderByProduct(product: IProduct, order: IOrder): IOrder { - const userStore = useUserStore() + const userStore = useUserStore(); const myorder: IOrder = { userId: this.userActive._id, idapp: import.meta.env.VITE_APP_ID, @@ -672,7 +797,7 @@ export const useProducts = defineStore('Products', { TotalPriceProduct: 0, TotalPriceProductCalc: 0, idProduct: product._id, - product, // Copia tutto l'oggetto Product ! + product, // Copia tutto l'oggetto Product ! // Ordine: price: product.price, @@ -682,17 +807,15 @@ export const useProducts = defineStore('Products', { idStorehouse: order.idStorehouse, idGasordine: order.idGasordine, //++Add Fields - } + }; - return myorder + return myorder; }, initcat() { - // rec.userId = this.userActive._id - return this.getRecordEmpty() - + return this.getRecordEmpty(); }, /*resetProducts() { @@ -702,29 +825,27 @@ export const useProducts = defineStore('Products', { },*/ async getProductById(id: string, forza?: boolean): Promise { - let prod = null + let prod = null; try { if (!id) { - return null + return null; } if (!this.products || forza) { // Se non lo carico all'avvio, allora fai la chiamata al server - prod = await this.loadProductById(id) + prod = await this.loadProductById(id); } else { - prod = this.products.find((prod: IProduct) => prod._id === id) + prod = this.products.find((prod: IProduct) => prod._id === id); } } catch (e) { - console.error('Err', e) + console.error('Err', e); } - return prod ? prod : getRecordProductEmpty() + return prod ? prod : getRecordProductEmpty(); }, - async loadProducts(loadonlyifempty?: boolean) { - - const userStore = useUserStore() - const globalStore = useGlobalStore() + const userStore = useUserStore(); + const globalStore = useGlobalStore(); //console.log('loadProducts') @@ -738,137 +859,128 @@ export const useProducts = defineStore('Products', { // } if (loadonlyifempty) { - if (this.products?.length > 0) - return true + if (this.products?.length > 0) return true; } - let ris = null + let ris = null; - let myIdActiveSelected = userStore.my._id - if (tools.isSeller()) - myIdActiveSelected = tools.getCookie(tools.COOK_SELCART, userStore.my._id, false) + let myIdActiveSelected = userStore.my._id; + if (tools.isSeller()) myIdActiveSelected = tools.getCookie(tools.COOK_SELCART, userStore.my._id, false); - const trovato = userStore.usersList.find((user: IUserShort) => user._id === myIdActiveSelected) - if (trovato) - this.userActive = trovato - else - this.userActive = userStore.my + const trovato = userStore.usersList.find((user: IUserShort) => user._id === myIdActiveSelected); + if (trovato) this.userActive = trovato; + else this.userActive = userStore.my; - console.log('userActive', this.userActive) + console.log('userActive', this.userActive); ris = await Api.SendReq('/products', 'POST', { userId: this.userActive._id }) .then((res) => { if (res.data.products) { // console.log('aggiorna prodotti') - this.products = [] - this.products = res.data.products + this.products = []; + this.products = res.data.products; } else { - this.products = [] + this.products = []; } if (res.data.orders) { - this.orders = [] - this.orders = res.data.orders + this.orders = []; + this.orders = res.data.orders; } else { - this.orders = [] + this.orders = []; } - return res + return res; }) .catch((error) => { - console.log('error getProducts', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error getProducts', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); // ApiTables.aftercalling(ris, checkPending, 'categories') - return ris + return ris; }, async updateOrderByOrder(idOrdersCart: string, idOrder: string, paramstoupdate: any) { - - const userStore = useUserStore() - const globalStore = useGlobalStore() + const userStore = useUserStore(); + const globalStore = useGlobalStore(); // console.log('loadProducts') - if (!globalStore.site.confpages.enableEcommerce) - return null + if (!globalStore.site.confpages.enableEcommerce) return null; - console.log('updateOrderByOrder', 'userid=', this.userActive._id) + console.log('updateOrderByOrder', 'userid=', this.userActive._id); - let ris = null + let ris = null; ris = await Api.SendReq('/orders/updateord', 'POST', { idOrdersCart, idOrder, paramstoupdate }) .then((res) => { - let myorderscart = res.data.orderscart + let myorderscart = res.data.orderscart; if (res) { - myorderscart = res.data && res.data.orderscart ? res.data.orderscart : null + myorderscart = res.data && res.data.orderscart ? res.data.orderscart : null; if (myorderscart) { - const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id) + const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id); if (idord >= 0) { - console.log('aggiorna ordine') - this.orders[idord] = { ...myorderscart } + console.log('aggiorna ordine'); + this.orders[idord] = { ...myorderscart }; } } } - return myorderscart + return myorderscart; }) .catch((error) => { - console.log('error updateOrderByOrder', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error updateOrderByOrder', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); // ApiTables.aftercalling(ris, checkPending, 'categories') - return ris + return ris; }, async updateOrdersCartById(idOrdersCart: string, paramstoupdate: any) { - - const userStore = useUserStore() - const globalStore = useGlobalStore() + const userStore = useUserStore(); + const globalStore = useGlobalStore(); // console.log('loadProducts') - if (!globalStore.site.confpages.enableEcommerce) - return null + if (!globalStore.site.confpages.enableEcommerce) return null; - console.log('updateOrdersCartById', 'userid=', this.userActive._id) + console.log('updateOrdersCartById', 'userid=', this.userActive._id); - let ris = null + let ris = null; ris = await Api.SendReq('/orders/update', 'POST', { idOrdersCart, paramstoupdate }) .then((res) => { - let myorderscart = res.data.orderscart + let myorderscart = res.data.orderscart; if (res) { if (myorderscart) { - const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id) + const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id); if (idord >= 0) { - console.log('aggiorna orderscart') - this.orders[idord] = myorderscart + console.log('aggiorna orderscart'); + this.orders[idord] = myorderscart; } } } - return myorderscart + return myorderscart; }) .catch((error) => { - console.log('error updateOrderByOrder', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error updateOrderByOrder', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); // ApiTables.aftercalling(ris, checkPending, 'categories') - return ris + return ris; }, async loadProductById(id: string) { - - const userStore = useUserStore() - const globalStore = useGlobalStore() + const userStore = useUserStore(); + const globalStore = useGlobalStore(); //if (!globalStore.site.confpages.enableEcommerce) // return null @@ -877,123 +989,110 @@ export const useProducts = defineStore('Products', { // return new Types.AxiosError(0, null, 0, '') // } - let ris = null + let ris = null; ris = await Api.SendReq('/products/id/' + id, 'GET', null) .then((res) => { - console.log('product', res.data.product) - if (res.data.product) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) - this.updateDataProduct(res) - return res.data.product + console.log('product', res.data.product); + if (res.data.product) { + // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) + this.updateDataProduct(res); + return res.data.product; } else { - return null + return null; } }) .catch((error) => { - console.log('error getProduct', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error getProduct', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); - return ris + return ris; }, - async loadOrders() { - // console.log('loadOrders') - const userStore = useUserStore() - const globalStore = useGlobalStore() + const userStore = useUserStore(); + const globalStore = useGlobalStore(); - if (!globalStore.site.confpages.enableEcommerce) - return null + if (!globalStore.site.confpages.enableEcommerce) return null; - if (!this.userActive._id) - return null + if (!this.userActive._id) return null; // if (this.userActive._id === '') { // return new Types.AxiosError(0, null, 0, '') // } - let ris = null + let ris = null; ris = await Api.SendReq('/cart/' + this.userActive._id, 'GET', null) .then((res) => { - if (res.data && res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) - this.cart = res.data.cart + if (res.data && res.data.cart) { + // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) + this.cart = res.data.cart; } else { - this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' } + this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }; } - this.updateDataProduct(res) + this.updateDataProduct(res); - return res + return res; }) .catch((error) => { - console.log('error loadOrders', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error loadOrders', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); // ApiTables.aftercalling(ris, checkPending, 'categories') - return ris + return ris; }, - async removeFromCart({ order }: { order: IOrder }) { + const userStore = useUserStore(); - const userStore = useUserStore() + return Api.SendReq('/cart/' + this.userActive._id, 'DELETE', { orderId: order._id }).then((res) => { + this.updateDataProduct(res); - return Api.SendReq('/cart/' + this.userActive._id, 'DELETE', { orderId: order._id }) - .then((res) => { - this.updateDataProduct(res) - - return res - }) + return res; + }); }, async getGestoreOrdini({ idGasordine }: { idGasordine: string }) { - const userStore = useUserStore() + const userStore = useUserStore(); - let useractive = this.userActive._id - if (!useractive) - useractive = userStore.my._id; + let useractive = this.userActive._id; + if (!useractive) useractive = userStore.my._id; - return Api.SendReq('/cart/' + useractive + '/gestord', 'POST', { idGasordine }) - .then((res) => { - if (res) - return res.data.arrout - else - return [] - - }) + return Api.SendReq('/cart/' + useractive + '/gestord', 'POST', { idGasordine }).then((res) => { + if (res) return res.data.arrout; + else return []; + }); }, - async addToCart({ product, order, addqty }: { product: IProduct, order: IOrder, addqty: boolean }) { + async addToCart({ product, order, addqty }: { product: IProduct; order: IOrder; addqty: boolean }) { + const userStore = useUserStore(); + const globalStore = useGlobalStore(); - const userStore = useUserStore() - const globalStore = useGlobalStore() - - if (!globalStore.site.confpages.enableEcommerce) - return null + if (!globalStore.site.confpages.enableEcommerce) return null; let neworder = null; // Controlla se esiste già nel carrello, allora semplicemente aggiungerò la quantità: if (this.existProductInCart(product._id)) { - const ordcart = this.getOrderProductInCart(product._id) + const ordcart = this.getOrderProductInCart(product._id); if (ordcart) { - - if (!addqty && ((ordcart.quantity + ordcart.quantitypreordered) === 1)) { + if (!addqty && ordcart.quantity + ordcart.quantitypreordered === 1) { // sto per rimuovere l'ultimo pezzo, quindi cancello direttamente - const risrem = await this.removeFromCart({ order: ordcart }) + const risrem = await this.removeFromCart({ order: ordcart }); if (risrem) { - order.quantity = 0 - order.quantitypreordered = 0 - return true + order.quantity = 0; + order.quantitypreordered = 0; + return true; } else { - return false + return false; } } @@ -1005,143 +1104,141 @@ export const useProducts = defineStore('Products', { if (res && res.msgerr) { return res; } else if (res && res.risult) { - order.quantity = res.myord.quantity - order.quantitypreordered = res.myord.quantitypreordered + order.quantity = res.myord.quantity; + order.quantitypreordered = res.myord.quantitypreordered; } return res; - }) + }); } } else { if (this.isQtyAvailableByProduct(product)) { - order.quantity = product.minBuyQty || 1 - order.quantitypreordered = 0 + order.quantity = product.minBuyQty || 1; + order.quantitypreordered = 0; } else { if (this.isInPreorderByProduct(product)) { - order.quantitypreordered = product.minBuyQty || 1 - order.quantity = 0 + order.quantitypreordered = product.minBuyQty || 1; + order.quantity = 0; } } if (!order.idStorehouse) { if (product.storehouses.length === 1) { - order.idStorehouse = product.storehouses[0]._id + order.idStorehouse = product.storehouses[0]._id; } else { try { - order.idStorehouse = globalStore.storehouses?.length ? globalStore.storehouses[0]._id : '' - } catch (e) { - - } + order.idStorehouse = globalStore.storehouses?.length ? globalStore.storehouses[0]._id : ''; + } catch (e) {} } } if (!order.idGasordine && order.quantitypreordered > 0) { if (product.gasordine && product.gasordine._id) { - order.idGasordine = product.gasordine._id + order.idGasordine = product.gasordine._id; } else { - order.idGasordine = globalStore.gasordines?.length ? globalStore.gasordines[0]._id : '' + order.idGasordine = globalStore.gasordines?.length ? globalStore.gasordines[0]._id : ''; } } if (order.idStorehouse) { - neworder = this.createOrderByProduct(product, order) + neworder = this.createOrderByProduct(product, order); } } // if (neworder && !neworder.idStorehouse) // return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, 'Nessuno Store') - console.log('addToCart', 'userid=', this.userActive._id, neworder) + console.log('addToCart', 'userid=', this.userActive._id, neworder); - let ris = null + let ris = null; ris = await Api.SendReq('/cart/' + this.userActive._id, 'POST', { order: neworder }) .then((res) => { - if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) - this.cart = res.data.cart + if (res.data.cart) { + // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) + this.cart = res.data.cart; } else { - this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' } + this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }; } - this.updateDataProduct(res) + this.updateDataProduct(res); - return { risult: !!res, myord: res.data.myord, msgerr: res.data.msgerr } + return { risult: !!res, myord: res.data.myord, msgerr: res.data.msgerr }; }) .catch((error) => { - console.log('error addToCart', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error addToCart', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); // ApiTables.aftercalling(ris, checkPending, 'categories') - return ris + return ris; }, - async addSubQtyToItem({ addqty, subqty, order }: { addqty: boolean, subqty: boolean, order: IOrder }) { + async addSubQtyToItem({ addqty, subqty, order }: { addqty: boolean; subqty: boolean; order: IOrder }) { + const userStore = useUserStore(); + const globalStore = useGlobalStore(); - const userStore = useUserStore() - const globalStore = useGlobalStore() - - if (!globalStore.site.confpages.enableEcommerce) - return null + if (!globalStore.site.confpages.enableEcommerce) return null; // console.log('addSubQtyToItem', 'userid=', this.userActive._id, order) - let ris = null + let ris = null; ris = await Api.SendReq('/cart/' + this.userActive._id, 'POST', { addqty, subqty, order }) .then((res: any) => { - this.updateDataProduct(res) + this.updateDataProduct(res); - return { risult: !!res, myord: res.data.myord, msgerr: res.msgerr } + return { risult: !!res, myord: res.data.myord, msgerr: res.msgerr }; }) .catch((error) => { - console.log('error addSubQtyToItem', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error addSubQtyToItem', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); // ApiTables.aftercalling(ris, checkPending, 'categories') - return ris + return ris; }, getOptions(sendmail: boolean) { return { - sendmail - } + sendmail, + }; }, - async CreateOrdersCart({ cart_id, status, note }: { cart_id: string, status: number, note: string }) { + async CreateOrdersCart({ cart_id, status, note }: { cart_id: string; status: number; note: string }) { + const userStore = useUserStore(); + const globalStore = useGlobalStore(); - const userStore = useUserStore() - const globalStore = useGlobalStore() + if (!globalStore.site.confpages.enableEcommerce) return null; - if (!globalStore.site.confpages.enableEcommerce) - return null + if (!this.userActive._id) return null; - if (!this.userActive._id) - return null + let ris = null; - let ris = null - - ris = await Api.SendReq('/cart/' + this.userActive._id + '/createorderscart', 'POST', { cart_id, status, note, options: this.getOptions(true) }) + ris = await Api.SendReq('/cart/' + this.userActive._id + '/createorderscart', 'POST', { + cart_id, + status, + note, + options: this.getOptions(true), + }) .then((res) => { - if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) { // Cancella il Carrello, ho creato l'ordine ! - this.cart = {} + this.cart = {}; } - this.updateDataProduct(res) + this.updateDataProduct(res); - return res.data.recOrderCart + return res.data.recOrderCart; }) .catch((error) => { - console.log('error UpdateStatusCart', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error UpdateStatusCart', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); - return ris + return ris; }, /*async UpdateStatusCart({ ordercart_id, status }: { ordercart_id: string, status: number }) { @@ -1173,342 +1270,356 @@ export const useProducts = defineStore('Products', { return ris },*/ - async UpdateOrderCartStatus({ order_id, status, sendmail }: { order_id: string, status: number, sendmail: boolean }) { + async UpdateOrderCartStatus({ + order_id, + status, + sendmail, + }: { + order_id: string; + status: number; + sendmail: boolean; + }) { + const userStore = useUserStore(); + const globalStore = useGlobalStore(); - const userStore = useUserStore() - const globalStore = useGlobalStore() + if (!globalStore.site.confpages.enableEcommerce) return null; - if (!globalStore.site.confpages.enableEcommerce) - return null + let ris = null; - let ris = null - - ris = await Api.SendReq('/cart/' + this.userActive._id + '/ordercartstatus', 'POST', { order_id, status, options: this.getOptions(sendmail) }) + ris = await Api.SendReq('/cart/' + this.userActive._id + '/ordercartstatus', 'POST', { + order_id, + status, + options: this.getOptions(sendmail), + }) .then((res) => { + this.updateDataProduct(res); - this.updateDataProduct(res) - - return res.data.status - + return res.data.status; }) .catch((error) => { - console.log('error UpdateOrderCartStatus', error) - userStore.setErrorCatch(error) - return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) - }) + console.log('error UpdateOrderCartStatus', error); + userStore.setErrorCatch(error); + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error); + }); - return ris + return ris; }, - async addtoCartBase({ $q, t, id, order, addqty }: { $q: any, t: any, id: string, order: IOrder, addqty: boolean }) { - let product = await this.getProductById(id) - - return await this.addToCart({ product, order, addqty }) - .then((ris) => { - if (ris && ris.msgerr) { - tools.showNegativeNotif($q, ris.msgerr) - } else { - let strprod = t('ecomm.prodotto') - - let msg = '' - console.log('ris', ris) - if (ris && ris.myord == null) { - msg = t('ecomm.prodotto_tolto') - tools.showNotif($q, msg) - return - } - if (ris === null || ris.myord == null) { - msg = t('ecomm.error_cart') - tools.showNegativeNotif($q, msg) - return - } else { - - let qta = ris.myord.quantity + ris.myord.quantitypreordered - if (qta > 1 || qta === 0) - strprod = t('ecomm.prodotti') - - - if (qta >= 0) { - let totalPrice = this.cart.totalPrice ? this.cart.totalPrice.toFixed(2) : 0 - let tot = totalPrice + ' €' - msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta, tot }) - } - - } - if (ris === null || ris.myord.quantity === 0) - tools.showNotif($q, msg) - else - tools.showPositiveNotif($q, msg, undefined, 'prodotto') + async addtoCartBase({ $q, t, id, order, addqty }: { $q: any; t: any; id: string; order: IOrder; addqty: boolean }) { + let product = await this.getProductById(id); + return await this.addToCart({ product, order, addqty }).then((ris) => { + if (ris && ris.msgerr) { + tools.showNegativeNotif($q, ris.msgerr); + } else { + let strprod = t('ecomm.prodotto'); + let msg = ''; + console.log('ris', ris); + if (ris && ris.myord == null) { + msg = t('ecomm.prodotto_tolto'); + tools.showNotif($q, msg); + return; } - //updateproduct() + if (ris === null || ris.myord == null) { + msg = t('ecomm.error_cart'); + tools.showNegativeNotif($q, msg); + return; + } else { + let qta = ris.myord.quantity + ris.myord.quantitypreordered; + if (qta > 1 || qta === 0) strprod = t('ecomm.prodotti'); - return ris - }) + if (qta >= 0) { + let totalPrice = this.cart.totalPrice ? this.cart.totalPrice.toFixed(2) : 0; + let tot = totalPrice + ' €'; + msg = t('ecomm.prod_sul_carrello', { strprod, qty: qta, tot }); + } + } + if (ris === null || ris.myord.quantity === 0) tools.showNotif($q, msg); + else tools.showPositiveNotif($q, msg, undefined, 'prodotto'); + } + //updateproduct() + + return ris; + }); }, getQuantityByOrder($t: any, order: IOrder): string { let mystr = ''; if (order.quantity > 0) { - mystr += order.quantity + mystr += order.quantity; } - if ((order.quantitypreordered > 0) && (order.quantity > 0)) { - mystr += ' ' + $t('ecomm.available') - mystr += ' + ' + if (order.quantitypreordered > 0 && order.quantity > 0) { + mystr += ' ' + $t('ecomm.available'); + mystr += ' + '; } if (order.quantitypreordered > 0) { mystr += ' ' + order.quantitypreordered + ' '; } - return mystr + return mystr; }, isQtyAvailableByProduct(product: IProduct): boolean { if (product) { - return (product.quantityAvailable! > 0) + return product.quantityAvailable! > 0; } return false; }, isInPreorderByProduct(product: IProduct): boolean { if (product) { - return (product.bookableAvailableQty! > 0) + return product.bookableAvailableQty! > 0; } return false; }, isQtyAvailableByOrder(order: IOrder): boolean { if (order && order.product) { - return this.isQtyAvailableByProduct(order.product) + return this.isQtyAvailableByProduct(order.product); } return false; }, isInPreorderByOrder(order: IOrder): boolean { if (order && order.product) { - return this.isInPreorderByProduct(order.product) + return this.isInPreorderByProduct(order.product); } return false; }, getSingleGasordine(order: IOrder, short: boolean): string { try { - const mygas = order.gasordine + const mygas = order.gasordine; if (mygas) { - if (short) - return mygas.name! + if (short) return mygas.name!; else - return mygas.name + ' (' + mygas.city + ') ' + translate('gas.dataora_chiusura_ordini') + ': ' + tools.getstrDateShort(mygas.dataora_chiusura_ordini) - + ' ' + translate('gas.data_arrivo_merce') + ': ' + tools.getstrDateShort(mygas.data_arrivo_merce) - + ' ' + translate('gas.dataora_ritiro') + ': ' + tools.getstrDateShort(mygas.dataora_ritiro) - } else - return '' + return ( + mygas.name + + ' (' + + mygas.city + + ') ' + + translate('gas.dataora_chiusura_ordini') + + ': ' + + tools.getstrDateShort(mygas.dataora_chiusura_ordini) + + ' ' + + translate('gas.data_arrivo_merce') + + ': ' + + tools.getstrDateShort(mygas.data_arrivo_merce) + + ' ' + + translate('gas.dataora_ritiro') + + ': ' + + tools.getstrDateShort(mygas.dataora_ritiro) + ); + } else return ''; } catch (e) { - return '' + return ''; } }, getQtyAvailable(myproduct: IProduct): number { - let qty = myproduct.quantityAvailable! - return qty + let qty = myproduct.quantityAvailable!; + return qty; }, getQtyBookableAvailable(myproduct: IProduct): number { - let qty = myproduct.bookableAvailableQty! - return qty + let qty = myproduct.bookableAvailableQty!; + return qty; }, getQtyBloccataAvailable(myproduct: IProduct): number { - let qty = myproduct.stockBloccatiQty - return qty + let qty = myproduct.stockBloccatiQty; + return qty; }, getQtyBloccataBookableAvailable(myproduct: IProduct): number { - let qty = myproduct.bookableGASBloccatiQty - return qty + let qty = myproduct.bookableGASBloccatiQty; + return qty; }, enableSubQty(myorder: IOrder): boolean { - let qty = myorder.quantity + myorder.quantitypreordered - return qty ? qty > 0 : false + let qty = myorder.quantity + myorder.quantitypreordered; + return qty ? qty > 0 : false; }, CanDeleteIfSub(myorder: IOrder): boolean { - let qty = myorder.quantity + myorder.quantitypreordered + let qty = myorder.quantity + myorder.quantitypreordered; - qty = qty - this.qtaNextSub(myorder, myorder.product!) - return qty === 0 + qty = qty - this.qtaNextSub(myorder, myorder.product!); + return qty === 0; }, enableAddQty(myorder: IOrder, myproduct: IProduct): boolean { - const globalStore = useGlobalStore() + const globalStore = useGlobalStore(); if (globalStore.site.ecomm && globalStore.site.ecomm.enablePreOrders) { - return ((this.getQtyBookableAvailable(myproduct) > 0) - && (myproduct.maxBookableSinglePersQty === 0 - || (myorder.quantitypreordered + 1 < myproduct.maxBookableSinglePersQty)) - ) - || (this.getQtyAvailable(myproduct) > 0) - && (myproduct.maxBookableSinglePersQty === 0 - || (myorder.quantity + 1 < myproduct.maxBookableSinglePersQty)) - + return ( + (this.getQtyBookableAvailable(myproduct) > 0 && + (myproduct.maxBookableSinglePersQty === 0 || + myorder.quantitypreordered + 1 < myproduct.maxBookableSinglePersQty)) || + (this.getQtyAvailable(myproduct) > 0 && + (myproduct.maxBookableSinglePersQty === 0 || myorder.quantity + 1 < myproduct.maxBookableSinglePersQty)) + ); } else { - return (this.getQtyAvailable(myproduct) > 0) - && (myproduct.maxBookableSinglePersQty === 0 - || (myorder.quantity + 1 < myproduct.maxBookableSinglePersQty)) + return ( + this.getQtyAvailable(myproduct) > 0 && + (myproduct.maxBookableSinglePersQty === 0 || myorder.quantity + 1 < myproduct.maxBookableSinglePersQty) + ); } - }, qtaNextAdd(myorder: IOrder, myproduct: IProduct): number { - let step = myproduct.minStepQty + let step = myproduct.minStepQty; if (this.getQtyAvailable(myproduct) > 0) { - if (myorder.quantity === 0) - step = myproduct.minBuyQty + if (myorder.quantity === 0) step = myproduct.minBuyQty; } else { - if (myorder.quantitypreordered === 0) - step = myproduct.minBuyQty + if (myorder.quantitypreordered === 0) step = myproduct.minBuyQty; } if (step === 0) { - step = 1 + step = 1; } - return step + return step; }, qtaNextSub(myorder: IOrder, myproduct: IProduct) { - let step = myproduct.minStepQty - let minqta = myproduct.minBuyQty + let step = myproduct.minStepQty; + let minqta = myproduct.minBuyQty; if (this.getQtyAvailable(myproduct) > 0) { - if (myorder.quantity === minqta) - step = minqta + if (myorder.quantity === minqta) step = minqta; } else { - if (myorder.quantitypreordered === minqta) - step = minqta + if (myorder.quantitypreordered === minqta) step = minqta; } - return step + return step; }, getNumQtaGas() { - const arrprod = this.getProducts(shared_consts.PROD.GAS) - return arrprod.length + const arrprod = this.getProducts(shared_consts.PROD.GAS); + return arrprod.length; }, getNumQtaTutti() { - const arrprod = this.getProducts(shared_consts.PROD.TUTTI) - return arrprod.length + const arrprod = this.getProducts(shared_consts.PROD.TUTTI); + return arrprod.length; }, getNumQtaBottega() { - const arrprod = this.getProducts(shared_consts.PROD.BOTTEGA) - return arrprod.length + const arrprod = this.getProducts(shared_consts.PROD.BOTTEGA); + return arrprod.length; }, changeuserActive(valuerec: any) { if (valuerec) { - console.log('valuerec', valuerec) - tools.setCookie(tools.COOK_SELCART, valuerec._id) - this.products = [] - this.orders = [] - this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' } + console.log('valuerec', valuerec); + tools.setCookie(tools.COOK_SELCART, valuerec._id); + this.products = []; + this.orders = []; + this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }; - this.loadOrders() - this.loadProducts() + this.loadOrders(); + this.loadProducts(); } }, async sendMailToTheBuyer(idOrdersCart: string, templemail_id: string, test: boolean) { - return await Api.SendReq('/orders/sendmail', 'POST', { templemail_id, idOrdersCart, previewonly: tools.isDebug(), test }) - .then((res) => { - console.log('res', res) - if (res) - return res.data - else - return null - }) + return await Api.SendReq('/orders/sendmail', 'POST', { + templemail_id, + idOrdersCart, + previewonly: tools.isDebug(), + test, + }).then((res) => { + console.log('res', res); + if (res) return res.data; + else return null; + }); }, - getStrInfoOrder(t: any, order: IOrder) { - let mystr = '' - let qtyrisult: any + let mystr = ''; + let qtyrisult: any; if (order.product) { - let qtystr = '' - let qtynum = 0 - if (order.quantity > 0) - qtynum += order.quantity; - if (order.quantitypreordered > 0) - qtynum += order.quantitypreordered; + let qtystr = ''; + let qtynum = 0; + if (order.quantity > 0) qtynum += order.quantity; + if (order.quantitypreordered > 0) qtynum += order.quantitypreordered; if (order.product.productInfo.sfuso && order.product.productInfo.weight) qtyrisult = qtynum * order.product.productInfo.weight; - else - qtyrisult = qtynum + ' x ' + order.product.productInfo.weight; + else qtyrisult = qtynum + ' x ' + order.product.productInfo.weight; - qtystr += qtyrisult + ' ' + tools.getUnitsMeasure(order.product.productInfo.unit, true, order.product.productInfo.weight); + qtystr += + qtyrisult + + ' ' + + tools.getUnitsMeasure(order.product.productInfo.unit, true, order.product.productInfo.weight); - if (order.quantitypreordered > 0) - qtystr += ' Pre-Ordinati'; - - mystr += '✅ [' + qtystr + '] ' + order.product.productInfo.name + ' a ' + order.price + '€ ' + (order.after_price ? order.after_price : '') + '
Totale = ' + order.TotalPriceProduct + '€'; + if (order.quantitypreordered > 0) qtystr += ' Pre-Ordinati'; + mystr += + '✅ [' + + qtystr + + '] ' + + order.product.productInfo.name + + ' a ' + + order.price + + '€ ' + + (order.after_price ? order.after_price : '') + + '
Totale = ' + + order.TotalPriceProduct + + '€'; } - return mystr + return mystr; }, getGasordineNameById(idGasordine: string) { - - const globalStore = useGlobalStore() - const rec = globalStore.gasordines.find((gasordine: IGasordine) => gasordine._id === idGasordine) - return rec ? rec.name : '' - + const globalStore = useGlobalStore(); + const rec = globalStore.gasordines.find((gasordine: IGasordine) => gasordine._id === idGasordine); + return rec ? rec.name : ''; }, getGasordines() { - const globalStore = useGlobalStore() + const globalStore = useGlobalStore(); - const myarr: any = [{ - id: 0, - label: 'Tutti', - value: '' - }] - let ind = 1 + const myarr: any = [ + { + id: 0, + label: 'Tutti', + value: '', + }, + ]; + let ind = 1; if (globalStore.gasordines) { globalStore.gasordines.forEach((gasordine: IGasordine) => { if (gasordine) { - myarr.push( - { - id: ind, - label: gasordine.name - + (gasordine.dataora_chiusura_ordini ? (' - chiusura: ' + tools.getstrDateShort(gasordine.dataora_chiusura_ordini)) : '') - + (gasordine.dataora_ritiro ? (' - consegna ' + tools.getstrDateShort(gasordine.dataora_ritiro)) : '') - , - value: gasordine._id - }) - ind++ + myarr.push({ + id: ind, + label: + gasordine.name + + (gasordine.dataora_chiusura_ordini + ? ' - chiusura: ' + tools.getstrDateShort(gasordine.dataora_chiusura_ordini) + : '') + + (gasordine.dataora_ritiro ? ' - consegna ' + tools.getstrDateShort(gasordine.dataora_ritiro) : ''), + value: gasordine._id, + }); + ind++; } - }) + }); } - return myarr + return myarr; }, getGasordinesActives() { - const globalStore = useGlobalStore() + const globalStore = useGlobalStore(); - return globalStore.gasordines.filter((rec) => rec.active) + return globalStore.gasordines.filter((rec) => rec.active); }, getAutoriByArrayAuthors(authors?: IAuthor[]) { // Gestione degli autori let authorString = ''; if (authors && Array.isArray(authors)) { - // Crea un array di nomi completi - const fullNames = authors.map(author => - `${author.name} ${author.surname}`.trim() - ); + const fullNames = authors.map((author) => `${author.name} ${author.surname}`.trim()); // Formattazione degli autori if (fullNames.length === 1) { @@ -1520,14 +1631,14 @@ export const useProducts = defineStore('Products', { authorString = `${fullNames.join(', ')} e ${lastAuthor}`; } } - return authorString + return authorString; }, getkeyValStr(chiave: string, valore: any) { try { - return ` ${chiave} = ${valore} ` + return ` ${chiave} = ${valore} `; } catch (e) { - return ` ${chiave}` + return ` ${chiave}`; } }, @@ -1550,16 +1661,18 @@ export const useProducts = defineStore('Products', { if (testo.contenuto.includes('{descrizione_da_fdv}')) { const description = myproduct.productInfo.short_descr || ''; - replacements['{descrizione_da_fdv}'] = description.length > maxDescriptionLength - ? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...' - : description; + replacements['{descrizione_da_fdv}'] = + description.length > maxDescriptionLength + ? description.substring(0, description.lastIndexOf(' ', maxDescriptionLength)) + '...' + : description; } if (testo.contenuto.includes('{descrizione_estesa_fdv}')) { const long_descr = myproduct.productInfo.description || ''; - replacements['{descrizione_estesa_fdv}'] = long_descr.length > maxDescriptionLength - ? long_descr.substring(0, long_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' - : long_descr; + replacements['{descrizione_estesa_fdv}'] = + long_descr.length > maxDescriptionLength + ? long_descr.substring(0, long_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' + : long_descr; } if (testo.contenuto.includes('{descrizione_estesa}')) { @@ -1568,7 +1681,8 @@ export const useProducts = defineStore('Products', { if (long_descr_macro.length > maxDescriptionLength && maxDescriptionLength > 0) { addtesto = true; } - const addstrcontinua = '👉🏻 continua a leggere'; + const addstrcontinua = + '👉🏻 continua a leggere'; let descrizione_completa_macro = addtesto ? long_descr_macro.substring(0, long_descr_macro.lastIndexOf(' ', maxDescriptionLength)) + '...' : long_descr_macro; @@ -1581,17 +1695,22 @@ export const useProducts = defineStore('Products', { if (testo.contenuto.includes('{descrizione_breve_macro}')) { const short_descr = myproduct.productInfo.descrizione_breve_macro || ''; - replacements['{descrizione_breve_macro}'] = short_descr.length > maxDescriptionLength && maxDescriptionLength > 0 - ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' - : short_descr; + replacements['{descrizione_breve_macro}'] = + short_descr.length > maxDescriptionLength && maxDescriptionLength > 0 + ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' + : short_descr; } - if (testo.contenuto.includes('{descr_trafiletto_catalogo}') || testo.contenuto.includes('{descrizione_completa_macro}')) { + if ( + testo.contenuto.includes('{descr_trafiletto_catalogo}') || + testo.contenuto.includes('{descrizione_completa_macro}') + ) { const short_descr = myproduct.productInfo.descr_trafiletto_catalogo || ''; - replacements['{descr_trafiletto_catalogo}'] = short_descr.length > maxDescriptionLength && maxDescriptionLength > 0 - ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' - : short_descr; - replacements['{descrizione_completa_macro}'] = replacements['{descr_trafiletto_catalogo}'] + replacements['{descr_trafiletto_catalogo}'] = + short_descr.length > maxDescriptionLength && maxDescriptionLength > 0 + ? short_descr.substring(0, short_descr.lastIndexOf(' ', maxDescriptionLength)) + '...' + : short_descr; + replacements['{descrizione_completa_macro}'] = replacements['{descr_trafiletto_catalogo}']; } if (testo.contenuto.includes('{prezzo}') || testo.contenuto.includes('{prezzo_scontato}')) { @@ -1603,10 +1722,32 @@ export const useProducts = defineStore('Products', { // Additional replacements based on the content const keysToCheck = [ - '{titolo}', '{sottotitolo}', '{categoria}', '{sottocategoria}', '{descr_categoria}', - '{pagine}', '{isbn}', '{misure}', '{edizione}', '{ristampa}', '{argomento}', '{date_pub}', '{date_updated_fromGM}', '{ranking_globale}', - '{venduti}', '{formato}', '{tipologia}', '{stato}', '{scale}', '{descr_trafiletto_catalogo}', - '{link_macro}', '{qta}', '{image_link}', '{imagefile}', '{casaeditrice}', '{debug}' + '{titolo}', + '{sottotitolo}', + '{categoria}', + '{sottocategoria}', + '{descr_categoria}', + '{pagine}', + '{isbn}', + '{misure}', + '{edizione}', + '{ristampa}', + '{argomento}', + '{date_pub}', + '{date_updated_fromGM}', + '{ranking_globale}', + '{venduti}', + '{formato}', + '{tipologia}', + '{stato}', + '{scale}', + '{descr_trafiletto_catalogo}', + '{link_macro}', + '{qta}', + '{image_link}', + '{imagefile}', + '{casaeditrice}', + '{debug}', ]; for (const key of keysToCheck) { @@ -1619,10 +1760,16 @@ export const useProducts = defineStore('Products', { replacements[key] = myproduct.productInfo.sottotitolo || ''; break; case '{sottocategoria}': - replacements[key] = myproduct.productInfo.subcatprods && myproduct.productInfo.subcatprods.length > 0 ? myproduct.productInfo.subcatprods[0].name! : ''; + replacements[key] = + myproduct.productInfo.subcatprods && myproduct.productInfo.subcatprods.length > 0 + ? myproduct.productInfo.subcatprods[0].name! + : ''; break; case '{descr_categoria}': - replacements[key] = myproduct.productInfo.catprods && myproduct.productInfo.catprods.length > 0 ? this.getCatProdDescrStrByIdCatProd(myproduct.productInfo.catprods![0].name) : ''; + replacements[key] = + myproduct.productInfo.catprods && myproduct.productInfo.catprods.length > 0 + ? this.getCatProdDescrStrByIdCatProd(myproduct.productInfo.catprods![0].name) + : ''; break; case '{pagine}': replacements[key] = myproduct.arrvariazioni?.[0]?.pagine || ''; @@ -1634,7 +1781,7 @@ export const useProducts = defineStore('Products', { replacements[key] = myproduct.arrvariazioni?.[0]?.misure || ''; break; case '{casaeditrice}': - replacements[key] = this.getCasaEditriceByIdPublisher(myproduct.productInfo.idPublisher) + replacements[key] = this.getCasaEditriceByIdPublisher(myproduct.productInfo.idPublisher); break; case '{edizione}': replacements[key] = myproduct.arrvariazioni?.[0]?.edizione || ''; @@ -1658,13 +1805,15 @@ export const useProducts = defineStore('Products', { replacements[key] = myproduct.productInfo.totVen! || '0'; break; case '{formato}': - replacements[key] = this.getDescrByIdTipoFormato(myproduct.arrvariazioni?.[0]?.idTipoFormato || 0) + replacements[key] = this.getDescrByIdTipoFormato(myproduct.arrvariazioni?.[0]?.idTipoFormato || 0); break; case '{tipologia}': replacements[key] = this.getDescrByIdTipologia(myproduct.arrvariazioni?.[0]?.idTipologia || 0); break; case '{stato}': - replacements[key] = this.getDescrStatiProdottoByIdStatoProdotto(myproduct.productInfo.idStatoProdotto || ''); + replacements[key] = this.getDescrStatiProdottoByIdStatoProdotto( + myproduct.productInfo.idStatoProdotto || '' + ); break; case '{scale}': replacements[key] = optcatalogo.printable ? optcatalogo.areadistampa?.scale : '1'; @@ -1690,7 +1839,8 @@ export const useProducts = defineStore('Products', { const linkfatturati = `${myproduct.productInfo.totFat! || 0}`; const fatLast3M = myproduct.productInfo.fatLast3M! || 0; - replacements[key] = this.getkeyValStr('Pub:', date_pub) + + replacements[key] = + this.getkeyValStr('Pub:', date_pub) + this.getkeyValStr('fat6M', fatLast6M) + this.getkeyValStr('Ven:', linkvenduti) + this.getkeyValStr('v3M', vLast3M) + @@ -1712,13 +1862,12 @@ export const useProducts = defineStore('Products', { }, getSubCatStrByProduct(myproductInfo: IProductInfo): string { - return this.getSubCatProdsStrBySubCatProds(myproductInfo.idSubCatProds || []) + return this.getSubCatProdsStrBySubCatProds(myproductInfo.idSubCatProds || []); }, getListProductBySumQuantity(idGasordine: string): ISingleProductOrdered[] { - const arrprod = this.orders.filter((rec: IOrderCart) => { - if (idGasordine && !rec.items?.some(item => item.order && item.order.idGasordine === idGasordine)) { + if (idGasordine && !rec.items?.some((item) => item.order && item.order.idGasordine === idGasordine)) { return false; // Skip records not matching gasordine condition } return true; @@ -1727,18 +1876,20 @@ export const useProducts = defineStore('Products', { const productMap = new Map(); arrprod.forEach((rec: IOrderCart) => { - rec.items?.forEach(item => { + rec.items?.forEach((item) => { if (item.order && item.order.idGasordine === idGasordine) { const productId: string = item.order.idProduct!; - const qtyparz = item.order.quantity + item.order.quantitypreordered + const qtyparz = item.order.quantity + item.order.quantitypreordered; if (productMap.has(productId)) { - const existingProduct: ISingleProductOrdered = productMap.get(productId)! - existingProduct.qty += qtyparz - existingProduct.subtotalPrice += item.order.price * qtyparz - existingProduct.subtotalPrice = Number((existingProduct.subtotalPrice).toFixed(2)) + const existingProduct: ISingleProductOrdered = productMap.get(productId)!; + existingProduct.qty += qtyparz; + existingProduct.subtotalPrice += item.order.price * qtyparz; + existingProduct.subtotalPrice = Number(existingProduct.subtotalPrice.toFixed(2)); } else { - - const sottocategoria = item.order.product?.productInfo?.subcatprods && item.order.product?.productInfo?.subcatprods.length > 0 ? item.order.product?.productInfo?.subcatprods[0].name : '' + const sottocategoria = + item.order.product?.productInfo?.subcatprods && item.order.product?.productInfo?.subcatprods.length > 0 + ? item.order.product?.productInfo?.subcatprods[0].name + : ''; productMap.set(productId, { subCat: sottocategoria, strSubCatProds: this.getSubCatProdsStrBySubCatProds(item.order.product?.productInfo?.idSubCatProds), @@ -1757,111 +1908,132 @@ export const useProducts = defineStore('Products', { }); return Array.from(productMap.values()); + }, + getOptCatalogoTemplate() { + // Ottieni l'array delle pagine che in cataloghi sono dimensioni_def.isTemplate + + let arr: any = []; + + const globalStore = useGlobalStore(); + + arr.push({ label: '[Nessuna]', value: '' }); + + for (const myelem of globalStore.myelems) { + if (myelem.catalogo && myelem.catalogo.dimensioni_def && myelem.catalogo.dimensioni_def.isTemplate) { + const page = globalStore.getPageById(myelem.idPage); + let pagename = page ? page.title! : ''; + + if (pagename) { + pagename = '[Pag: ' + pagename + '] '; + } + + const mylabel = pagename; + + arr.push({ label: mylabel, value: myelem._id }); + } + }; + + return arr }, getSchedeOpt(arrschede: ISchedaSingola[], tag?: string): any[] { + let arr: any = []; - let arr: any = [] + const globalStore = useGlobalStore(); - const globalStore = useGlobalStore() - - arr.push({ label: '[Nessuna]', value: '' }) + arr.push({ label: '[Nessuna]', value: '' }); if (arrschede) { arrschede.forEach((recscheda: ISchedaSingola) => { - let pagename = '' + let pagename = ''; if (recscheda.scheda) { if (recscheda.idPageOrig) { - const page = globalStore.getPageById(recscheda.idPageOrig) + const page = globalStore.getPageById(recscheda.idPageOrig); // const page = this.mypage?.find((page) => (`${page._id}`) === recscheda.idPageOrig) - pagename = page ? page.title! : '' + pagename = page ? page.title! : ''; } - if (pagename) - pagename = '[Pag: ' + pagename + '] ' + if (pagename) pagename = '[Pag: ' + pagename + '] '; - const mylabel = pagename + (recscheda.scheda ? recscheda.scheda!.name : '') + const mylabel = pagename + (recscheda.scheda ? recscheda.scheda!.name : ''); if (!tag || mylabel.startsWith(tag)) { - arr.push({ label: mylabel, value: recscheda.scheda!._id }) + arr.push({ label: mylabel, value: recscheda.scheda!._id }); } } }); } - return arr - + return arr; }, addNewScheda(catalogo: IOptCatalogo) { - - let maxorder = 0 - catalogo!.arrSchede?.forEach(scheda => { + let maxorder = 0; + catalogo!.arrSchede?.forEach((scheda) => { if (scheda?.order > maxorder) { - maxorder = scheda.order + maxorder = scheda.order; } - }) + }); + let testodef: IText = {}; + testodef = tools.resetIText(testodef); - let testodef: IText = {} - testodef = tools.resetIText(testodef) - - const defaultDimensioniPag = tools.resetRecIDimensioni(null) + const defaultDimensioniPag = tools.resetRecIDimensioni(null); defaultDimensioniPag.size = { width: '800px', height: '600px', - } + }; defaultDimensioniPag.margini = { top: '12px', bottom: '0px', left: '0px', right: '0px', - } + }; defaultDimensioniPag.padding = { top: '0px', bottom: '0px', left: '0px', right: '0px', - } + }; - const defaultDimensioniRiga = tools.resetRecIDimensioni(null) + const defaultDimensioniRiga = tools.resetRecIDimensioni(null); defaultDimensioniRiga.size = { width: '800px', height: '300px', - } + }; defaultDimensioniRiga.margini = { top: '40px', bottom: '0px', left: '0px', right: '0px', - } + }; defaultDimensioniRiga.padding = { top: '0px', bottom: '0px', left: '0px', right: '0px', - } + }; - const defaultSchedaProdotto = tools.resetRecIDimensioni(null) + const defaultSchedaProdotto = tools.resetRecIDimensioni(null); defaultSchedaProdotto.size = { width: '360px', height: '230px', - } + }; defaultSchedaProdotto.margini = { top: '0px', bottom: '0px', left: '0px', right: '0px', - } + }; defaultSchedaProdotto.padding = { top: '0px', bottom: '0px', left: '0px', right: '0px', - } + }; const dimensioni: IElementiScheda = { pagina: { dimensioni: defaultDimensioniPag, testo_down: testodef, testo_up: testodef, testo_title: testodef }, @@ -1885,7 +2057,7 @@ export const useProducts = defineStore('Products', { right: '0px', }, }, - } + }; const newscheda: IMyScheda = { _id: objectId(), @@ -1916,7 +2088,7 @@ export const useProducts = defineStore('Products', { maxlength: 0, font: { posiz_text: costanti.POSIZ_TESTO.IN_BASSO, - } + }, }, barcode: { show: false, @@ -1928,7 +2100,7 @@ export const useProducts = defineStore('Products', { font: { name: 'monospace', size: '16px', - } + }, }, productTypes: [], excludeproductTypes: [], @@ -1946,44 +2118,32 @@ export const useProducts = defineStore('Products', { }, bestseller: { show: false, - quantiFattRaggiunti: 50 - } - } - } + quantiFattRaggiunti: 50, + }, + }, + }; - if (!catalogo!.arrSchede) - catalogo!.arrSchede = [] - - catalogo!.arrSchede.push( - { - _id: objectId(), - scheda: newscheda, - order: maxorder + 10, - numPagineMax: 0, - } - ) + if (!catalogo!.arrSchede) catalogo!.arrSchede = []; + catalogo!.arrSchede.push({ + _id: objectId(), + scheda: newscheda, + order: maxorder + 10, + numPagineMax: 0, + }); }, - getPathByPage(idpag: string) { + let linkpage = ''; - let linkpage = '' - - const globalStore = useGlobalStore() + const globalStore = useGlobalStore(); if (idpag) { - const mypage = globalStore.getPageById(idpag) - if (mypage) - linkpage = mypage.path! + const mypage = globalStore.getPageById(idpag); + if (mypage) linkpage = mypage.path!; } - return linkpage - + return linkpage; }, - - }, - -}) - +}); diff --git a/src/store/globalStore.ts b/src/store/globalStore.ts index 8144675e..54584f08 100644 --- a/src/store/globalStore.ts +++ b/src/store/globalStore.ts @@ -237,6 +237,30 @@ export const useGlobalStore = defineStore('GlobalStore', { return null; }, + sovrascriviPaginaDefaultFromTemplate: + (state: IGlobalState) => (idTemplate: string, origDimensioni: IDimensioni, optcatalogo: IOptCatalogo) => { + + const myfindelem = state.myelems.find((myelem: IMyElem) => myelem._id === idTemplate); + + const linkIdTemplate = origDimensioni.linkIdTemplate; + const precname = origDimensioni.name; + + if (myfindelem) { + const myelemtocopy = tools.jsonCopy(myfindelem); + + if (myelemtocopy) { + // myelemtocopy.scheda._id = origScheda.scheda?._id; + myelemtocopy.catalogo.dimensioni_def.isTemplate = false; + myelemtocopy.catalogo.dimensioni_def.name = precname; + myelemtocopy.catalogo.dimensioni_def.linkIdTemplate = linkIdTemplate; + + return myelemtocopy.catalogo; + } + } + + return null; + }, + // conta: (state: IGlobalState) => { state.conta }, // listatodo: (state: IGlobalState) => { state.listatodo }, // category: (state: IGlobalState) => { state.category }, @@ -289,6 +313,12 @@ export const useGlobalStore = defineStore('GlobalStore', { return Products.getSchedeOpt(state.myschedas, tag); }, + getOptCatalogoTemplate: (state: IGlobalState) => (tag?: string) => { + const Products = useProducts(); + + return Products.getSchedeOpt(state.myschedas, tag); + }, + getLinkIdTemplateByName: (state: IGlobalState) => (name: string) => { try { const myrecscheda = state.myschedas.find((recscheda: ISchedaSingola) => recscheda.scheda.name === name); @@ -2463,6 +2493,9 @@ export const useGlobalStore = defineStore('GlobalStore', { editore: [], pdf: false, dimensioni_def: { + isTemplate: false, + linkIdTemplate: '', + name: '', pagina: tools.resetRecIDimensioni(null), }, areadistampa: tools.resetRecIAreaDiStampa(null), @@ -2478,6 +2511,9 @@ export const useGlobalStore = defineStore('GlobalStore', { editore: [], pdf: false, dimensioni_def: { + isTemplate: false, + linkIdTemplate: '', + name: '', pagina: tools.resetRecIDimensioni(null), }, areadistampa: tools.resetRecIAreaDiStampa(null), @@ -2617,7 +2653,7 @@ export const useGlobalStore = defineStore('GlobalStore', { window.URL.revokeObjectURL(downloadUrl); } else { - return response + return response; } } else { console.error('No data returned from the server.'); diff --git a/src/views/ecommerce/catalogo/catalogo.ts b/src/views/ecommerce/catalogo/catalogo.ts index 3c7a1c97..ff72b008 100755 --- a/src/views/ecommerce/catalogo/catalogo.ts +++ b/src/views/ecommerce/catalogo/catalogo.ts @@ -581,6 +581,14 @@ export default defineComponent({ // console.log('populateDataWithlinkIdTemplate') if (optcatalogo.value) { + // LINK PAGINA + if (optcatalogo.value.dimensioni_def.linkIdTemplate) { + const reccatalog = globalStore.sovrascriviPaginaDefaultFromTemplate(optcatalogo.value.dimensioni_def.linkIdTemplate, optcatalogo.value.dimensioni_def); + if (reccatalog) { + optcatalogo.value.dimensioni_def.pagina = { ...reccatalog.dimensioni_def.pagina}; + } + } + for (const recscheda of optcatalogo.value.arrSchede!) { if (recscheda.scheda?.linkIdTemplate) { // ricopia da Template: diff --git a/src/views/ecommerce/catalogo/catalogo.vue b/src/views/ecommerce/catalogo/catalogo.vue index 42e9d206..c76f1ac4 100755 --- a/src/views/ecommerce/catalogo/catalogo.vue +++ b/src/views/ecommerce/catalogo/catalogo.vue @@ -308,11 +308,18 @@ >1 + + @@ -701,7 +708,6 @@