2025-06-12 10:08:07 +02:00
|
|
|
import { ref, onMounted, onBeforeMount, PropType, reactive, watch } from 'vue';
|
|
|
|
|
import { CCardState } from '../CCardState';
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2025-06-12 10:08:07 +02:00
|
|
|
import { computed, defineComponent } from 'vue';
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore';
|
|
|
|
|
import { useProducts } from '@store/Products';
|
|
|
|
|
import { CCopyBtn } from '@src/components/CCopyBtn';
|
|
|
|
|
import { CSingleCart } from '@src/components/CSingleCart';
|
|
|
|
|
import { CTitleBanner } from '@src/components/CTitleBanner';
|
2025-06-12 23:49:13 +02:00
|
|
|
import { tools } from '@store/Modules/tools';
|
2021-09-16 21:08:02 +02:00
|
|
|
|
2025-06-12 10:08:07 +02:00
|
|
|
import { useI18n } from 'vue-i18n';
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2025-06-12 10:08:07 +02:00
|
|
|
import MixinUsers from '../../mixins/mixin-users';
|
2025-06-12 23:49:13 +02:00
|
|
|
import { useQuasar } from 'quasar';
|
2025-09-02 16:22:13 +02:00
|
|
|
import { ICart } from 'app/src/model';
|
2024-01-13 00:29:02 +01:00
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'CMyCart',
|
|
|
|
|
props: {},
|
|
|
|
|
components: { CTitleBanner, CCardState, CCopyBtn, CSingleCart },
|
|
|
|
|
|
|
|
|
|
setup() {
|
2025-06-12 10:08:07 +02:00
|
|
|
const globalStore = useGlobalStore();
|
|
|
|
|
const productStore = useProducts();
|
|
|
|
|
const { t } = useI18n();
|
2025-06-12 23:49:13 +02:00
|
|
|
const $q = useQuasar();
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2025-06-12 10:08:07 +02:00
|
|
|
const { getnumItemsCart } = MixinUsers();
|
2021-09-16 21:08:02 +02:00
|
|
|
|
2025-06-12 23:49:13 +02:00
|
|
|
const codice_sconto = ref('')
|
|
|
|
|
const descr_sconto = ref('')
|
|
|
|
|
const caricamentodati = ref(false)
|
|
|
|
|
|
2025-09-02 16:22:13 +02:00
|
|
|
const myCart = computed<ICart | null>(() => productStore.cart);
|
2021-09-04 15:05:34 +02:00
|
|
|
const myTotalPrice = computed(() => {
|
2025-06-12 10:08:07 +02:00
|
|
|
if (productStore.cart) {
|
|
|
|
|
return productStore.cart.totalPrice.toFixed(2);
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const totalPriceIntero = computed((): string => {
|
|
|
|
|
if (productStore.cart && productStore.cart.totalPriceIntero) {
|
|
|
|
|
return productStore.cart.totalPriceIntero.toFixed(2);
|
2021-09-04 15:05:34 +02:00
|
|
|
} else {
|
2025-06-12 10:08:07 +02:00
|
|
|
return '0';
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
2025-06-12 10:08:07 +02:00
|
|
|
});
|
2021-09-04 15:05:34 +02:00
|
|
|
|
|
|
|
|
const ordersCart = computed(() => {
|
2025-06-12 10:08:07 +02:00
|
|
|
if (!!productStore.cart) {
|
|
|
|
|
return productStore.cart.items;
|
2021-09-04 15:05:34 +02:00
|
|
|
} else {
|
2025-06-12 10:08:07 +02:00
|
|
|
return null;
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
2025-06-12 10:08:07 +02:00
|
|
|
});
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2025-09-02 16:22:13 +02:00
|
|
|
const idOrdersCart = computed(() => {
|
|
|
|
|
if (!!productStore.cart) {
|
|
|
|
|
return productStore.cart._id;
|
|
|
|
|
} else {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
const numOrders = computed(() => {
|
2025-06-12 10:08:07 +02:00
|
|
|
if (!!productStore.cart && productStore.cart.items) {
|
|
|
|
|
return productStore.cart.items.length;
|
2021-09-04 15:05:34 +02:00
|
|
|
} else {
|
2025-06-12 10:08:07 +02:00
|
|
|
return 0;
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
2025-06-12 10:08:07 +02:00
|
|
|
});
|
2021-09-04 15:05:34 +02:00
|
|
|
|
|
|
|
|
function closecart() {
|
2025-06-12 10:08:07 +02:00
|
|
|
globalStore.rightCartOpen = false;
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-30 14:27:46 +01:00
|
|
|
function mounted() {
|
2025-06-12 10:08:07 +02:00
|
|
|
productStore.loadOrders();
|
2023-11-30 14:27:46 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-28 00:50:42 +01:00
|
|
|
function existsOrders() {
|
2025-06-12 10:08:07 +02:00
|
|
|
return productStore.getNumOrders() > 0;
|
2023-12-28 00:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
2025-06-12 23:49:13 +02:00
|
|
|
async function applicaSconto(codice: string) {
|
|
|
|
|
try {
|
|
|
|
|
caricamentodati.value = true;
|
|
|
|
|
const rissconto = await productStore.ApplicaSconto({
|
|
|
|
|
cart_id: myCart.value._id,
|
|
|
|
|
codice_sconto: codice,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (rissconto) {
|
|
|
|
|
if (rissconto.msg) {
|
|
|
|
|
tools.showNeutralNotif($q, `${rissconto.msg}`);
|
|
|
|
|
} else if (rissconto.valido && rissconto.mycart) {
|
|
|
|
|
tools.showPositiveNotif($q, 'Sconto Applicato!');
|
|
|
|
|
} else {
|
|
|
|
|
tools.showNegativeNotif($q, `${rissconto.errmsg}`);
|
|
|
|
|
}
|
|
|
|
|
codice_sconto.value = '';
|
|
|
|
|
descr_sconto.value = '';
|
|
|
|
|
if (rissconto.mycart) {
|
2025-09-02 16:22:13 +02:00
|
|
|
myCart.value = rissconto.mycart
|
2025-06-12 23:49:13 +02:00
|
|
|
};
|
|
|
|
|
}
|
2025-09-02 16:22:13 +02:00
|
|
|
} catch (error: any) {
|
2025-06-12 23:49:13 +02:00
|
|
|
console.log('error ApplicaSconto', error);
|
2025-09-02 16:22:13 +02:00
|
|
|
tools.showNegativeNotif($q, `Sconto Non Applicato! ${error?.message || ''}`);
|
2025-06-12 23:49:13 +02:00
|
|
|
codice_sconto.value = '';
|
|
|
|
|
descr_sconto.value = '';
|
|
|
|
|
} finally {
|
|
|
|
|
caricamentodati.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function confermaCodiceSconto() {
|
|
|
|
|
await applicaSconto(codice_sconto.value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-06-12 10:08:07 +02:00
|
|
|
onMounted(mounted);
|
2023-11-30 14:27:46 +01:00
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
return {
|
|
|
|
|
myCart,
|
|
|
|
|
myTotalPrice,
|
2025-06-12 10:08:07 +02:00
|
|
|
totalPriceIntero,
|
2021-09-04 15:05:34 +02:00
|
|
|
ordersCart,
|
|
|
|
|
numOrders,
|
|
|
|
|
closecart,
|
2021-09-16 21:08:02 +02:00
|
|
|
getnumItemsCart,
|
2023-12-28 00:50:42 +01:00
|
|
|
existsOrders,
|
|
|
|
|
globalStore,
|
2024-01-13 00:29:02 +01:00
|
|
|
t,
|
2025-06-12 23:49:13 +02:00
|
|
|
codice_sconto,
|
|
|
|
|
confermaCodiceSconto,
|
|
|
|
|
caricamentodati,
|
|
|
|
|
descr_sconto,
|
2025-09-02 16:22:13 +02:00
|
|
|
idOrdersCart,
|
2025-06-12 10:08:07 +02:00
|
|
|
};
|
2021-09-04 15:05:34 +02:00
|
|
|
},
|
2025-06-12 10:08:07 +02:00
|
|
|
});
|