- Aggiunto bottone Aggiungi al Carrello sulla lista dei libri dei cataloghi
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
import { PropType, computed, defineComponent, onMounted, ref, watch } from 'vue';
|
||||
import {
|
||||
PropType,
|
||||
computed,
|
||||
defineComponent,
|
||||
onMounted,
|
||||
ref,
|
||||
watch,
|
||||
reactive,
|
||||
} from 'vue';
|
||||
import draggable from 'vuedraggable';
|
||||
|
||||
import { tools } from '@tools';
|
||||
@@ -7,7 +15,8 @@ import { useQuasar } from 'quasar';
|
||||
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useGlobalStore } from '@src/store/globalStore';
|
||||
import { useProducts } from '@src/store/productStore';
|
||||
import { useProducts } from '@src/store/Products';
|
||||
import { useUserStore } from '@src/store/UserStore';
|
||||
|
||||
import { CMyValueDb } from '@src/components/CMyValueDb';
|
||||
import { CSchedaProdotto } from '@src/components/CSchedaProdotto';
|
||||
@@ -20,7 +29,6 @@ import { IAuthor, ICatProd } from 'app/src/model';
|
||||
|
||||
import type { IMyScheda, IOptCatalogo, IProduct } from '@src/model';
|
||||
import { shared_consts } from 'app/src/common/shared_vuejs';
|
||||
import { useProducts } from 'app/src/store/Products';
|
||||
import { CViewTable } from '../CViewTable';
|
||||
import { CLabel } from '../CLabel';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -67,16 +75,17 @@ export default defineComponent({
|
||||
// Copia locale della lista_prodotti per manipolazione interna
|
||||
const internalProducts = ref([...(props.lista_prodotti || [])]);
|
||||
|
||||
const productStore = useProducts();
|
||||
|
||||
const $router = useRouter();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const $q = useQuasar();
|
||||
|
||||
const arrordersCart = ref(<IOrderCart[]>[]);
|
||||
|
||||
const globalStore = useGlobalStore();
|
||||
const products = useProducts();
|
||||
const ProductStore = useProducts();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const showProd = ref(false);
|
||||
const selProd = ref(<IProduct | null>null);
|
||||
@@ -97,6 +106,7 @@ export default defineComponent({
|
||||
|
||||
const addstr = ref('');
|
||||
|
||||
|
||||
const optionscatalogo = ref(<any>{ maxlength: 0 });
|
||||
|
||||
function handleUpdate(newList) {
|
||||
@@ -302,6 +312,14 @@ export default defineComponent({
|
||||
noexp: true,
|
||||
notsortable: true,
|
||||
},
|
||||
{
|
||||
name: 'addtocart',
|
||||
label: 'Carrello',
|
||||
field: 'addtocart',
|
||||
align: 'center',
|
||||
noexp: true,
|
||||
notsortable: true,
|
||||
},
|
||||
{ name: 'name', label: 'Titolo', field: 'name', align: 'left' },
|
||||
{
|
||||
name: 'sottotitolo',
|
||||
@@ -436,18 +454,28 @@ export default defineComponent({
|
||||
|
||||
const allColumnsComputed = computed(() => {
|
||||
return allColumns.value.filter(
|
||||
(col) => !col.visu || col.visu === costanti.VISUCAMPI.PER_TUTTI || (col.visu === costanti.VISUCAMPI.PER_EDITORE && tools.isCollaboratore())
|
||||
(col) =>
|
||||
!col.visu ||
|
||||
col.visu === costanti.VISUCAMPI.PER_TUTTI ||
|
||||
(col.visu === costanti.VISUCAMPI.PER_EDITORE && tools.isCollaboratore())
|
||||
);
|
||||
});
|
||||
|
||||
async function mounted() {
|
||||
console.log('mounted CProductTable');
|
||||
//myorder = ProductStore.createMyOrder()
|
||||
// ProductStore.initproduct(myorder);
|
||||
|
||||
internalProducts.value.forEach((p: IProduct) => {
|
||||
p.myorder = ProductStore.createMyOrder();
|
||||
});
|
||||
|
||||
// console.log('mounted CProductTable');
|
||||
loading.value = true;
|
||||
|
||||
if (props.table === shared_consts.TABLES_CATALOG) {
|
||||
selectedColumns.value = selectedColumns_Catalogs.value;
|
||||
} else {
|
||||
// "products"
|
||||
// "ProductStore"
|
||||
selectedColumns.value = tools.isUtente()
|
||||
? selectedColumns_Utenti.value
|
||||
: selectedColumns_Editori.value;
|
||||
@@ -455,10 +483,10 @@ export default defineComponent({
|
||||
|
||||
addstr.value = tools.addstrCookie(props.table);
|
||||
|
||||
if (props.table === 'products') {
|
||||
if (props.table === shared_consts.TABLES_PRODUCTS) {
|
||||
allColumns.value = allColumns_Catalog.value;
|
||||
isVisibleEditBtn.value = true;
|
||||
} else if (props.table === 'catalogs') {
|
||||
} else if (props.table === shared_consts.TABLES_CATALOG) {
|
||||
allColumns.value = allColumns_Raccolta.value;
|
||||
isVisibleEditBtn.value = false;
|
||||
}
|
||||
@@ -522,6 +550,8 @@ export default defineComponent({
|
||||
return tools.getstrDate(catalog.data_online);
|
||||
case 'data_online_stampa':
|
||||
return tools.getstrDate(catalog.data_online_stampa);
|
||||
case 'addtocart':
|
||||
return true;
|
||||
case 'image':
|
||||
return catalog.foto_collana?.imagefile
|
||||
? tools.getFullFileNameByImageFile(
|
||||
@@ -535,7 +565,10 @@ export default defineComponent({
|
||||
switch (field.field) {
|
||||
case 'image':
|
||||
return element.productInfo?.imagefile
|
||||
? tools.getFullFileNameByImageFile('productInfos', element.productInfo?.imagefile)
|
||||
? tools.getFullFileNameByImageFile(
|
||||
'productInfos',
|
||||
element.productInfo?.imagefile
|
||||
)
|
||||
: element.productInfo?.image_link;
|
||||
|
||||
case 'name':
|
||||
@@ -576,21 +609,25 @@ export default defineComponent({
|
||||
return element.arrvariazioni?.[0]?.edizione;
|
||||
|
||||
case 'casaeditrice':
|
||||
return products.getCasaEditriceByIdPublisher(element.productInfo?.idPublisher);
|
||||
return ProductStore.getCasaEditriceByIdPublisher(
|
||||
element.productInfo?.idPublisher
|
||||
);
|
||||
|
||||
case 'idCollana':
|
||||
return tools.formatCollane(element.productInfo?.idCollana);
|
||||
|
||||
case 'stato':
|
||||
return products.getDescrStatiProdottoByIdStatoProdotto(
|
||||
return ProductStore.getDescrStatiProdottoByIdStatoProdotto(
|
||||
element.productInfo?.idStatoProdotto || ''
|
||||
);
|
||||
|
||||
case 'tipologia':
|
||||
return products.getDescrByIdTipologia(element.arrvariazioni?.[0]?.idTipologia || '');
|
||||
return ProductStore.getDescrByIdTipologia(
|
||||
element.arrvariazioni?.[0]?.idTipologia || ''
|
||||
);
|
||||
|
||||
case 'tipoformato':
|
||||
return products.getDescrByIdTipoFormato(
|
||||
return ProductStore.getDescrByIdTipoFormato(
|
||||
element.arrvariazioni?.[0]?.idTipoFormato || ''
|
||||
);
|
||||
|
||||
@@ -599,11 +636,11 @@ export default defineComponent({
|
||||
|
||||
case 'prezzo':
|
||||
// return element.price ? '€ ' + element.price.toFixed(2) : '';
|
||||
return '€ ' + element.arrvariazioni?.[0]?.price.toFixed(2);
|
||||
return '€ ' + element.arrvariazioni?.[0]?.price?.toFixed(2);
|
||||
|
||||
case 'prezzo_sconto':
|
||||
// return element.sale_price ? '€ ' + element.sale_price.toFixed(2) : '';
|
||||
return '€ ' + element.arrvariazioni?.[0]?.sale_price.toFixed(2);
|
||||
return '€ ' + element.arrvariazioni?.[0]?.sale_price?.toFixed(2);
|
||||
|
||||
case 'rank3M':
|
||||
return element.productInfo?.rank3M;
|
||||
@@ -637,7 +674,9 @@ export default defineComponent({
|
||||
|
||||
case 'quantity':
|
||||
if (tools.isUtente())
|
||||
return tools.getDescrQuantitàByQuantity(element.arrvariazioni?.[0]?.quantita);
|
||||
return tools.getDescrQuantitàByQuantity(
|
||||
element.arrvariazioni?.[0]?.quantita
|
||||
);
|
||||
else return element.arrvariazioni?.[0]?.quantita;
|
||||
|
||||
default:
|
||||
@@ -659,13 +698,13 @@ export default defineComponent({
|
||||
: 'text-red';
|
||||
|
||||
case 'stato':
|
||||
if (products.isProssimaUscita(element.productInfo)) {
|
||||
if (ProductStore.isProssimaUscita(element.productInfo)) {
|
||||
return 'bg-purple-3';
|
||||
}
|
||||
if (products.isPrevendita(element.productInfo)) {
|
||||
if (ProductStore.isPrevendita(element.productInfo)) {
|
||||
return 'bg-blue-3';
|
||||
}
|
||||
if (products.isNonVendibile(element.productInfo)) {
|
||||
if (ProductStore.isNonVendibile(element.productInfo)) {
|
||||
return 'bg-grey';
|
||||
}
|
||||
return '';
|
||||
@@ -680,14 +719,14 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
case 'quantity':
|
||||
if (products.isPubblicato(element.productInfo)) {
|
||||
if (products.isQtaLimitata(element)) {
|
||||
if (ProductStore.isPubblicato(element.productInfo)) {
|
||||
if (ProductStore.isQtaLimitata(element)) {
|
||||
return 'bg-yellow';
|
||||
}
|
||||
if (products.isInEsaurendo(element)) {
|
||||
if (ProductStore.isInEsaurendo(element)) {
|
||||
return 'bg-orange';
|
||||
}
|
||||
if (products.isEsaurito(element)) {
|
||||
if (ProductStore.isEsaurito(element)) {
|
||||
return 'text-white bg-red-10';
|
||||
}
|
||||
}
|
||||
@@ -846,14 +885,19 @@ export default defineComponent({
|
||||
persistent: false,
|
||||
})
|
||||
.onOk(() => {
|
||||
internalProducts.value = internalProducts.value.filter((p: any) => p._id !== product._id);
|
||||
internalProducts.value = internalProducts.value.filter(
|
||||
(p: any) => p._id !== product._id
|
||||
);
|
||||
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
|
||||
});
|
||||
};
|
||||
|
||||
// 8. Salvataggio delle colonne selezionate in un cookie
|
||||
const saveSelectedColumns = () => {
|
||||
tools.setCookie(addstr.value + 'selColCat_2', JSON.stringify(selectedColumns.value));
|
||||
tools.setCookie(
|
||||
addstr.value + 'selColCat_2',
|
||||
JSON.stringify(selectedColumns.value)
|
||||
);
|
||||
};
|
||||
|
||||
// 9. Watcher per salvare automaticamente le preferenze quando cambiano
|
||||
@@ -901,7 +945,7 @@ export default defineComponent({
|
||||
let link_macro = element.productInfo?.link_macro;
|
||||
|
||||
if (tools.isUtente() && link_macro) {
|
||||
tools.openUrl(link_macro + '?utm_source=catalog&id=' + props.idcatalog)
|
||||
tools.openUrl(link_macro + '?utm_source=catalog&id=' + props.idcatalog);
|
||||
} else {
|
||||
selProd.value = element;
|
||||
|
||||
@@ -910,7 +954,7 @@ export default defineComponent({
|
||||
} else if (isCatalog()) {
|
||||
// Apri la pagina del catalogo
|
||||
if (element.idPageAssigned) {
|
||||
const mypagepath = productStore.getPathByPage(element.idPageAssigned);
|
||||
const mypagepath = ProductStore.getPathByPage(element.idPageAssigned);
|
||||
|
||||
// fai il route sulla pagina myfilename
|
||||
$router.push(`/${mypagepath}`);
|
||||
@@ -953,9 +997,9 @@ export default defineComponent({
|
||||
console.log('PRODUCT TABLE: updateproductmodif');
|
||||
try {
|
||||
if (element?._id) {
|
||||
selProd.value = await products.getProductById(element?._id);
|
||||
selProd.value = await ProductStore.getProductById(element?._id);
|
||||
} else {
|
||||
selProd.value = await products.getProductById(selProd.value?._id);
|
||||
selProd.value = await ProductStore.getProductById(selProd.value?._id);
|
||||
}
|
||||
|
||||
// update record inside internalProducts
|
||||
@@ -1019,7 +1063,9 @@ export default defineComponent({
|
||||
return sortDirection.value === 1 ? aVal - bVal : bVal - aVal;
|
||||
}
|
||||
if (typeof aVal === 'string' && typeof bVal === 'string') {
|
||||
return sortDirection.value === 1 ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal);
|
||||
return sortDirection.value === 1
|
||||
? aVal.localeCompare(bVal)
|
||||
: bVal.localeCompare(aVal);
|
||||
}
|
||||
return sortDirection.value === 1
|
||||
? String(aVal).localeCompare(String(bVal))
|
||||
@@ -1092,7 +1138,9 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function isSortable(field: string): boolean {
|
||||
return allColumns && !allColumns.value.find((col) => col.name === field)?.notsortable;
|
||||
return (
|
||||
allColumns && !allColumns.value.find((col) => col.name === field)?.notsortable
|
||||
);
|
||||
}
|
||||
|
||||
function getImageByElement(element) {
|
||||
@@ -1107,10 +1155,48 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function isProduct() {
|
||||
return props.table === 'products';
|
||||
return props.table === shared_consts.TABLES_PRODUCTS;
|
||||
}
|
||||
function isCatalog() {
|
||||
return props.table === 'catalogs';
|
||||
return props.table === shared_consts.TABLES_CATALOG;
|
||||
}
|
||||
|
||||
/*
|
||||
async function addToCart(element: any) {
|
||||
if (props.table === shared_consts.TABLES_PRODUCTS) {
|
||||
await updateProduct(element);
|
||||
|
||||
if (!!element) {
|
||||
arrordersCart.value = ProductStore.getOrdersCartInAttesaByIdProduct(
|
||||
element._id
|
||||
);
|
||||
|
||||
ProductStore.setMyOrder(myorder, element, null, {
|
||||
setstore: false,
|
||||
});
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
async function addtoCart(element: any, add: boolean) {
|
||||
if (!userStore.isLogged) {
|
||||
tools.showNeutralNotif($q, t('ecomm.area_personale'));
|
||||
globalStore.rightDrawerOpen = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
ProductStore.setMyOrder(element.myorder, element, null, {
|
||||
setstore: false,
|
||||
});
|
||||
|
||||
const ris = await ProductStore.addtoCartBase({
|
||||
$q,
|
||||
t,
|
||||
id: element._id,
|
||||
order: element.myorder,
|
||||
addqty: add,
|
||||
});
|
||||
updateProduct(element);
|
||||
}
|
||||
|
||||
onMounted(mounted);
|
||||
@@ -1144,7 +1230,7 @@ export default defineComponent({
|
||||
updateproductmodif,
|
||||
optionscatalogo,
|
||||
t,
|
||||
products,
|
||||
ProductStore,
|
||||
sortTable,
|
||||
sortAttribute,
|
||||
sortDirection,
|
||||
@@ -1160,6 +1246,8 @@ export default defineComponent({
|
||||
isProduct,
|
||||
isCatalog,
|
||||
allColumnsComputed,
|
||||
addtoCart,
|
||||
arrordersCart,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user