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
|
||||
|
||||
@@ -23,3 +23,8 @@
|
||||
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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { IUserFields } from './UserStore'
|
||||
|
||||
|
||||
export interface IProduct {
|
||||
_id?: any
|
||||
active?: boolean
|
||||
idProducer?: string,
|
||||
idProvider?: string,
|
||||
idStorehouses?: string[],
|
||||
producer: IProducer,
|
||||
producer?: IProducer,
|
||||
storehouses: IStorehouse[],
|
||||
provider: IProvider,
|
||||
provider?: IProvider,
|
||||
code?: string,
|
||||
name?: string,
|
||||
description?: string,
|
||||
@@ -16,13 +19,13 @@ export interface IProduct {
|
||||
after_price?: string,
|
||||
color?: string,
|
||||
size?: string,
|
||||
quantityAvailable: number,
|
||||
QuantitaOrdinateInAttesa: number,
|
||||
stockQty: number,
|
||||
quantityAvailable?: number,
|
||||
QuantitaOrdinateInAttesa?: number,
|
||||
stockQty?: number,
|
||||
canBeShipped?: boolean,
|
||||
canBeBuyOnline?: boolean,
|
||||
weight?: number,
|
||||
unit: number,
|
||||
unit?: number,
|
||||
stars?: number,
|
||||
date?: Date,
|
||||
icon?: string,
|
||||
@@ -135,13 +138,13 @@ export interface IOrderCart {
|
||||
idapp?: string
|
||||
numorder: number
|
||||
userId: string
|
||||
user: IUserFields,
|
||||
totalQty: number
|
||||
totalPrice: number
|
||||
department?: string
|
||||
items?: IBaseOrder[]
|
||||
nameSurname?: string
|
||||
status: number
|
||||
note?: string
|
||||
modify_at?: Date
|
||||
evaso: boolean
|
||||
date_evaso?: Date
|
||||
@@ -155,6 +158,8 @@ export interface IOrderCart {
|
||||
date_ricevuto?: Date
|
||||
completato: boolean
|
||||
date_completato?: Date
|
||||
created_at: Date
|
||||
note: string
|
||||
}
|
||||
|
||||
export interface IShareWithUs {
|
||||
|
||||
@@ -382,7 +382,6 @@ export default defineComponent({
|
||||
strris += ', "name":"' + tools.removeescape(tools.addslashes(rec[1])) + '"'
|
||||
strris += ', "price":"' + tools.removeescape(tools.addslashes(tools.convertPriceEurToValue(rec[2]))) + '"'
|
||||
strris += ', "stockQty":"' + tools.removeescape(tools.addslashes(rec[3])) + '"'
|
||||
strris += ', "quantityAvailable":"' + tools.removeescape(tools.addslashes(rec[3])) + '"'
|
||||
strris += ', "link":"' + tools.removeescape(tools.addslashes(rec[4])) + '"'
|
||||
strris += ', "perc_iva":"' + tools.removeescape(tools.addslashes(rec[5])) + '"'
|
||||
strris += ', "price_acquistato":"' + tools.removeescape(tools.addslashes(tools.convertPriceEurToValue(rec[6]))) + '"'
|
||||
|
||||
@@ -1610,6 +1610,18 @@ const msg_it = {
|
||||
seen: 'Visto da {num} utenti',
|
||||
attend: '{num} Partecipanti',
|
||||
},
|
||||
install: {
|
||||
Installazione_Sito: 'Installazione Sito',
|
||||
title_inst: 'Installa un nuovo Sito',
|
||||
submit: 'Installa Sito',
|
||||
name: 'Nome Sito (Esempio)',
|
||||
domain: 'Host: (esempio.it)',
|
||||
code: 'Codice Auth',
|
||||
username: 'Username Admin',
|
||||
password: 'Password Admin',
|
||||
idapp:'Id Applicazione',
|
||||
created: 'Sito Installato [IdApp = {idapp}] !',
|
||||
},
|
||||
ecomm: {
|
||||
already_in_cart: 'Questo prodotto è stato già aggiunto al Carrello',
|
||||
area_personale: 'Devi prima accedere alla tua Area Personale',
|
||||
@@ -1632,19 +1644,12 @@ const msg_it = {
|
||||
spedito: 'Ordine Spedito',
|
||||
completed: 'Ordine Completato',
|
||||
ricevuto: 'Prodotti Ricevuti',
|
||||
listaord: 'Lista Ordini',
|
||||
carrello_vuoto:'Il Carrello è Vuoto',
|
||||
note:'Scrivi qui per eventuali note o chiarimenti:',
|
||||
totale: 'Totale',
|
||||
carrello: 'Carrello',
|
||||
},
|
||||
install: {
|
||||
Installazione_Sito: 'Installazione Sito',
|
||||
title_inst: 'Installa un nuovo Sito',
|
||||
submit: 'Installa Sito',
|
||||
name: 'Nome Sito (Esempio)',
|
||||
domain: 'Host: (esempio.it)',
|
||||
code: 'Codice Auth',
|
||||
username: 'Username Admin',
|
||||
password: 'Password Admin',
|
||||
idapp:'Id Applicazione',
|
||||
created: 'Sito Installato [IdApp = {idapp}] !',
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@@ -24,6 +24,29 @@ export const useProducts = defineStore('Products', {
|
||||
return state.products
|
||||
},
|
||||
|
||||
updateDataProduct: (state: IProductsState) => (res: any) => {
|
||||
if (res && res.data.product) {
|
||||
// Update product from server
|
||||
const indelem = state.products.findIndex((prod: IProduct) => prod._id === res.data.product._id)
|
||||
if (indelem >= 0) {
|
||||
state.products[indelem] = { ...res.data.product }
|
||||
}
|
||||
}
|
||||
if (res && res.data.orders) {
|
||||
state.orders = res.data.orders
|
||||
}
|
||||
|
||||
if (res && res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
state.cart = res.data.cart
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
getProduct: (state: IProductsState) => (code: string): IProduct => {
|
||||
const prod = state.products.find((prod: IProduct) => prod.code === code)
|
||||
return prod ? prod : { storehouses: [] }
|
||||
},
|
||||
|
||||
getCart: (state: IProductsState) => (): ICart => {
|
||||
return state.cart
|
||||
},
|
||||
@@ -69,6 +92,55 @@ export const useProducts = defineStore('Products', {
|
||||
return null
|
||||
},
|
||||
|
||||
getOrderProductInOrdersCart: (state: IProductsState) => (idordercart: string, idproduct: string): IOrder | null => {
|
||||
// console.log('.cart.items', this.cart.items)
|
||||
if (state.orders) {
|
||||
const orderscart = state.orders.find((rec: IOrderCart) => rec._id === idordercart)
|
||||
if (orderscart) {
|
||||
const ris = orderscart.items!.find((item: IBaseOrder) => item.order.idProduct === idproduct)
|
||||
return ris ? ris.order : null
|
||||
}
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
getSumQtyOrderProductInOrdersCart: (state: IProductsState) => (idproduct: string): number => {
|
||||
let totalQuantity = 0;
|
||||
if (state.orders) {
|
||||
const orderscart = state.orders
|
||||
if (orderscart) {
|
||||
for (const myord of orderscart) {
|
||||
myord.items?.forEach((item: IBaseOrder) => {
|
||||
if (item.order) {
|
||||
if (item.order.idProduct === idproduct) {
|
||||
totalQuantity += item.order.quantity || 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalQuantity
|
||||
},
|
||||
|
||||
getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => {
|
||||
// console.log('.cart.items', this.cart.items)
|
||||
try {
|
||||
if (state.orders) {
|
||||
const ris = state.orders.filter((ordercart: IOrderCart) => {
|
||||
return ordercart.items!.some(item => {
|
||||
if (item.order)
|
||||
return item.order.idProduct === idproduct
|
||||
})
|
||||
})
|
||||
return ris ? ris : []
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Err', e)
|
||||
}
|
||||
return []
|
||||
},
|
||||
|
||||
getRecordEmpty: (state: IProductsState) => (): IProduct => {
|
||||
|
||||
const tomorrow = tools.getDateNow()
|
||||
@@ -165,17 +237,21 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/products', 'POST', null)
|
||||
ris = await Api.SendReq('/products', 'POST', { userId: userStore.my._id })
|
||||
.then((res) => {
|
||||
if (res.data.products) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
if (res.data.products) {
|
||||
this.products = res.data.products
|
||||
} else {
|
||||
this.products = []
|
||||
}
|
||||
|
||||
// console.log('ARRAY PRODUCTS = ', this.products)
|
||||
if (res.data.orders) {
|
||||
this.orders = res.data.orders
|
||||
} else {
|
||||
this.orders = []
|
||||
}
|
||||
|
||||
if (process.env.DEBUG === '1') {
|
||||
// console.log('dbLoad', 'this.products', this.products)
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -212,6 +288,7 @@ export const useProducts = defineStore('Products', {
|
||||
.then((res) => {
|
||||
console.log('product', res.data.product)
|
||||
if (res.data.product) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.updateDataProduct(res)
|
||||
return res.data.product
|
||||
} else {
|
||||
return null
|
||||
@@ -249,6 +326,8 @@ export const useProducts = defineStore('Products', {
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -261,17 +340,14 @@ export const useProducts = defineStore('Products', {
|
||||
return ris
|
||||
},
|
||||
|
||||
|
||||
async removeFromCart({ order }: { order: IOrder }) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
return Api.SendReq('/cart/' + userStore.my._id, 'DELETE', { orderId: order._id })
|
||||
.then((res) => {
|
||||
if (res.data.cart) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories)
|
||||
this.cart = res.data.cart
|
||||
} else {
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res
|
||||
})
|
||||
@@ -308,8 +384,11 @@ export const useProducts = defineStore('Products', {
|
||||
addqty,
|
||||
subqty: !addqty,
|
||||
order: ordcart,
|
||||
}).then((newqty) => {
|
||||
order.quantity = newqty
|
||||
}).then((res: any) => {
|
||||
if (res && res.risult) {
|
||||
order.quantity = res.qty
|
||||
}
|
||||
return res;
|
||||
})
|
||||
}
|
||||
} else {
|
||||
@@ -333,8 +412,9 @@ export const useProducts = defineStore('Products', {
|
||||
} else {
|
||||
this.cart = { items: [], totalPrice: 0, totalQty: 0, userId: '' }
|
||||
}
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res
|
||||
return { risult: !!res, qty: order.quantity }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addToCart', error)
|
||||
@@ -361,15 +441,9 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id, 'POST', { addqty, subqty, order })
|
||||
.then((res) => {
|
||||
this.cart = res.data.cart
|
||||
if (!!res.data.qty) {
|
||||
// const ind = this.cart.items.findIndex((rec) => rec.order._id === order._id)
|
||||
// this.cart.items[ind].order.quantity = res.data.qty
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res.data.qty
|
||||
}
|
||||
|
||||
return 0
|
||||
return { risult: !!res, qty: res.data.qty }
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log('error addSubQtyToItem', error)
|
||||
@@ -382,7 +456,7 @@ export const useProducts = defineStore('Products', {
|
||||
return ris
|
||||
},
|
||||
|
||||
async CreateOrdersCart({ cart_id, status }: { cart_id: string, status: number }) {
|
||||
async CreateOrdersCart({ cart_id, status, note }: { cart_id: string, status: number, note: string }) {
|
||||
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
@@ -392,15 +466,15 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
let ris = null
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/createorderscart', 'POST', { cart_id, status })
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/createorderscart', 'POST', { cart_id, status, note })
|
||||
.then((res) => {
|
||||
|
||||
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
// Cancella il Carrello, ho creato l'ordine !
|
||||
this.cart = {}
|
||||
}
|
||||
if (res.data.orders)
|
||||
this.orders = res.data.orders
|
||||
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res.data.recOrderCart
|
||||
})
|
||||
@@ -429,8 +503,7 @@ export const useProducts = defineStore('Products', {
|
||||
if (res.data.status === shared_consts.OrderStatus.CHECKOUT_SENT) {
|
||||
this.cart = {}
|
||||
}
|
||||
if (res.data.orders)
|
||||
this.orders = res.data.orders
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res.data.status
|
||||
})
|
||||
@@ -455,8 +528,8 @@ export const useProducts = defineStore('Products', {
|
||||
|
||||
ris = await Api.SendReq('/cart/' + userStore.my._id + '/ordercartstatus', 'POST', { order_id, status })
|
||||
.then((res) => {
|
||||
if (res.data.orders)
|
||||
this.orders = res.data.orders
|
||||
|
||||
this.updateDataProduct(res)
|
||||
|
||||
return res.data.status
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="q-pa-md row items-start q-gutter-md" v-for="(product, index) in getProducts()" :key="index">
|
||||
<CProductCard :product="product"/>
|
||||
<CProductCard :code="product.code"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defineComponent, onMounted, ref } from 'vue'
|
||||
import { defineComponent, onMounted, ref, computed } from 'vue'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useRouter } from 'vue-router'
|
||||
@@ -31,8 +31,15 @@ export default defineComponent({
|
||||
const myrec = ref(<any[string]>[])
|
||||
const oldrec = ref(<any[string]>[])
|
||||
const note = ref('')
|
||||
const endload = ref(false)
|
||||
const recOrderCart = ref(<IOrderCart>{})
|
||||
const statusnow = ref(shared_consts.OrderStatus.NONE)
|
||||
|
||||
const statusnow = computed(() => (): number => {
|
||||
if (recOrderCart.value) {
|
||||
return recOrderCart.value.status
|
||||
}
|
||||
return 0
|
||||
})
|
||||
|
||||
function mounted() {
|
||||
// Inizializza
|
||||
@@ -98,10 +105,12 @@ export default defineComponent({
|
||||
note.value = mycart.value.note!
|
||||
|
||||
if (mycart.value) {
|
||||
recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status: 0 })
|
||||
recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status: 0, note: note.value })
|
||||
}
|
||||
|
||||
console.log('myrec', myrec.value)
|
||||
|
||||
endload.value = true
|
||||
}
|
||||
|
||||
function CanBeShipped() {
|
||||
@@ -150,11 +159,11 @@ export default defineComponent({
|
||||
}).onOk(async () => {
|
||||
const status = shared_consts.OrderStatus.CHECKOUT_SENT
|
||||
|
||||
const myordercart = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status })
|
||||
recOrderCart.value = await productStore.CreateOrdersCart({ cart_id: mycart.value._id, status, note: note.value })
|
||||
|
||||
statusnow.value = myordercart ? myordercart.status : 0
|
||||
// statusnow.value = myordercart ? myordercart.status : 0
|
||||
|
||||
if (statusnow.value === status) {
|
||||
if (recOrderCart.value.status === status) {
|
||||
tools.showPositiveNotif($q, t('ecomm.ord_confirmed'))
|
||||
setTimeout(() => {
|
||||
$router.push('/orderinfo')
|
||||
@@ -187,6 +196,7 @@ export default defineComponent({
|
||||
myTotalQty,
|
||||
recOrderCart,
|
||||
mycart,
|
||||
endload,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<template>
|
||||
<q-page v-if="recOrderCart">
|
||||
<CTitleBanner title="Carrello"></CTitleBanner>
|
||||
<div class="panel">
|
||||
<q-page>
|
||||
<CTitleBanner :title="$t('ecomm.carrello')"></CTitleBanner>
|
||||
{{ tools.getstrDateTimeShort(mycart.modify_at) }}
|
||||
<q-spinner v-if="!endload" color="primary" size="3em" :thickness="2" />
|
||||
<div v-if="endload">
|
||||
<div v-if="recOrderCart" class="panel">
|
||||
<div>
|
||||
<div class="container">
|
||||
<div
|
||||
@@ -14,7 +17,7 @@
|
||||
</div>
|
||||
<q-separator></q-separator>
|
||||
<div class="col-6 q-mr-sm" style="text-align: right">
|
||||
<span class="text-grey q-mr-xs">Totale:</span>
|
||||
<span class="text-grey q-mr-xs">{{ $t('ecomm.totale') }}:</span>
|
||||
<span class="text-subtitle1 q-mr-sm">€ {{ myTotalPrice() }}</span>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +25,7 @@
|
||||
v-if="getNumItems() > 0"
|
||||
v-model="note"
|
||||
style="max-width: 400px"
|
||||
label="Scrivi qui per eventuali note o chiarimenti:"
|
||||
:label="$t('ecomm.note')"
|
||||
filled
|
||||
dense
|
||||
debounce="1000"
|
||||
@@ -34,9 +37,14 @@
|
||||
<br />
|
||||
</div>
|
||||
|
||||
recOrderCart.status: {{ recOrderCart.status }}
|
||||
|
||||
<div class="text-center">
|
||||
<q-btn
|
||||
v-if="recOrderCart && recOrderCart.status < shared_consts.OrderStatus.CHECKOUT_SENT"
|
||||
v-if="
|
||||
recOrderCart &&
|
||||
recOrderCart.status < shared_consts.OrderStatus.CHECKOUT_SENT
|
||||
"
|
||||
rounded
|
||||
icon="fas fa-shopping-cart"
|
||||
color="green"
|
||||
@@ -47,6 +55,10 @@
|
||||
></q-btn>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else style="text-align: center" class="text-grey">
|
||||
{{ $t('ecomm.carrello_vuoto') }}
|
||||
</div>
|
||||
</div>
|
||||
</q-page>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -24,3 +24,8 @@ $heightBtn: 100%;
|
||||
font-weight: bold;
|
||||
color: green;
|
||||
}
|
||||
|
||||
.note {
|
||||
font-style: italic;
|
||||
color:blue;
|
||||
}
|
||||
@@ -33,6 +33,7 @@ export default defineComponent({
|
||||
|
||||
const conferma_carrello = ref(false)
|
||||
const conferma_ordine = ref(false)
|
||||
const endload = ref(false)
|
||||
|
||||
const taborders = ref(shared_consts.OrderStat.IN_CORSO.value)
|
||||
const statusnow = ref(0)
|
||||
@@ -164,13 +165,11 @@ export default defineComponent({
|
||||
arrnumstatus.value[status] = allorders.filter((rec) => (rec.status === status)).reduce((sum, item) => sum + 1, 0)
|
||||
}
|
||||
|
||||
selectfirstavailable()
|
||||
|
||||
}
|
||||
|
||||
function mounted() {
|
||||
|
||||
updateorders()
|
||||
|
||||
taborders.value = -1
|
||||
function selectfirstavailable() {
|
||||
|
||||
Object.keys(arrnumstatus.value).forEach((stat: any) => {
|
||||
if (arrnumstatus.value[stat] > 0) {
|
||||
@@ -178,6 +177,15 @@ export default defineComponent({
|
||||
taborders.value = parseInt(stat)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function mounted() {
|
||||
|
||||
await productStore.loadProducts()
|
||||
|
||||
taborders.value = -1
|
||||
|
||||
updateorders()
|
||||
|
||||
if (taborders.value === -1)
|
||||
taborders.value = shared_consts.OrderStat.IN_CORSO.value
|
||||
@@ -186,6 +194,8 @@ export default defineComponent({
|
||||
if (tools.isManager()) {
|
||||
columns.value = [...columns_Admin.value]
|
||||
}
|
||||
|
||||
endload.value = true
|
||||
}
|
||||
|
||||
function CanBeShipped() {
|
||||
@@ -272,6 +282,7 @@ export default defineComponent({
|
||||
getAllOrdersCart,
|
||||
updateorders,
|
||||
getCols,
|
||||
endload,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<template>
|
||||
<q-page>
|
||||
<CTitleBanner title="Ordini"></CTitleBanner>
|
||||
<div class="panel">
|
||||
<q-spinner v-if="!endload" color="primary" size="3em" :thickness="2" />
|
||||
<div v-if="endload" class="panel">
|
||||
<q-tabs v-model="taborders" inline-label class="text-blue">
|
||||
<span v-for="(stat, index) of shared_consts.OrderStat" :key="index">
|
||||
<q-tab
|
||||
@@ -39,7 +40,7 @@
|
||||
v-for="(item, index) of props.row.items"
|
||||
:key="index"
|
||||
>
|
||||
<div v-if="!!item.order.product">
|
||||
<div v-if="!!item.order && item.order.product">
|
||||
{{ item.order.product.name }} ({{
|
||||
item.order.quantity
|
||||
}})<br />
|
||||
@@ -82,12 +83,15 @@
|
||||
</q-td>
|
||||
<q-td key="items" :props="props">
|
||||
<div v-for="(item, index) of props.row.items" :key="index">
|
||||
<div v-if="!!item.order.product">
|
||||
<div v-if="!!item.order && item.order.product">
|
||||
{{ item.order.product.name }} ({{
|
||||
item.order.quantity
|
||||
}})<br />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="props.row.note" class="note">
|
||||
Note: {{ props.row.note }}
|
||||
</div>
|
||||
</q-td>
|
||||
<q-td key="totalPrice" :props="props">
|
||||
{{ props.row.totalPrice }} €
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="q-pa-md row items-start q-gutter-md" v-for="(product, index) in getProducts()" :key="index">
|
||||
<CProductCard :product="product" :complete="false"/>
|
||||
<CProductCard :code="product.code" :complete="false"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user