avanti...
This commit is contained in:
@@ -1,178 +1,182 @@
|
||||
import Vue from 'vue'
|
||||
import { Component, Watch } from 'vue-property-decorator'
|
||||
import { defineComponent, onMounted, ref } from 'vue'
|
||||
import { tools } from '@store/Modules/tools'
|
||||
import { useUserStore } from '@store/UserStore'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useGlobalStore } from '@store/globalStore'
|
||||
import { useProducts } from '@store/Products'
|
||||
import { useI18n } from '@/boot/i18n'
|
||||
import { toolsext } from '@store/Modules/toolsext'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { costanti } from '@costanti'
|
||||
import { ICart, IOrderCart, IShareWithUs } from '@src/model/Products'
|
||||
|
||||
import { SingleProject } from '../../../components/projects/SingleProject/index'
|
||||
import { CTodo } from '../../../components/todos/CTodo'
|
||||
|
||||
import { CProgress } from '../../../components/CProgress'
|
||||
import { CDate } from '../../../components/CDate'
|
||||
import { Action } from 'vuex'
|
||||
import Products from '@src/store/Modules/Products'
|
||||
import { CSingleCart } from '../../../components/CSingleCart'
|
||||
import { CTitleBanner } from '@components'
|
||||
import { tools } from '@src/store/Modules/tools'
|
||||
import { ICart } from '@src/model'
|
||||
import MixinBase from '@src/mixins/mixin-base'
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
|
||||
const namespace: string = 'Products'
|
||||
import { CSingleCart } from '../../../components/CSingleCart'
|
||||
import { CTitleBanner } from '@components'
|
||||
|
||||
@Component({
|
||||
export default defineComponent({
|
||||
name: 'checkOut',
|
||||
components: { SingleProject, CProgress, CTodo, CDate, CSingleCart, CTitleBanner },
|
||||
filters: {
|
||||
capitalize(value) {
|
||||
if (!value) {
|
||||
return ''
|
||||
components: { CSingleCart, CTitleBanner },
|
||||
props: {},
|
||||
setup() {
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const productStore = useProducts()
|
||||
const $router = useRouter()
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n();
|
||||
|
||||
const mycart = ref(<ICart>{})
|
||||
const myrec = ref(<any[string]>[])
|
||||
const oldrec = ref(<any[string]>[])
|
||||
const note = ref('')
|
||||
const statusnow = ref(shared_consts.OrderStatus.NONE)
|
||||
|
||||
function mounted() {
|
||||
// Inizializza
|
||||
load()
|
||||
}
|
||||
value = value.toString()
|
||||
return value.charAt(0).toUpperCase() + value.slice(1)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export default class CheckOut extends MixinBase {
|
||||
public $q: any
|
||||
public mycart: ICart = {}
|
||||
public myrec: any[]
|
||||
public note: string = ''
|
||||
public statusnow: number = shared_consts.OrderStatus.NONE
|
||||
|
||||
public conferma_carrello: boolean = false
|
||||
public conferma_ordine: boolean = false
|
||||
|
||||
/*public $refs: {
|
||||
singleproject: SingleProject[],
|
||||
ctodo: CTodo
|
||||
}*/
|
||||
|
||||
get getItemsCart() {
|
||||
const cart = Products.getters.getCart()
|
||||
function getItemsCart() {
|
||||
const cart = productStore.getCart()
|
||||
return cart.items || null
|
||||
}
|
||||
|
||||
get getNumItems() {
|
||||
const cart = Products.getters.getCart()
|
||||
function getNumItems() {
|
||||
const cart = productStore.getCart()
|
||||
if (!!cart.items)
|
||||
return cart.items.length || 0
|
||||
else
|
||||
return 0
|
||||
}
|
||||
|
||||
get getCart() {
|
||||
return Products.getters.getCart()
|
||||
function getCart() {
|
||||
return productStore.getCart()
|
||||
}
|
||||
|
||||
get getNote() {
|
||||
const cart = Products.getters.getCart()
|
||||
function getNote() {
|
||||
const cart = productStore.getCart()
|
||||
return cart.note
|
||||
}
|
||||
|
||||
public change_field(fieldname) {
|
||||
if (this.myrec[fieldname] !== this[fieldname]) {
|
||||
this.myrec[fieldname] = this[fieldname]
|
||||
function change_field(fieldname: string) {
|
||||
if (myrec.value[fieldname] !== oldrec.value[fieldname]) {
|
||||
myrec.value[fieldname] = oldrec.value[fieldname]
|
||||
|
||||
const mydata = {
|
||||
[fieldname]: this.myrec[fieldname]
|
||||
[fieldname]: myrec.value[fieldname]
|
||||
}
|
||||
|
||||
const aggiorna = fieldname !== 'status'
|
||||
tools.saveFieldToServer(this, 'carts', this.mycart._id, mydata, aggiorna)
|
||||
tools.saveFieldToServer($q, 'carts', mycart.value._id, mydata, aggiorna)
|
||||
myrec.value = oldrec.value
|
||||
}
|
||||
}
|
||||
|
||||
get myTotalPrice() {
|
||||
if (Products.state.cart && Products.state.cart.totalPrice) {
|
||||
return Products.state.cart.totalPrice.toFixed(2)
|
||||
function myTotalPrice() {
|
||||
if (productStore.cart && productStore.cart.totalPrice) {
|
||||
return productStore.cart.totalPrice.toFixed(2)
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
get myTotalQty() {
|
||||
if (Products.state.cart) {
|
||||
return Products.state.cart.totalQty
|
||||
function myTotalQty() {
|
||||
if (productStore.cart) {
|
||||
return productStore.cart.totalQty
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
public async mounted() {
|
||||
// Products.actions.loadCart()
|
||||
this.load()
|
||||
async function load() {
|
||||
mycart.value = getCart()
|
||||
myrec.value = Object.keys(mycart)
|
||||
note.value = mycart.value.note!
|
||||
|
||||
if (mycart.value)
|
||||
statusnow.value = await productStore.UpdateStatusCart({ cart_id: mycart.value._id, status: 0 })
|
||||
|
||||
console.log('myrec', myrec.value)
|
||||
}
|
||||
|
||||
public async load() {
|
||||
this.mycart = this.getCart
|
||||
this.myrec = Object.keys(this.mycart)
|
||||
this.note = this.mycart.note
|
||||
|
||||
if (this.mycart)
|
||||
this.statusnow = await Products.actions.UpdateStatusCart({ cart_id: this.mycart._id, status })
|
||||
|
||||
console.log('myrec', this.myrec)
|
||||
function CanBeShipped() {
|
||||
return productStore.cart.items ? productStore.cart.items.filter((rec: any) => rec.order.product.canBeShipped).length : false
|
||||
}
|
||||
|
||||
public CanBeShipped() {
|
||||
return Products.state.cart.items.filter((rec) => rec.order.product.canBeShipped).length
|
||||
function CanBeBuyOnline() {
|
||||
return productStore.cart.items ? productStore.cart.items.filter((rec: any) => rec.order.product.canBeBuyOnline).length : false
|
||||
}
|
||||
|
||||
public CanBeBuyOnline() {
|
||||
return Products.state.cart.items.filter((rec) => rec.order.product.canBeBuyOnline).length
|
||||
}
|
||||
|
||||
get getnumsteps() {
|
||||
function getnumsteps() {
|
||||
let numsteps = 1
|
||||
|
||||
if (this.CanBeShipped())
|
||||
if (CanBeShipped())
|
||||
numsteps++
|
||||
if (this.CanBeBuyOnline())
|
||||
if (CanBeBuyOnline())
|
||||
numsteps++
|
||||
|
||||
return numsteps
|
||||
}
|
||||
|
||||
public docheckout() {
|
||||
function docheckout() {
|
||||
|
||||
// Può essere spedito?
|
||||
|
||||
if (this.CanBeShipped()) {
|
||||
if (CanBeShipped()) {
|
||||
// mostra form di spedizione
|
||||
}
|
||||
|
||||
if (this.CanBeBuyOnline()) {
|
||||
if (CanBeBuyOnline()) {
|
||||
// mostra form di acquisto Online
|
||||
}
|
||||
}
|
||||
|
||||
get nextstep() {
|
||||
return 0
|
||||
}
|
||||
|
||||
public completeOrder() {
|
||||
this.$q.dialog({
|
||||
message: 'Confermare l\'ordine di acquisto di ' + this.myTotalQty + ' prodotti ?',
|
||||
function completeOrder() {
|
||||
$q.dialog({
|
||||
message: 'Confermare l\'ordine di acquisto di ' + myTotalQty() + ' prodotti ?',
|
||||
ok: {
|
||||
label: this.$t('dialog.yes'),
|
||||
label: t('dialog.yes'),
|
||||
push: true
|
||||
},
|
||||
cancel: {
|
||||
label: this.$t('dialog.cancel')
|
||||
label: t('dialog.cancel')
|
||||
},
|
||||
title: 'Ordine'
|
||||
}).onOk(async () => {
|
||||
const status = shared_consts.OrderStatus.CHECKOUT_SENT
|
||||
this.statusnow = await Products.actions.UpdateStatusCart({ cart_id: this.mycart._id, status })
|
||||
statusnow.value = await productStore.UpdateStatusCart({ cart_id: mycart.value._id, status })
|
||||
|
||||
if (this.statusnow === status) {
|
||||
tools.showPositiveNotif(this.$q, 'Ordine Confermato')
|
||||
if (statusnow.value === status) {
|
||||
tools.showPositiveNotif($q, 'Ordine Confermato')
|
||||
setTimeout(() => {
|
||||
this.$router.push('/orderinfo')
|
||||
$router.push('/orderinfo')
|
||||
}, 2000)
|
||||
}
|
||||
// this.change_field('status')
|
||||
// this.change_field('status')
|
||||
// change_field('status')
|
||||
// change_field('status')
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
onMounted(mounted)
|
||||
|
||||
return {
|
||||
userStore,
|
||||
costanti,
|
||||
tools,
|
||||
toolsext,
|
||||
completeOrder,
|
||||
getNumItems,
|
||||
myTotalPrice,
|
||||
getItemsCart,
|
||||
getNote,
|
||||
change_field,
|
||||
note,
|
||||
statusnow,
|
||||
shared_consts,
|
||||
myTotalQty,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div class="panel">
|
||||
<div>
|
||||
<div class="container">
|
||||
<div class="q-pa-sm col items-start q-gutter-xs" v-for="(itemorder, index) in getItemsCart" :key="index">
|
||||
<div class="q-pa-sm col items-start q-gutter-xs" v-for="(itemorder, index) in getItemsCart()" :key="index">
|
||||
|
||||
<CSingleCart :order="itemorder.order" :showall="true"/>
|
||||
</div>
|
||||
@@ -15,7 +15,7 @@
|
||||
class="text-subtitle1 q-mr-sm ">€ {{ myTotalPrice }}</span>
|
||||
</div>
|
||||
|
||||
<q-input v-if="getNumItems > 0" v-model="note" style="max-width: 400px;" label="Scrivi qui per eventuali note o chiarimenti:"
|
||||
<q-input v-if="getNumItems() > 0" v-model="note" style="max-width: 400px;" label="Scrivi qui per eventuali note o chiarimenti:"
|
||||
filled dense
|
||||
debounce="1000"
|
||||
autogrow
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<q-stepper-navigation>
|
||||
<q-btn v-if="statusnow < shared_consts.OrderStatus.CHECKOUT_SENT" rounded icon="fas fa-shopping-cart" color="green" label="Completa l'Ordine" class="q-mb-sm"
|
||||
:disabled="myTotalQty < 1"
|
||||
:disabled="myTotalQty() < 1"
|
||||
@click="completeOrder"></q-btn>
|
||||
</q-stepper-navigation>
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import { useI18n } from '@/boot/i18n'
|
||||
import { toolsext } from '@store/Modules/toolsext'
|
||||
import { useQuasar } from 'quasar'
|
||||
import { costanti } from '@costanti'
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
// import MixinBase from '@src/mixins/mixin-base'
|
||||
|
||||
|
||||
export default defineComponent({
|
||||
@@ -22,6 +24,8 @@ export default defineComponent({
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n();
|
||||
|
||||
// const { setValDb, getValDb } = MixinBase()
|
||||
|
||||
|
||||
function mounted() {
|
||||
// Inizializza
|
||||
@@ -35,6 +39,7 @@ export default defineComponent({
|
||||
costanti,
|
||||
tools,
|
||||
toolsext,
|
||||
shared_consts,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user