345 lines
8.0 KiB
TypeScript
Executable File
345 lines
8.0 KiB
TypeScript
Executable File
import { defineComponent, onMounted, ref, watch } 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 { shared_consts } from '@src/common/shared_vuejs'
|
|
// import MixinBase from '@src/mixins/mixin-base'
|
|
|
|
import { CSingleCart } from '../../../components/CSingleCart'
|
|
import { CTitleBanner } from '@components'
|
|
import { ICart, IOrder, IOrderCart } from '@src/model'
|
|
|
|
export default defineComponent({
|
|
name: 'OrderInfo',
|
|
components: { CSingleCart, CTitleBanner },
|
|
props: {},
|
|
setup() {
|
|
const userStore = useUserStore()
|
|
const globalStore = useGlobalStore()
|
|
const productStore = useProducts()
|
|
const $router = useRouter()
|
|
const $q = useQuasar()
|
|
const { t } = useI18n()
|
|
|
|
const myorderscart = ref(<IOrderCart[] | undefined>[])
|
|
const myarrrec = ref(<any>{})
|
|
const myoldrec = ref(<any>{})
|
|
|
|
const cosa = ref(0)
|
|
|
|
const initialPagination = ref({
|
|
sortBy: 'desc',
|
|
descending: false,
|
|
rowsPerPage: 10,
|
|
// rowsNumber: xx if getting data from a server
|
|
})
|
|
|
|
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)
|
|
const arrnumstatus = ref(<any[]>[])
|
|
const columns = ref(<any>[
|
|
{
|
|
name: 'numorder',
|
|
required: true,
|
|
align: 'left',
|
|
label: 'Ordine N.',
|
|
field: 'numorder',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'created_at',
|
|
required: true,
|
|
align: 'center',
|
|
label: 'Effettuato il',
|
|
field: 'created_at',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'items',
|
|
required: true,
|
|
label: '',
|
|
field: 'items',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'totalPrice',
|
|
required: true,
|
|
label: 'Totale',
|
|
field: 'totalPrice',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'status',
|
|
align: 'center',
|
|
required: true,
|
|
label: 'Stato',
|
|
field: 'status',
|
|
sortable: true
|
|
}
|
|
])
|
|
|
|
const columns_Admin = ref(<any>[
|
|
{
|
|
name: 'numorder',
|
|
required: true,
|
|
align: 'left',
|
|
label: 'Ordine N.',
|
|
field: 'numorder',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'nameSurname',
|
|
required: true,
|
|
align: 'left',
|
|
label: 'Nome',
|
|
field: 'nameSurname',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'created_at',
|
|
required: true,
|
|
align: 'center',
|
|
label: 'Effettuato il',
|
|
field: 'created_at',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'items',
|
|
required: true,
|
|
label: 'Articoli',
|
|
field: 'items',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'totalPrice',
|
|
required: true,
|
|
label: 'Totale',
|
|
field: 'totalPrice',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'status',
|
|
align: 'center',
|
|
required: true,
|
|
label: 'Stato',
|
|
field: 'status',
|
|
sortable: true
|
|
},
|
|
{
|
|
name: 'comandi',
|
|
align: 'center',
|
|
required: false,
|
|
label: 'Comandi',
|
|
field: 'comandi',
|
|
sortable: false
|
|
}
|
|
])
|
|
|
|
watch(() => cosa.value, (newval, oldval) => {
|
|
|
|
})
|
|
|
|
// const { setValDb, getValDb } = MixinBase()
|
|
|
|
function getCols(props: any) {
|
|
return props.cols.filter((col: any) => col.name !== 'desc')
|
|
}
|
|
|
|
function getOrdersCart(): IOrderCart[] | undefined {
|
|
const hasGasordine: any = (cosa.value === shared_consts.PROD.TUTTI) ? undefined : (cosa.value === shared_consts.PROD.GAS)
|
|
const ris = productStore.getOrdersCart(taborders.value, hasGasordine)
|
|
|
|
return ris
|
|
}
|
|
|
|
function getOrdersCartWithTotals(): any[] {
|
|
const orderscart = getOrdersCart();
|
|
|
|
if (orderscart) {
|
|
// Calculate totals
|
|
const totals = {
|
|
created_at: new Date(),
|
|
items: null,
|
|
user:{
|
|
name: 'TOTALI',
|
|
surname: '',
|
|
},
|
|
status: 0,
|
|
// Add other properties as needed
|
|
totalPrice: orderscart.reduce((total: number, rec: any) => total + rec.totalPrice, 0),
|
|
};
|
|
|
|
let rowsWithTotals: any = [...orderscart];
|
|
|
|
if (tools.isManager()) {
|
|
// Combine orders and totals
|
|
rowsWithTotals.push(totals);
|
|
}
|
|
|
|
return rowsWithTotals;
|
|
} else {
|
|
return []
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function getAllOrdersCart() {
|
|
return productStore.getOrdersAllCart()
|
|
}
|
|
|
|
function updateorders() {
|
|
myorderscart.value = getOrdersCart()
|
|
if (myorderscart.value) {
|
|
for (const ordercart of myorderscart.value) {
|
|
myarrrec.value[ordercart._id] = Object.keys(ordercart)
|
|
}
|
|
}
|
|
|
|
const allorders = getAllOrdersCart()
|
|
for (const status of [2, 3, 4, 5, 6, 7, 8, 10]) {
|
|
arrnumstatus.value[status] = allorders.filter((rec) => (rec.status === status)).reduce((sum, item) => sum + 1, 0)
|
|
}
|
|
|
|
selectfirstavailable()
|
|
|
|
}
|
|
|
|
function selectfirstavailable() {
|
|
|
|
Object.keys(arrnumstatus.value).forEach((stat: any) => {
|
|
if (arrnumstatus.value[stat] > 0) {
|
|
if (taborders.value === -1)
|
|
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
|
|
|
|
|
|
if (tools.isManager()) {
|
|
columns.value = [...columns_Admin.value]
|
|
}
|
|
|
|
endload.value = true
|
|
}
|
|
|
|
function CanBeShipped() {
|
|
return productStore.cart.items!.filter((rec) => rec.order.product!.canBeShipped).length
|
|
}
|
|
|
|
function CanBeBuyOnline() {
|
|
return productStore.cart.items!.filter((rec) => rec.order.product!.canBeBuyOnline).length
|
|
}
|
|
|
|
function getnumsteps() {
|
|
let numsteps = 1
|
|
|
|
if (CanBeShipped())
|
|
numsteps++
|
|
if (CanBeBuyOnline())
|
|
numsteps++
|
|
|
|
return numsteps
|
|
}
|
|
|
|
function docheckout() {
|
|
|
|
// Può essere spedito?
|
|
|
|
if (CanBeShipped()) {
|
|
// mostra form di spedizione
|
|
}
|
|
|
|
if (CanBeBuyOnline()) {
|
|
// mostra form di acquisto Online
|
|
}
|
|
}
|
|
|
|
function nextstep() {
|
|
return 0
|
|
}
|
|
|
|
function clickFunz(order: IOrderCart, status: number) {
|
|
|
|
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
|
// Conferma Ordine
|
|
}
|
|
|
|
const statusStr = shared_consts.getStatusStr(status)
|
|
|
|
$q.dialog({
|
|
message: 'Impostare l\'ordine n. ' + order.numorder + ' ' + statusStr + ' ?',
|
|
ok: {
|
|
label: t('dialog.yes'),
|
|
push: true
|
|
},
|
|
cancel: {
|
|
label: t('dialog.cancel')
|
|
},
|
|
title: 'Ordine'
|
|
}).onOk(async () => {
|
|
|
|
let options = {
|
|
// userIdStore: order.items ? order.items[0].order.storehouse.username : '',
|
|
}
|
|
|
|
statusnow.value = await productStore.UpdateOrderCartStatus({ order_id: order._id, status, options })
|
|
|
|
if (statusnow.value === status) {
|
|
order.status = statusnow.value
|
|
updateorders()
|
|
tools.showPositiveNotif($q, 'Ordine ' + statusStr)
|
|
}
|
|
// change_field('status')
|
|
// change_field('status')
|
|
})
|
|
}
|
|
|
|
onMounted(mounted)
|
|
|
|
return {
|
|
userStore,
|
|
costanti,
|
|
tools,
|
|
toolsext,
|
|
shared_consts,
|
|
columns,
|
|
taborders,
|
|
arrnumstatus,
|
|
clickFunz,
|
|
getOrdersCart,
|
|
getAllOrdersCart,
|
|
updateorders,
|
|
getCols,
|
|
endload,
|
|
getOrdersCartWithTotals,
|
|
productStore,
|
|
t,
|
|
initialPagination,
|
|
cosa,
|
|
}
|
|
}
|
|
})
|
|
|