Corretto Ordini e visualizzazione dei Totali
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="numOrders === 0" style="text-align: center" class="text-grey">
|
||||
Il Carrello è Vuoto
|
||||
{{ $t('ecomm.carrello_vuoto') }}
|
||||
</div>
|
||||
<div v-else style="text-align: center">
|
||||
<q-btn
|
||||
|
||||
@@ -22,4 +22,9 @@
|
||||
padding-left: 10px;
|
||||
font-size: 1rem;
|
||||
color: grey;
|
||||
}
|
||||
}
|
||||
|
||||
.totali{
|
||||
font-weight: bold;
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<template>
|
||||
<div class="q-pa-md row items-start q-gutter-md">
|
||||
<q-card :class="getmycardcl()" v-if="!!myproduct" bordered>
|
||||
<q-img :src="`` + myproduct.img" :alt="myproduct.name" :class="getclimgproduct()"></q-img>
|
||||
<q-spinner v-if="!endload" color="primary" size="3em" :thickness="2" />
|
||||
|
||||
<q-card :class="getmycardcl()" v-if="!!myproduct && endload" bordered>
|
||||
<q-img
|
||||
:src="`` + myproduct.img"
|
||||
:alt="myproduct.name"
|
||||
:class="getclimgproduct()"
|
||||
></q-img>
|
||||
|
||||
<q-list>
|
||||
<q-item>
|
||||
@@ -28,7 +34,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</q-item>
|
||||
<q-item clickable>
|
||||
<q-item>
|
||||
<q-item-section avatar>
|
||||
<q-icon color="moneygreen" name="fas fa-euro-sign" />
|
||||
</q-item-section>
|
||||
@@ -44,7 +50,6 @@
|
||||
<span v-if="!!myproduct.after_price">{{
|
||||
myproduct.after_price
|
||||
}}</span>
|
||||
|
||||
</q-item-label>
|
||||
</q-item-section>
|
||||
</q-item>
|
||||
@@ -87,7 +92,10 @@
|
||||
<!--<q-rating v-model="myproduct.stars" :max="5" size="32px" readonly/>-->
|
||||
|
||||
<q-list>
|
||||
<q-item>
|
||||
<q-item
|
||||
:clickable="tools.isManager()"
|
||||
@click="tools.isManager() ? (openlistorders = true) : null"
|
||||
>
|
||||
<q-item-section avatar>
|
||||
<q-icon color="green" name="fas fa-store" />
|
||||
</q-item-section>
|
||||
@@ -103,8 +111,14 @@
|
||||
<span class="prod_qtywarn">
|
||||
{{ getQtyWarn() }}
|
||||
|
||||
<div v-if="tools.isManager() && myproduct.QuantitaOrdinateInAttesa > 0">Quantita Ordinate In Attesa : {{ myproduct.QuantitaOrdinateInAttesa }}</div>
|
||||
|
||||
<div
|
||||
v-if="
|
||||
tools.isManager() && myproduct.QuantitaOrdinateInAttesa > 0
|
||||
"
|
||||
>
|
||||
Quantita Ordinate In Attesa :
|
||||
{{ myproduct.QuantitaOrdinateInAttesa }}
|
||||
</div>
|
||||
</span>
|
||||
</q-item-label>
|
||||
<q-item-label> </q-item-label>
|
||||
@@ -112,14 +126,6 @@
|
||||
</q-item>
|
||||
</q-list>
|
||||
<div class="row q-mb-sm no-wrap items-center centeritems">
|
||||
<!--<q-btn
|
||||
round
|
||||
size="xs"
|
||||
text-color="grey"
|
||||
icon="fas fa-minus"
|
||||
@click="decqty()"
|
||||
></q-btn>-->
|
||||
|
||||
<q-btn
|
||||
icon="fas fa-cart-arrow-down"
|
||||
:color="enableSubQty() ? 'negative' : 'grey'"
|
||||
@@ -144,7 +150,6 @@
|
||||
</template>
|
||||
</q-field>
|
||||
|
||||
<!--<q-btn round size="xs" text-color="grey" icon="fas fa-plus" @click="addqty()"></q-btn>-->
|
||||
<q-btn
|
||||
icon-right="fas fa-cart-plus"
|
||||
color="positive"
|
||||
@@ -200,6 +205,77 @@
|
||||
-->
|
||||
</q-card-actions>
|
||||
</q-card>
|
||||
<q-dialog v-model="openlistorders">
|
||||
<q-card class="dialog_card">
|
||||
<q-toolbar class="bg-primary text-white">
|
||||
<q-toolbar-title>
|
||||
{{ t('ecomm.listaord') }} - {{ myproduct.name }}
|
||||
</q-toolbar-title>
|
||||
<q-btn flat round color="white" icon="close" v-close-popup></q-btn>
|
||||
</q-toolbar>
|
||||
<q-card-section class="q-pa-xs inset-shadow">
|
||||
<q-markup-table
|
||||
wrap-cells
|
||||
bordered
|
||||
separator="horizontal"
|
||||
class="listaev__table"
|
||||
>
|
||||
<thead>
|
||||
<th>Data</th>
|
||||
<th>Persona</th>
|
||||
<th>Stato</th>
|
||||
<th>Quantita</th>
|
||||
<th>Note</th>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="(ordcart, index) of arrordersCart"
|
||||
:key="index"
|
||||
class="listaev listaev__table"
|
||||
>
|
||||
<td class="text-center">
|
||||
<div>
|
||||
{{ func_tools.getDateTimeShortStr(ordcart.created_at) }}
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<strong
|
||||
>{{ ordcart.user.name }} {{ ordcart.user.surname }}</strong
|
||||
>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<strong
|
||||
>{{ shared_consts.getStatusStr(ordcart.status) }}</strong
|
||||
>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<div v-for="(singleord, index) in ordcart.items" :key="index">
|
||||
<span v-if="singleord.order.idProduct === myproduct._id">{{
|
||||
singleord.order.quantity
|
||||
}}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
{{ ordcart.note }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
<td class="text-center">
|
||||
Totali:
|
||||
<span class="totali">{{
|
||||
products.getSumQtyOrderProductInOrdersCart(myproduct._id)
|
||||
}}</span>
|
||||
</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</q-markup-table>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -54,8 +54,10 @@ export default defineComponent({
|
||||
addqty,
|
||||
subqty,
|
||||
order: props.order,
|
||||
}).then((newqty) => {
|
||||
order.value.quantity = newqty
|
||||
}).then((res: any) => {
|
||||
if (res.risult) {
|
||||
order.value.quantity = res.qty
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user