aggiornamento visualizzazione Ordini e Carrello
This commit is contained in:
@@ -31,17 +31,6 @@ export default defineComponent({
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
order: {
|
||||
type: Object as PropType<IOrder>,
|
||||
required: false,
|
||||
default: () => {
|
||||
return {
|
||||
idapp: process.env.APP_ID,
|
||||
quantity: 1,
|
||||
idStorehouse: ''
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
components: { CTitleBanner, CCardState, CCopyBtn },
|
||||
setup(props, { emit }) {
|
||||
@@ -51,9 +40,13 @@ export default defineComponent({
|
||||
const globalStore = useGlobalStore()
|
||||
const products = useProducts()
|
||||
|
||||
const myorder = toRef(props, 'order')
|
||||
const myorder = ref(<IOrder>{
|
||||
idapp: process.env.APP_ID,
|
||||
quantity: 1,
|
||||
idStorehouse: ''
|
||||
})
|
||||
|
||||
const myproduct = ref(<IProduct> {})
|
||||
const myproduct = ref(<IProduct>{})
|
||||
|
||||
const storeSelected = ref('')
|
||||
|
||||
@@ -75,7 +68,7 @@ export default defineComponent({
|
||||
myorder.value.quantity++
|
||||
}
|
||||
|
||||
function addtoCart() {
|
||||
function addtoCart(add: boolean) {
|
||||
|
||||
if (!userStore.isLogged) {
|
||||
tools.showNeutralNotif($q, t('ecomm.area_personale'))
|
||||
@@ -83,113 +76,127 @@ export default defineComponent({
|
||||
return false
|
||||
}
|
||||
|
||||
// Controlla se esiste già nel carrello il prodotto
|
||||
if (products.existProductInCart(myproduct.value._id)) {
|
||||
tools.showNegativeNotif($q, t('ecomm.already_in_cart'))
|
||||
} else {
|
||||
products.addToCart({ product: myproduct.value, order: props.order }).then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
if (myorder.value.quantity > 1)
|
||||
strprod = t('ecomm.prodotti')
|
||||
if (ris)
|
||||
tools.showPositiveNotif($q, t('ecomm.haveadded') + ' ' + myorder.value.quantity + ' ' + strprod + ' ' + t('ecomm.tocart'))
|
||||
else
|
||||
tools.showNegativeNotif($q, t('ecomm.error_cart'))
|
||||
})
|
||||
}
|
||||
products.addToCart({ product: myproduct.value, order: myorder.value, addqty: add }).then((ris) => {
|
||||
let strprod = t('ecomm.prodotto')
|
||||
if (myorder.value.quantity > 1 || myorder.value.quantity === 0)
|
||||
strprod = t('ecomm.prodotti')
|
||||
|
||||
let msg = ''
|
||||
if (ris === null)
|
||||
msg = t('ecomm.error_cart')
|
||||
else {
|
||||
if (myorder.value.quantity === 0) {
|
||||
msg = t('ecomm.prodotto_tolto')
|
||||
} else {
|
||||
msg = t('ecomm.prod_sul_carrello', { strprod, qty: myorder.value.quantity })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ris === null || myorder.value.quantity === 0)
|
||||
tools.showNotif($q, msg)
|
||||
else
|
||||
tools.showPositiveNotif($q, msg)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
function getnumstore() {
|
||||
if (myproduct.value.storehouses)
|
||||
return myproduct.value.storehouses.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
function getnumstore() {
|
||||
if (myproduct.value.storehouses)
|
||||
return myproduct.value.storehouses.length
|
||||
else
|
||||
return 0
|
||||
}
|
||||
|
||||
function getSingleStorehouse() {
|
||||
const mystore = myproduct.value.storehouses[0]
|
||||
if (mystore)
|
||||
return mystore.name + ' (' + mystore.city + ')'
|
||||
else
|
||||
return ''
|
||||
}
|
||||
function getSingleStorehouse() {
|
||||
const mystore = myproduct.value.storehouses[0]
|
||||
if (mystore)
|
||||
return mystore.name + ' (' + mystore.city + ')'
|
||||
else
|
||||
return ''
|
||||
}
|
||||
|
||||
function getStorehouses() {
|
||||
function getStorehouses() {
|
||||
|
||||
const myarr: any = []
|
||||
let ind = 1
|
||||
myproduct.value.storehouses.forEach((store) => {
|
||||
myarr.push(
|
||||
{
|
||||
id: ind,
|
||||
label: store.name + ' (' + store.city + ')',
|
||||
value: store._id
|
||||
})
|
||||
|
||||
ind++
|
||||
const myarr: any = []
|
||||
let ind = 1
|
||||
myproduct.value.storehouses.forEach((store) => {
|
||||
myarr.push(
|
||||
{
|
||||
id: ind,
|
||||
label: store.name + ' (' + store.city + ')',
|
||||
value: store._id
|
||||
})
|
||||
|
||||
// console.log('arraystore', myarr)
|
||||
return myarr
|
||||
}
|
||||
ind++
|
||||
})
|
||||
|
||||
function checkifCartDisable() {
|
||||
return !myorder.value.idStorehouse
|
||||
}
|
||||
// console.log('arraystore', myarr)
|
||||
return myarr
|
||||
}
|
||||
|
||||
watch(() => props.code, (newval, oldval) => {
|
||||
console.log('change code')
|
||||
load()
|
||||
})
|
||||
function checkifCartDisable() {
|
||||
return !myorder.value.idStorehouse
|
||||
}
|
||||
|
||||
watch(() => storeSelected.value, (newval, oldval) => {
|
||||
myorder.value.idStorehouse = newval
|
||||
})
|
||||
watch(() => props.code, (newval, oldval) => {
|
||||
console.log('change code')
|
||||
load()
|
||||
})
|
||||
|
||||
async 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
|
||||
}
|
||||
watch(() => storeSelected.value, (newval, oldval) => {
|
||||
myorder.value.idStorehouse = newval
|
||||
})
|
||||
|
||||
console.log('myproduct', myproduct, 'product', props.product)
|
||||
async 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
|
||||
}
|
||||
|
||||
if (!!myproduct.value) {
|
||||
if (myproduct.value.storehouses.length === 1) {
|
||||
myorder.value.idStorehouse = myproduct.value.storehouses[0]._id
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log('myproduct', myproduct, 'product', props.product)
|
||||
|
||||
function getmycardcl() {
|
||||
return (props.complete) ? 'my-card-big' : 'my-card'
|
||||
}
|
||||
|
||||
function getclimg() {
|
||||
return (props.complete) ? 'myimgtitle centermydiv' : 'centermydiv'
|
||||
}
|
||||
|
||||
load()
|
||||
|
||||
return {
|
||||
decqty,
|
||||
addqty,
|
||||
addtoCart,
|
||||
iconWhishlist,
|
||||
getmycardcl,
|
||||
getclimg,
|
||||
getnumstore,
|
||||
getSingleStorehouse,
|
||||
getStorehouses,
|
||||
checkifCartDisable,
|
||||
myproduct,
|
||||
myorder,
|
||||
tools,
|
||||
t,
|
||||
storeSelected,
|
||||
if (!!myproduct.value) {
|
||||
if (myproduct.value.storehouses.length === 1) {
|
||||
myorder.value.idStorehouse = myproduct.value.storehouses[0]._id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getmycardcl() {
|
||||
return (props.complete) ? 'my-card-big' : 'my-card'
|
||||
}
|
||||
|
||||
function getclimg() {
|
||||
return (props.complete) ? 'myimgtitle centermydiv' : 'centermydiv'
|
||||
}
|
||||
|
||||
function enableSubQty() {
|
||||
return myorder.value ? myorder.value.quantity > 0 : true
|
||||
}
|
||||
|
||||
load()
|
||||
|
||||
return {
|
||||
decqty,
|
||||
addqty,
|
||||
addtoCart,
|
||||
iconWhishlist,
|
||||
getmycardcl,
|
||||
getclimg,
|
||||
getnumstore,
|
||||
getSingleStorehouse,
|
||||
getStorehouses,
|
||||
checkifCartDisable,
|
||||
myproduct,
|
||||
myorder,
|
||||
tools,
|
||||
t,
|
||||
storeSelected,
|
||||
enableSubQty,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user