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';
|
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';
|
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();
|
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 10:08:07 +02:00
|
|
|
const myCart = computed(() => 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
|
|
|
|
|
|
|
|
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 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 10:08:07 +02:00
|
|
|
};
|
2021-09-04 15:05:34 +02:00
|
|
|
},
|
2025-06-12 10:08:07 +02:00
|
|
|
});
|