2021-09-04 15:05:34 +02:00
|
|
|
import { tools } from '../../store/Modules/tools'
|
|
|
|
|
import { CCardState } from '../CCardState'
|
|
|
|
|
import { CCopyBtn } from '../CCopyBtn'
|
|
|
|
|
|
2025-03-01 14:14:43 +01:00
|
|
|
import type { IOrder} from '@src/model';
|
|
|
|
|
import { IOperators, IProduct } from '@src/model'
|
|
|
|
|
import type { PropType} from 'vue';
|
|
|
|
|
import { defineComponent, toRef, ref, watch, onMounted } from 'vue'
|
2021-09-16 21:08:02 +02:00
|
|
|
import { CTitleBanner } from '@src/components/CTitleBanner'
|
2021-09-04 15:05:34 +02:00
|
|
|
import { useProducts } from '@store/Products'
|
2025-03-01 14:14:43 +01:00
|
|
|
import { useI18n } from 'vue-i18n'
|
2023-12-27 02:58:23 +01:00
|
|
|
import { useQuasar } from 'quasar'
|
2024-01-15 22:19:33 +01:00
|
|
|
import { loadRouteLocation } from 'vue-router'
|
2021-09-04 15:05:34 +02:00
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
|
name: 'CSingleCart',
|
|
|
|
|
props: {
|
|
|
|
|
order: {
|
|
|
|
|
type: Object as PropType<IOrder>,
|
|
|
|
|
required: true,
|
|
|
|
|
},
|
2024-01-09 15:32:21 +01:00
|
|
|
editmode: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2021-09-04 15:05:34 +02:00
|
|
|
showall: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2024-01-09 15:32:21 +01:00
|
|
|
idOrdersCart: {
|
|
|
|
|
type: String,
|
|
|
|
|
required: false,
|
|
|
|
|
default: '',
|
|
|
|
|
},
|
2021-09-04 15:05:34 +02:00
|
|
|
nomodif: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
required: false,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
components: { CTitleBanner, CCardState, CCopyBtn },
|
2024-01-13 00:29:02 +01:00
|
|
|
setup(props, { emit }) {
|
2021-09-04 15:05:34 +02:00
|
|
|
const products = useProducts()
|
|
|
|
|
const order = toRef(props, 'order')
|
2023-12-27 02:58:23 +01:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
|
|
|
const $q = useQuasar()
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2024-01-15 22:19:33 +01:00
|
|
|
const orderQuantity = ref(<number | undefined>undefined);
|
2024-02-13 18:13:36 +01:00
|
|
|
const weight = ref(<number | undefined>undefined);
|
|
|
|
|
const price = ref(<number | undefined>undefined);
|
2024-01-15 22:19:33 +01:00
|
|
|
const orderQuantityPreordered = ref(<number | undefined>undefined);
|
|
|
|
|
const orderTotalPriceProduct = ref(<number | undefined>undefined);
|
|
|
|
|
|
|
|
|
|
const enableQty = ref(false)
|
|
|
|
|
const endload = ref(false)
|
|
|
|
|
const enableQtyPreordered = ref(false)
|
|
|
|
|
const enableChangeTotalPrice = ref(false)
|
|
|
|
|
|
|
|
|
|
watch(orderQuantity, (newValue: any) => {
|
|
|
|
|
if (!newValue)
|
|
|
|
|
order.value.quantity = 0
|
|
|
|
|
else
|
|
|
|
|
order.value.quantity = parseFloat(newValue);
|
|
|
|
|
|
|
|
|
|
enableChangeTotalPrice.value = false
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-13 18:13:36 +01:00
|
|
|
watch(weight, (newValue: any) => {
|
|
|
|
|
if (order.value.product) {
|
|
|
|
|
if (!newValue)
|
|
|
|
|
order.value.product.productInfo.weight = 0
|
|
|
|
|
else
|
|
|
|
|
order.value.product.productInfo.weight = parseFloat(newValue);
|
|
|
|
|
}
|
|
|
|
|
enableChangeTotalPrice.value = false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
watch(price, (newValue: any) => {
|
|
|
|
|
if (order.value) {
|
|
|
|
|
if (!newValue)
|
|
|
|
|
order.value.price = 0
|
|
|
|
|
else
|
|
|
|
|
order.value.price = parseFloat(newValue);
|
|
|
|
|
}
|
|
|
|
|
enableChangeTotalPrice.value = false
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-15 22:19:33 +01:00
|
|
|
watch(orderQuantityPreordered, (newValue: any) => {
|
|
|
|
|
if (!newValue)
|
|
|
|
|
order.value.quantitypreordered = 0
|
|
|
|
|
else
|
|
|
|
|
order.value.quantitypreordered = parseFloat(newValue);
|
|
|
|
|
|
|
|
|
|
enableChangeTotalPrice.value = false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
watch(orderTotalPriceProduct, (newValue: any) => {
|
|
|
|
|
if (!newValue)
|
|
|
|
|
order.value.TotalPriceProduct = 0
|
|
|
|
|
else
|
|
|
|
|
order.value.TotalPriceProduct = parseFloat(newValue);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
watch(() => props.order.TotalPriceProduct, (newValue: any) => {
|
|
|
|
|
if (!newValue)
|
|
|
|
|
orderTotalPriceProduct.value = 0
|
|
|
|
|
else
|
|
|
|
|
orderTotalPriceProduct.value = parseFloat(newValue);
|
|
|
|
|
});
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
function myimgclass() {
|
|
|
|
|
if (props.showall) {
|
|
|
|
|
return 'imgNormal'
|
|
|
|
|
} else {
|
|
|
|
|
return 'imgSmall'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-17 11:13:19 +01:00
|
|
|
async function addsubqty(addqty: boolean, subqty: boolean) {
|
2023-12-20 21:56:30 +01:00
|
|
|
if (products.isQtyAvailableByOrder(props.order)) {
|
|
|
|
|
if (addqty) {
|
2023-12-24 00:56:05 +01:00
|
|
|
if (props.order.quantity >= 100)
|
2023-12-20 21:56:30 +01:00
|
|
|
return false
|
|
|
|
|
}
|
2021-09-04 15:05:34 +02:00
|
|
|
|
2023-12-20 21:56:30 +01:00
|
|
|
if (subqty) {
|
|
|
|
|
if (props.order.quantity === 0)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (products.isInPreorderByOrder(props.order)) {
|
|
|
|
|
if (addqty) {
|
2023-12-24 00:56:05 +01:00
|
|
|
if (props.order.quantitypreordered >= 100)
|
2023-12-20 21:56:30 +01:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (subqty) {
|
|
|
|
|
if (props.order.quantitypreordered === 0)
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-17 11:13:19 +01:00
|
|
|
return await products.addSubQtyToItem({
|
2021-09-04 15:05:34 +02:00
|
|
|
addqty,
|
|
|
|
|
subqty,
|
|
|
|
|
order: props.order,
|
2023-12-15 21:50:28 +01:00
|
|
|
}).then((res: any) => {
|
|
|
|
|
if (res.risult) {
|
2023-12-27 02:58:23 +01:00
|
|
|
if (res.myord) {
|
|
|
|
|
order.value.quantity = res.myord.quantity
|
|
|
|
|
order.value.quantitypreordered = res.myord.quantitypreordered
|
|
|
|
|
}
|
2023-12-15 21:50:28 +01:00
|
|
|
}
|
2021-09-04 15:05:34 +02:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-18 08:02:35 +01:00
|
|
|
function isApplicatoSconto() {
|
2023-12-27 02:58:23 +01:00
|
|
|
const totalipotetico = order.value.product!.price * (order.value.quantity + order.value.quantitypreordered)
|
2024-02-13 18:13:36 +01:00
|
|
|
if (totalipotetico.toFixed(2) > order.value.TotalPriceProduct.toFixed(2)) {
|
2023-12-18 08:02:35 +01:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
function removeFromCard() {
|
2024-01-15 22:19:33 +01:00
|
|
|
products.removeFromCart({ order: order.value })
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-13 00:29:02 +01:00
|
|
|
async function updateOrder(paramstoupdate: any) {
|
2024-01-15 22:19:33 +01:00
|
|
|
endload.value = false
|
|
|
|
|
if (enableChangeTotalPrice.value) {
|
|
|
|
|
paramstoupdate = { ...paramstoupdate, TotalPriceProduct: order.value.TotalPriceProduct }
|
|
|
|
|
}
|
|
|
|
|
const myOrdersCart = await products.updateOrderByOrder(props.idOrdersCart, order.value._id, paramstoupdate)
|
2024-01-13 00:29:02 +01:00
|
|
|
emit('update')
|
2024-01-15 22:19:33 +01:00
|
|
|
mounted()
|
2024-01-12 13:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-27 02:58:23 +01:00
|
|
|
function getRisparmio(): string {
|
|
|
|
|
return ((order.value.product!.price * order.value.quantity) - order.value.TotalPriceProduct).toFixed(2)
|
2023-12-18 15:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-15 22:19:33 +01:00
|
|
|
function mounted() {
|
|
|
|
|
endload.value = false
|
2024-02-13 18:13:36 +01:00
|
|
|
weight.value = props.order.product?.productInfo.weight
|
|
|
|
|
price.value = props.order.price
|
2024-01-15 22:19:33 +01:00
|
|
|
if (props.order.quantity !== 0) {
|
|
|
|
|
orderQuantity.value = props.order.quantity
|
|
|
|
|
enableQty.value = true
|
|
|
|
|
}
|
|
|
|
|
if (props.order.quantitypreordered !== 0) {
|
|
|
|
|
orderQuantityPreordered.value = props.order.quantitypreordered
|
|
|
|
|
enableQtyPreordered.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orderTotalPriceProduct.value = props.order.TotalPriceProduct
|
|
|
|
|
endload.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function changeTotalPrice() {
|
|
|
|
|
console.log('changeTotalPrice')
|
|
|
|
|
enableChangeTotalPrice.value = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(mounted)
|
|
|
|
|
|
2021-09-04 15:05:34 +02:00
|
|
|
return {
|
|
|
|
|
myimgclass,
|
|
|
|
|
addsubqty,
|
|
|
|
|
removeFromCard,
|
2023-12-18 08:02:35 +01:00
|
|
|
isApplicatoSconto,
|
2023-12-18 15:21:12 +01:00
|
|
|
getRisparmio,
|
2023-12-24 00:56:05 +01:00
|
|
|
tools,
|
|
|
|
|
products,
|
2023-12-27 02:58:23 +01:00
|
|
|
t,
|
2024-01-12 13:03:07 +01:00
|
|
|
updateOrder,
|
2024-01-15 22:19:33 +01:00
|
|
|
orderQuantity,
|
2024-02-13 18:13:36 +01:00
|
|
|
weight,
|
|
|
|
|
price,
|
2024-01-15 22:19:33 +01:00
|
|
|
orderQuantityPreordered,
|
|
|
|
|
enableQty,
|
|
|
|
|
enableQtyPreordered,
|
|
|
|
|
changeTotalPrice,
|
|
|
|
|
orderTotalPriceProduct,
|
|
|
|
|
endload,
|
2021-09-04 15:05:34 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|