2023-11-30 14:27:46 +01:00
|
|
|
import { ref, onMounted, onBeforeMount, PropType, reactive, watch } from 'vue'
|
2021-09-04 15:05:34 +02:00
|
|
|
import { CCardState } from '../CCardState'
|
|
|
|
|
|
|
|
|
|
import { computed, defineComponent } from 'vue'
|
|
|
|
|
import { useGlobalStore } from '@store/globalStore'
|
|
|
|
|
import { useProducts } from '@store/Products'
|
2025-03-01 14:14:43 +01:00
|
|
|
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-03-01 14:14:43 +01:00
|
|
|
import { useI18n } from 'vue-i18n'
|
2024-01-13 00:29:02 +01:00
|
|
|
|
2021-09-16 21:08:02 +02:00
|
|
|
import MixinUsers from '../../mixins/mixin-users'
|
2021-09-04 15:05:34 +02:00
|
|
|
|
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() {
|
|
|
|
|
const globalStore = useGlobalStore()
|
|
|
|
|
const products = useProducts()
|
2024-01-13 00:29:02 +01:00
|
|
|
const { t } = useI18n()
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2021-09-16 21:08:02 +02:00
|
|
|
const { getnumItemsCart } = MixinUsers()
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
const myCart = computed(() => products.cart)
|
|
|
|
|
const myTotalPrice = computed(() => {
|
|
|
|
|
if (products.cart) {
|
|
|
|
|
return products.cart.totalPrice
|
|
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const ordersCart = computed(() => {
|
|
|
|
|
if (!!products.cart) {
|
|
|
|
|
return products.cart.items
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const numOrders = computed(() => {
|
2023-12-10 15:15:27 +01:00
|
|
|
if (!!products.cart && products.cart.items) {
|
|
|
|
|
return products.cart.items.length
|
2021-09-04 15:05:34 +02:00
|
|
|
} else {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function closecart() {
|
|
|
|
|
globalStore.rightCartOpen = false
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 14:27:46 +01:00
|
|
|
function mounted() {
|
|
|
|
|
products.loadOrders()
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 00:50:42 +01:00
|
|
|
function existsOrders() {
|
|
|
|
|
return products.getNumOrders() > 0
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-30 14:27:46 +01:00
|
|
|
onMounted(mounted)
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
return {
|
|
|
|
|
myCart,
|
|
|
|
|
myTotalPrice,
|
|
|
|
|
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,
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|