Corretto Ordini e visualizzazione dei Totali
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { defineComponent, ref, toRef, computed, PropType, watch, onMounted } from 'vue'
|
||||
import { defineComponent, ref, toRef, computed, PropType, watch, onMounted, reactive } from 'vue'
|
||||
import { useI18n } from '@src/boot/i18n'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
@@ -8,10 +8,13 @@ import { CTitleBanner } from '../CTitleBanner'
|
||||
import { CCardState } from '../CCardState'
|
||||
import { CCopyBtn } from '../CCopyBtn'
|
||||
|
||||
import { IOrder, IProduct } from '@src/model'
|
||||
import { func_tools, toolsext } from '@store/Modules/toolsext'
|
||||
|
||||
import { IOrder, IOrderCart, IProduct } from '@src/model'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { useProducts } from '@store/Products'
|
||||
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'CProductCard',
|
||||
@@ -40,22 +43,28 @@ export default defineComponent({
|
||||
const globalStore = useGlobalStore()
|
||||
const products = useProducts()
|
||||
|
||||
const myorder = ref(<IOrder>{
|
||||
const myorder = reactive(<IOrder>{
|
||||
idapp: process.env.APP_ID,
|
||||
quantity: 0,
|
||||
idStorehouse: '',
|
||||
idProvider: ''
|
||||
})
|
||||
|
||||
const myproduct = ref(<IProduct>{})
|
||||
|
||||
const storeSelected = ref('')
|
||||
const arrordersCart = ref(<IOrderCart[]>[])
|
||||
|
||||
const openlistorders = ref(false)
|
||||
const endload = ref(false)
|
||||
|
||||
const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean) => {
|
||||
// console.log('valoriopt', item.table)
|
||||
return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter)
|
||||
})
|
||||
|
||||
const myproduct = computed((): IProduct => {
|
||||
return products.getProduct(props.code)
|
||||
})
|
||||
|
||||
|
||||
function iconWhishlist(order: IProduct) {
|
||||
if (true) {
|
||||
@@ -64,17 +73,6 @@ export default defineComponent({
|
||||
return 'fas fa-heart'
|
||||
}
|
||||
}
|
||||
|
||||
function decqty() {
|
||||
if (myorder.value.quantity > 0)
|
||||
myorder.value.quantity--
|
||||
}
|
||||
|
||||
function addqty() {
|
||||
if (myorder.value.quantity < 10)
|
||||
myorder.value.quantity++
|
||||
}
|
||||
|
||||
function addtoCart(add: boolean) {
|
||||
|
||||
if (!userStore.isLogged) {
|
||||
@@ -83,24 +81,27 @@ export default defineComponent({
|
||||
return false
|
||||
}
|
||||
|
||||
products.addToCart({ product: myproduct.value, order: myorder.value, addqty: add }).then((ris) => {
|
||||
|
||||
products.addToCart({ product: myproduct.value, order: myorder, addqty: add }).then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
if (myorder.value.quantity > 1 || myorder.value.quantity === 0)
|
||||
|
||||
if (myorder.quantity > 1 || myorder.quantity === 0)
|
||||
strprod = t('ecomm.prodotti')
|
||||
|
||||
let msg = ''
|
||||
if (ris === null)
|
||||
msg = t('ecomm.error_cart')
|
||||
else {
|
||||
if (myorder.value.quantity === 0) {
|
||||
|
||||
if (myorder.quantity === 0) {
|
||||
msg = t('ecomm.prodotto_tolto')
|
||||
} else {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: myorder.value.quantity })
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: myorder.quantity })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ris === null || myorder.value.quantity === 0)
|
||||
if (ris === null || myorder.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
@@ -147,28 +148,26 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function checkifCartDisable() {
|
||||
return !myorder.value.idStorehouse
|
||||
// return !myorder.idStorehouse
|
||||
return false
|
||||
}
|
||||
|
||||
function updateQtyAvailable() {
|
||||
myproduct.value.quantityAvailable = myproduct.value.stockQty
|
||||
if (myorder.value.quantity > 0) {
|
||||
myproduct.value.quantityAvailable -= myorder.value.quantity
|
||||
}
|
||||
if (myproduct.value.QuantitaOrdinateInAttesa > 0) {
|
||||
myproduct.value.quantityAvailable -= myproduct.value.QuantitaOrdinateInAttesa
|
||||
if (myproduct.value.QuantitaOrdinateInAttesa! > 0) {
|
||||
myproduct.value.quantityAvailable! -= myproduct.value.QuantitaOrdinateInAttesa!
|
||||
}
|
||||
}
|
||||
|
||||
function getQtyAvailable() {
|
||||
updateQtyAvailable()
|
||||
let qty = myproduct.value.quantityAvailable
|
||||
let qty = myproduct.value.quantityAvailable!
|
||||
return qty
|
||||
}
|
||||
|
||||
function getQtyWarn() {
|
||||
if (myorder.value.quantity > 0) {
|
||||
return t('ecomm.di_cui_x_in_carrello', { qty: myorder.value.quantity })
|
||||
if (myorder.quantity > 0) {
|
||||
return t('ecomm.di_cui_x_in_carrello', { qty: myorder.quantity })
|
||||
}
|
||||
return ''
|
||||
}
|
||||
@@ -179,32 +178,27 @@ export default defineComponent({
|
||||
})
|
||||
|
||||
watch(() => storeSelected.value, (newval, oldval) => {
|
||||
myorder.value.idStorehouse = newval
|
||||
myorder.idStorehouse = newval
|
||||
})
|
||||
|
||||
async function load() {
|
||||
function load() {
|
||||
// console.log('created Cproductcard', code)
|
||||
if (props.code) {
|
||||
myproduct.value = await products.loadProduct({ code: props.code })
|
||||
} else {
|
||||
// @ts-ignore
|
||||
myproduct.value = props.product
|
||||
}
|
||||
|
||||
console.log('myproduct', myproduct, 'product', props.product)
|
||||
arrordersCart.value = products.getOrdersCartByIdProduct(myproduct.value._id)
|
||||
|
||||
if (!!myproduct.value) {
|
||||
if (myproduct.value.storehouses && myproduct.value.storehouses.length === 1) {
|
||||
myorder.value.idStorehouse = myproduct.value.storehouses[0]._id
|
||||
myorder.idStorehouse = myproduct.value.storehouses[0]._id
|
||||
}
|
||||
|
||||
const ord = products.getOrderProductInCart(myproduct.value._id)
|
||||
if (ord) {
|
||||
myorder.value.quantity = ord.quantity
|
||||
myorder.quantity = ord.quantity
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
endload.value = true
|
||||
}
|
||||
|
||||
function getmycardcl() {
|
||||
@@ -216,7 +210,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function enableSubQty() {
|
||||
return myorder.value ? myorder.value.quantity > 0 : true
|
||||
return myorder.quantity ? myorder.quantity > 0 : false
|
||||
}
|
||||
|
||||
function enableAddQty() {
|
||||
@@ -226,8 +220,6 @@ export default defineComponent({
|
||||
onMounted(load)
|
||||
|
||||
return {
|
||||
decqty,
|
||||
addqty,
|
||||
addtoCart,
|
||||
iconWhishlist,
|
||||
getmycardcl,
|
||||
@@ -245,6 +237,13 @@ export default defineComponent({
|
||||
enableAddQty,
|
||||
getQtyAvailable,
|
||||
getQtyWarn,
|
||||
openlistorders,
|
||||
func_tools,
|
||||
toolsext,
|
||||
products,
|
||||
arrordersCart,
|
||||
endload,
|
||||
shared_consts,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user