email da inviare ai clienti ...
This commit is contained in:
206
src/components/COrdersCart/COrdersCart.ts
Executable file
206
src/components/COrdersCart/COrdersCart.ts
Executable file
@@ -0,0 +1,206 @@
|
||||
import { defineComponent, onMounted, ref, computed } 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 { IBaseOrder, ICart, IOrder, IOrderCart, IProduct, IShareWithUs } from '@src/model/Products'
|
||||
|
||||
import { shared_consts } from '@src/common/shared_vuejs'
|
||||
|
||||
import { CSingleCart } from '../CSingleCart'
|
||||
import { CTitleBanner } from '@components'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'COrdersCart',
|
||||
props: {
|
||||
iscash: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
idOrdersCart: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
|
||||
},
|
||||
components: { CSingleCart, CTitleBanner },
|
||||
setup(props) {
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const productStore = useProducts()
|
||||
const $router = useRouter()
|
||||
const $q = useQuasar()
|
||||
const { t } = useI18n();
|
||||
|
||||
const myrec = ref(<any[string]>[])
|
||||
const oldrec = ref(<any[string]>[])
|
||||
const note = ref('')
|
||||
const endload = ref(false)
|
||||
const recOrderCart = ref(<IOrderCart>{})
|
||||
|
||||
const search = ref('')
|
||||
|
||||
const statusnow = computed(() => (): number => {
|
||||
if (recOrderCart.value) {
|
||||
return recOrderCart.value.status
|
||||
}
|
||||
return 0
|
||||
})
|
||||
|
||||
function mounted() {
|
||||
// Inizializza
|
||||
load()
|
||||
}
|
||||
|
||||
function getItems(): IBaseOrder[] | [] {
|
||||
return recOrderCart.value.items ?? []
|
||||
}
|
||||
|
||||
function getNumItems(): number {
|
||||
const itemsord = getItems()
|
||||
if (itemsord)
|
||||
return itemsord.length || 0
|
||||
else
|
||||
return 0
|
||||
}
|
||||
|
||||
function change_field(fieldname: string) {
|
||||
if (myrec.value[fieldname] !== oldrec.value[fieldname]) {
|
||||
myrec.value[fieldname] = oldrec.value[fieldname]
|
||||
|
||||
const mydata = {
|
||||
[fieldname]: myrec.value[fieldname]
|
||||
}
|
||||
|
||||
const aggiorna = false
|
||||
tools.saveFieldToServer($q, 'orderscarts', recOrderCart.value._id, mydata, aggiorna)
|
||||
oldrec.value[fieldname] = myrec.value[fieldname]
|
||||
}
|
||||
}
|
||||
|
||||
function myTotalPrice(): string {
|
||||
if (recOrderCart.value) {
|
||||
return recOrderCart.value.totalPrice.toFixed(2)
|
||||
} else {
|
||||
return '0'
|
||||
}
|
||||
}
|
||||
|
||||
function myTotalQty(): number {
|
||||
if (recOrderCart.value) {
|
||||
return recOrderCart.value.totalQty
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
function load() {
|
||||
recOrderCart.value = productStore.getOrdersCartById(props.idOrdersCart)
|
||||
if (recOrderCart.value) {
|
||||
oldrec.value = myrec.value
|
||||
note.value = recOrderCart.value.note!
|
||||
}
|
||||
endload.value = true
|
||||
}
|
||||
|
||||
function CanBeShipped() {
|
||||
return recOrderCart.value.items ? recOrderCart.value.items.filter((rec: any) => rec.order.product.canBeShipped).length : false
|
||||
}
|
||||
|
||||
function CanBeBuyOnline() {
|
||||
return recOrderCart.value.items ? recOrderCart.value.items.filter((rec: any) => rec.order.product.canBeBuyOnline).length : false
|
||||
}
|
||||
|
||||
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 getActualIdStorehouse(myprod: IProduct) {
|
||||
// Ottieni il negozio attualmente selezionato:
|
||||
// Se ce n'è solo 1 allora prendi quello !
|
||||
if (myprod.storehouses.length === 1) {
|
||||
return myprod.storehouses[0]._id
|
||||
} else {
|
||||
// Ottieni il negozio attualmente scelto !
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
function getActualGasordine(myprod: IProduct) {
|
||||
// Ottieni il negozio attualmente selezionato:
|
||||
// Se ce n'è solo 1 allora prendi quello !
|
||||
if (myprod.gasordines.length === 1) {
|
||||
return myprod.gasordines[0]._id
|
||||
} else {
|
||||
// Ottieni il gasordine attualmente scelto !
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
async function insertArticolo() {
|
||||
let lowerSearchText = search.value.trim();
|
||||
|
||||
const myprod = productStore.getProductByCode(lowerSearchText);
|
||||
if (myprod && myprod.active) {
|
||||
let myorder: IOrder = {
|
||||
quantity: 1, quantitypreordered: 0,
|
||||
TotalPriceProduct: 0, price: 0,
|
||||
idStorehouse: getActualIdStorehouse(myprod),
|
||||
idGasordine: getActualGasordine(myprod),
|
||||
}
|
||||
await productStore.addtoCartBase({ $q, t, id: myprod._id, order: myorder, addqty: true })
|
||||
search.value = ''
|
||||
load()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(mounted)
|
||||
|
||||
return {
|
||||
userStore,
|
||||
costanti,
|
||||
tools,
|
||||
toolsext,
|
||||
getNumItems,
|
||||
myTotalPrice,
|
||||
getItems,
|
||||
change_field,
|
||||
note,
|
||||
statusnow,
|
||||
shared_consts,
|
||||
myTotalQty,
|
||||
recOrderCart,
|
||||
endload,
|
||||
search,
|
||||
insertArticolo,
|
||||
t,
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user