- possibilità di visualizzare i dati estratti e di aggiornare i dati, sia solo se vuoti, che sovrascrivere tutti i dati.
655 lines
19 KiB
TypeScript
Executable File
655 lines
19 KiB
TypeScript
Executable File
import {
|
|
PropType,
|
|
computed,
|
|
defineComponent,
|
|
onMounted,
|
|
ref,
|
|
watch,
|
|
} from 'vue';
|
|
import draggable from 'vuedraggable';
|
|
|
|
import { tools } from '@tools';
|
|
|
|
import { useGlobalStore } from '@src/store/globalStore';
|
|
|
|
import { CTableCupleLabelValue } from '@src/components/CTableCupleLabelValue';
|
|
|
|
import { costanti } from '@costanti';
|
|
|
|
import type { IMyScheda, IProduct, IRecFields } from '@src/model';
|
|
import { shared_consts } from 'app/src/common/shared_vuejs';
|
|
import { useProducts } from 'app/src/store/Products';
|
|
import { useI18n } from 'vue-i18n';
|
|
import { useQuasar } from 'quasar';
|
|
|
|
export default defineComponent({
|
|
name: 'CSchedaProdotto',
|
|
emits: ['updateproductmodif'],
|
|
components: {
|
|
CTableCupleLabelValue,
|
|
},
|
|
props: {
|
|
modelValue: {
|
|
type: Object as PropType<IProduct>,
|
|
required: true,
|
|
},
|
|
scheda: {
|
|
type: Object as PropType<IMyScheda>,
|
|
required: false,
|
|
default: () => ({}),
|
|
},
|
|
},
|
|
setup(props, { emit }) {
|
|
// Copia locale della lista_prodotti per manipolazione interna
|
|
const $q = useQuasar();
|
|
const { t } = useI18n();
|
|
|
|
const globalStore = useGlobalStore();
|
|
const products = useProducts();
|
|
|
|
const mytab = ref('scheda');
|
|
|
|
const loading = ref(false);
|
|
|
|
const updatetogm = ref(false);
|
|
const field_updated_toGM = ref('');
|
|
|
|
const myproduct = ref<IProduct>({ ...props.modelValue });
|
|
|
|
watch(
|
|
() => props.modelValue,
|
|
(newVal) => {
|
|
myproduct.value = { ...newVal };
|
|
},
|
|
{ deep: false }
|
|
);
|
|
|
|
async function mounted() {}
|
|
|
|
/*
|
|
// Aggiorna la copia locale quando il prop cambia
|
|
watch(
|
|
() => props.lista_prodotti,
|
|
(newVal) => {
|
|
internalProducts.value = [...newVal];
|
|
}
|
|
);
|
|
*/
|
|
|
|
function getArrListStat(): IRecFields[] {
|
|
const arrlist: IRecFields[] = [
|
|
{
|
|
editOn: false,
|
|
label: 'Fatturati',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'totFat',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Fatturati ultimi 3 Mesi',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'fatLast3M',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Fatturati ultimi 6 Mesi',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'fatLast6M',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Fatturati ultimo Anno',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'fatLast1Y',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Fatturati ultimi 2 Anni',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'fatLast2Y',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Venduti',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'totVen',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Venduti Ultimi 3 Mesi',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'vLast3M',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Venduti Ultimi 6 Mesi',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'vLast6M',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Venduti Ultimo Anno',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'vLast1Y',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Venduti Ultimi 2 Anni',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'vLast2Y',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.number,
|
|
},
|
|
|
|
// SEZIONE RANKING (FATTURATI)
|
|
/*{
|
|
editOn: false,
|
|
label: "Ranking 3 Mesi",
|
|
table: "productinfos",
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: "rank3M",
|
|
debounce: "1000",
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: "Ranking 6 Mesi",
|
|
table: "productinfos",
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: "rank6M",
|
|
debounce: "1000",
|
|
type: costanti.FieldType.number,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: "Ranking 1 Anno",
|
|
table: "productinfos",
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: "rank1Y",
|
|
debounce: "1000",
|
|
type: costanti.FieldType.number,
|
|
},*/
|
|
];
|
|
return arrlist;
|
|
}
|
|
|
|
function getArrListDescrizioni(): IRecFields[] {
|
|
const arrlist: IRecFields[] = [
|
|
{
|
|
editOn: true,
|
|
label: 'Descrizione Sinossi per Catalogo',
|
|
title: myproduct.value?.productInfo?.name,
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'descr_trafiletto_catalogo',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.editor_nohtml,
|
|
dense: true,
|
|
showall: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Descrizione breve macro',
|
|
title: myproduct.value?.productInfo?.name,
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'descrizione_breve_macro',
|
|
maxlength: 650,
|
|
debounce: '1000',
|
|
type: costanti.FieldType.editor_nohtml,
|
|
dense: true,
|
|
showall: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Descrizione Estesa',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'descrizione_completa_macro',
|
|
maxlength: props.scheda?.testo_bottom?.maxlength
|
|
? props.scheda?.testo_bottom?.maxlength
|
|
: 10000,
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
showall: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Link a gruppomacro.com',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id, // ID dinamico, da sostituire con il valore reale
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'link_macro',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
showall: true,
|
|
},
|
|
];
|
|
|
|
return arrlist;
|
|
}
|
|
|
|
function getArrListScheda(): IRecFields[] {
|
|
const arrlist: IRecFields[] = [
|
|
{
|
|
editOn: true,
|
|
label: 'Titolo',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo, // Oggetto dinamico, da sostituire con il valore reale
|
|
mykey: 'name',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Verifica',
|
|
table: 'products',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'validaprod',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.verifica,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'SottoTitolo',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'sottotitolo',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
},
|
|
/*{
|
|
editOn: true,
|
|
label: "Pagine",
|
|
table: "arrvariazioni",
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: "data_verifica",
|
|
debounce: "0",
|
|
type: costanti.FieldType.date,
|
|
dense: true,
|
|
},*/
|
|
{
|
|
editOn: false,
|
|
label: 'Pubblicazione',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'date_pub',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.onlydate,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'ISBN',
|
|
table: 'products',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'isbn',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Stato',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'idStatoProdotto',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.select,
|
|
jointable: 't_web_statiprodottos',
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Argomento',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo?._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'idCatProds',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.multiselect,
|
|
jointable: 'catprtotali',
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Pagine',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'pagine',
|
|
debounce: '0',
|
|
|
|
type: costanti.FieldType.number,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Misure',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'misure',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Edizione',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'edizione',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.string,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Tipologia',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'idTipologia',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.select,
|
|
jointable: 't_web_tipologies',
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Formato',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'idTipoFormato',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.select,
|
|
jointable: 't_web_tipiformatos',
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Prezzo',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'price',
|
|
debounce: '0',
|
|
|
|
type: costanti.FieldType.number,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: true,
|
|
label: 'Prezzo Scontato',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'sale_price',
|
|
debounce: '0',
|
|
|
|
type: costanti.FieldType.number,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Magazzino',
|
|
table: 'arrvariazioni',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'quantita',
|
|
debounce: '0',
|
|
|
|
type: costanti.FieldType.number,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Aggiornato (da GM) il',
|
|
table: 'productinfos',
|
|
id: myproduct.value.productInfo._id,
|
|
rec: myproduct.value.productInfo,
|
|
mykey: 'date_updated_fromGM',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.onlydate,
|
|
dense: true,
|
|
},
|
|
{
|
|
editOn: false,
|
|
label: 'Dati estratti dal Web',
|
|
table: 'products',
|
|
id: myproduct.value._id,
|
|
rec: myproduct.value,
|
|
mykey: 'scraped',
|
|
debounce: '1000',
|
|
type: costanti.FieldType.boolean,
|
|
dense: true,
|
|
},
|
|
];
|
|
|
|
return arrlist;
|
|
}
|
|
|
|
function updateproductmodif(element: any) {
|
|
console.log('CSCHEDAPRODOTTO updateproductmodif ', element);
|
|
emit('updateproductmodif', element);
|
|
}
|
|
|
|
async function updateFieldsDataToGM(data: any) {
|
|
if (myproduct.value) {
|
|
try {
|
|
loading.value = true; // Attiva lo stato di caricamento
|
|
updatetogm.value = true; // Indica che l'aggiornamento è in corso
|
|
|
|
// Ottieni lo SKU del prodotto corrente
|
|
const sku = myproduct.value.productInfo.sku;
|
|
|
|
if (!sku) {
|
|
throw new Error('SKU non disponibile per il prodotto.');
|
|
}
|
|
|
|
// Aggiorna il campo nel database utilizzando setGM_FieldOf_T_Web_Articoli
|
|
const result = await globalStore.setGM_FieldOf_T_Web_Articoli(
|
|
sku, // SKU del prodotto
|
|
data, // Nuovo valore per il campo
|
|
shared_consts.CmdQueryMs.SET // Comando per l'aggiornamento
|
|
);
|
|
|
|
console.log(`Record aggiornato con successo. Risultato:`, result);
|
|
} catch (error) {
|
|
console.error(
|
|
`Errore durante l'aggiornamento del record:`,
|
|
error.message
|
|
);
|
|
throw new Error(
|
|
`Errore durante l'aggiornamento del record: ${error.message}`
|
|
);
|
|
} finally {
|
|
loading.value = false; // Disattiva lo stato di caricamento
|
|
updatetogm.value = false; // Indica che l'aggiornamento è terminato
|
|
}
|
|
} else {
|
|
console.warn("Nessun prodotto selezionato per l'aggiornamento.");
|
|
}
|
|
}
|
|
|
|
function updateRecordToGM() {
|
|
console.log(
|
|
'myproduct.value.productInfo.catprods',
|
|
myproduct.value.productInfo.catprods
|
|
);
|
|
|
|
let mydata = {
|
|
ListaArgomenti: products.getArrayidArgomentoByArridCatProds(
|
|
myproduct.value.productInfo.idCatProds
|
|
),
|
|
};
|
|
console.log('devo salvare mydata', mydata);
|
|
updateFieldsDataToGM(mydata);
|
|
}
|
|
|
|
async function updateproduct(load?: boolean) {
|
|
myproduct.value = await products.getProductById(
|
|
myproduct.value._id,
|
|
load
|
|
);
|
|
}
|
|
|
|
/*async function refreshDataFromGM() {
|
|
if (myproduct.value) {
|
|
loading.value = true
|
|
const ris = await globalStore.updateLocalDbFromGM_T_Web_Articoli(myproduct.value.productInfo.sku!, myproduct.value.isbn)
|
|
if (ris) {
|
|
|
|
await updateproduct(false)
|
|
|
|
tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK'))
|
|
}
|
|
loading.value = false
|
|
}
|
|
|
|
}*/
|
|
|
|
async function refreshSingleBookFromGM(options: any) {
|
|
if (myproduct.value) {
|
|
loading.value = true;
|
|
await globalStore
|
|
.updateAllBookFromGM_T_Web_Articoli({
|
|
sku: myproduct.value.productInfo.sku!,
|
|
isbn: myproduct.value.productInfo.code,
|
|
...options,
|
|
})
|
|
.then((ris) => {
|
|
if (ris) {
|
|
if (ris.error) {
|
|
tools.showNegativeNotif($q, ris.error);
|
|
} else {
|
|
updateproduct(false);
|
|
// console.log('product AGGIORNATO:', myproduct.value)
|
|
tools.showPositiveNotif($q, t('dbgm.updateLocalDb_OK'));
|
|
}
|
|
loading.value = false;
|
|
}
|
|
})
|
|
.catch((e) => {
|
|
console.error('Errore aggiornamento singolo libro:', e);
|
|
tools.showNegativeNotif($q, t('dbgm.updateLocalDb_ERROR'));
|
|
loading.value = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
async function scrapingBook(update: boolean, aggiornasoloSeVuoti: boolean) {
|
|
const options = {
|
|
update,
|
|
aggiornasoloSeVuoti,
|
|
}
|
|
const myparam = { product_id: myproduct.value._id, options };
|
|
|
|
loading.value = true;
|
|
|
|
const dataupdated = await globalStore
|
|
.scrapingBook(myparam)
|
|
.then((dataupdated) => {
|
|
if (dataupdated) {
|
|
tools.showPositiveNotif($q, t('dbgm.scrapingOkUpdated'));
|
|
}
|
|
return dataupdated;
|
|
})
|
|
.catch((e) => {
|
|
console.error('Errore aggiornamento singolo libro:', e);
|
|
tools.showNegativeNotif($q, t('dbgm.updateLocalDb_ERROR'));
|
|
loading.value = false;
|
|
});
|
|
|
|
if (dataupdated) {
|
|
updateproductmodif()
|
|
}
|
|
|
|
loading.value = false;
|
|
}
|
|
|
|
onMounted(mounted);
|
|
|
|
return {
|
|
tools,
|
|
globalStore,
|
|
costanti,
|
|
shared_consts,
|
|
t,
|
|
products,
|
|
getArrListScheda,
|
|
getArrListDescrizioni,
|
|
getArrListStat,
|
|
mytab,
|
|
myproduct,
|
|
updateproductmodif,
|
|
updatetogm,
|
|
field_updated_toGM,
|
|
loading,
|
|
updateRecordToGM,
|
|
refreshSingleBookFromGM,
|
|
scrapingBook,
|
|
// refreshDataFromGM,
|
|
};
|
|
},
|
|
});
|