possibilità di modificare un ordine, e anche i totali

This commit is contained in:
Surya Paolo
2024-01-15 22:19:33 +01:00
parent 8979cd807a
commit c8a4be65c1
25 changed files with 315 additions and 94 deletions

View File

@@ -230,7 +230,7 @@ export default defineComponent({
if (myprod && myprod.active) {
let myorder: IOrder = {
quantity: 1, quantitypreordered: 0,
TotalPriceProduct: 0, price: 0,
TotalPriceProduct: 0, TotalPriceProductCalc: 0, price: 0,
idStorehouse: getActualIdStorehouse(myprod),
idGasordine: getActualGasordine(myprod),
}

View File

@@ -130,10 +130,10 @@ export default defineComponent({
async function mounted() {
console.log(' ## INIZIO MOUNT ')
// console.log(' ## INIZIO MOUNT ')
username.value = userStore.my.username
await loadCircuits()
console.log(' -- FINE MOUNT ')
// console.log(' -- FINE MOUNT ')
}
function updateValue(val: number) {

View File

@@ -1,4 +1,4 @@
import { defineComponent, onMounted, ref, computed } from 'vue'
import { defineComponent, onMounted, ref, computed, watch } from 'vue'
import { tools } from '@store/Modules/tools'
import { useUserStore } from '@store/UserStore'
import { useRouter } from 'vue-router'
@@ -15,6 +15,7 @@ import { shared_consts } from '@src/common/shared_vuejs'
import { CSingleCart } from '../CSingleCart'
import { CTitleBanner } from '@components'
export default defineComponent({
name: 'COrdersCart',
props: {
@@ -46,6 +47,17 @@ export default defineComponent({
const recOrderCart = ref(<IOrderCart>{})
const search = ref('')
const editOn = ref(false)
const allTotalPrice = ref(<number | undefined>undefined);
watch(allTotalPrice, (newValue: any) => {
if (!newValue)
recOrderCart.value.totalPrice = 0
else
recOrderCart.value.totalPrice = parseFloat(newValue);
});
const statusnow = computed(() => (): number => {
if (recOrderCart.value) {
@@ -57,6 +69,8 @@ export default defineComponent({
function mounted() {
// Inizializza
load()
allTotalPrice.value = recOrderCart.value.totalPrice
}
function getItems(): IBaseOrder[] | [] {
@@ -93,6 +107,14 @@ export default defineComponent({
}
}
function myTotalPriceCalc(): string {
if (recOrderCart.value) {
return recOrderCart.value.totalPriceCalc ? recOrderCart.value.totalPriceCalc.toFixed(2) : ''
} else {
return '0'
}
}
function myTotalQty(): number {
if (recOrderCart.value) {
return recOrderCart.value.totalQty
@@ -108,6 +130,7 @@ export default defineComponent({
oldrec.value = myrec.value
note.value = recOrderCart.value.note!
}
allTotalPrice.value = recOrderCart.value.totalPrice
endload.value = true
}
@@ -172,7 +195,7 @@ export default defineComponent({
if (myprod && myprod.active) {
let myorder: IOrder = {
quantity: 1, quantitypreordered: 0,
TotalPriceProduct: 0, price: 0,
TotalPriceProduct: 0, TotalPriceProductCalc: 0, price: 0,
idStorehouse: getActualIdStorehouse(myprod),
idGasordine: getActualGasordine(myprod),
}
@@ -182,8 +205,9 @@ export default defineComponent({
}
}
function updateOrdersCart(paramstoupdate: any) {
productStore.updateOrdersCartById(props.idOrdersCart, paramstoupdate)
async function updateOrdersCart(paramstoupdate: any) {
await productStore.updateOrdersCartById(props.idOrdersCart, paramstoupdate)
}
function ordersUpdated() {
@@ -191,6 +215,17 @@ export default defineComponent({
load()
}
function changeTotalPrice() {
change_field('totalPrice')
}
function updateTotalPrice() {
updateOrdersCart({totalPrice: allTotalPrice.value})
}
onMounted(mounted)
@@ -214,6 +249,11 @@ export default defineComponent({
updateOrdersCart,
ordersUpdated,
t,
editOn,
allTotalPrice,
changeTotalPrice,
updateTotalPrice,
myTotalPriceCalc,
}
}
})

View File

@@ -2,6 +2,15 @@
<q-spinner v-if="!endload" color="primary" size="3em" :thickness="2" />
<div v-if="endload && recOrderCart.numorder > 0">
<div v-if="recOrderCart" class="panel">
<q-toggle
v-if="tools.isManager()"
v-model="editOn"
class="absolute-top-left"
color="green"
icon="fas fa-pencil-alt"
dense
>
</q-toggle>
<div class="numorder">
{{ t('orderscart.numero_ordine') }}: {{ recOrderCart.numorder }}
</div>
@@ -26,17 +35,51 @@
:order="itemorder.order"
:showall="false"
:idOrdersCart="recOrderCart._id"
:editmode="tools.isManager()"
:editmode="editOn"
:nomodif="true"
@update="ordersUpdated()"
/>
</div>
</div>
<q-separator></q-separator>
<div
v-if="myTotalPriceCalc() !== myTotalPrice() && myTotalPriceCalc() !== ''"
class="col-6 q-mr-sm"
style="text-align: right"
>
<span class="text-grey q-mr-xs">{{ t('ecomm.calcolato') }}:</span>
<span class="text-subtitle1 q-mr-sm"
> {{ myTotalPriceCalc() }}</span
>
</div>
<div class="col-6 q-mr-sm" style="text-align: right">
<span class="text-grey q-mr-xs">{{ t('ecomm.totale') }}:</span>
<span class="text-subtitle1 q-mr-sm"> {{ myTotalPrice() }}</span>
</div>
<div>
<q-input
v-if="editOn && getNumItems() > 0"
v-model="allTotalPrice"
:label="t('ecomm.totalPrice')"
filled
dense
debounce="1000"
@change="changeTotalPrice"
>
</q-input>
<q-btn
v-if="editOn"
outline
rounded
dense
color="green"
icon="fas fa-redo"
:label="t('orderscart.update_TotalPrice')"
@click="updateTotalPrice"
>
</q-btn>
</div>
<q-input
v-if="tools.isManager() && getNumItems() > 0"

View File

@@ -3,11 +3,12 @@ import { CCardState } from '../CCardState'
import { CCopyBtn } from '../CCopyBtn'
import { IOperators, IOrder, IProduct } from '@src/model'
import { defineComponent, PropType, toRef } from 'vue'
import { defineComponent, PropType, toRef, ref, watch, onMounted } from 'vue'
import { CTitleBanner } from '@src/components/CTitleBanner'
import { useProducts } from '@store/Products'
import { useI18n } from '@src/boot/i18n'
import { useQuasar } from 'quasar'
import { loadRouteLocation } from 'vue-router'
export default defineComponent({
name: 'CSingleCart',
@@ -45,6 +46,47 @@ export default defineComponent({
const $q = useQuasar()
const orderQuantity = ref(<number | undefined>undefined);
const orderQuantityPreordered = ref(<number | undefined>undefined);
const orderTotalPriceProduct = ref(<number | undefined>undefined);
const enableQty = ref(false)
const endload = ref(false)
const enableQtyPreordered = ref(false)
const enableChangeTotalPrice = ref(false)
watch(orderQuantity, (newValue: any) => {
if (!newValue)
order.value.quantity = 0
else
order.value.quantity = parseFloat(newValue);
enableChangeTotalPrice.value = false
});
watch(orderQuantityPreordered, (newValue: any) => {
if (!newValue)
order.value.quantitypreordered = 0
else
order.value.quantitypreordered = parseFloat(newValue);
enableChangeTotalPrice.value = false
});
watch(orderTotalPriceProduct, (newValue: any) => {
if (!newValue)
order.value.TotalPriceProduct = 0
else
order.value.TotalPriceProduct = parseFloat(newValue);
});
watch(() => props.order.TotalPriceProduct, (newValue: any) => {
if (!newValue)
orderTotalPriceProduct.value = 0
else
orderTotalPriceProduct.value = parseFloat(newValue);
});
function myimgclass() {
if (props.showall) {
return 'imgNormal'
@@ -102,23 +144,46 @@ export default defineComponent({
}
function removeFromCard() {
if (props.idOrdersCart) {
//
} else {
products.removeFromCart({ order: order.value })
}
products.removeFromCart({ order: order.value })
}
async function updateOrder(paramstoupdate: any) {
await products.updateOrderByOrder(props.idOrdersCart, order.value._id, paramstoupdate)
endload.value = false
if (enableChangeTotalPrice.value) {
paramstoupdate = { ...paramstoupdate, TotalPriceProduct: order.value.TotalPriceProduct }
}
const myOrdersCart = await products.updateOrderByOrder(props.idOrdersCart, order.value._id, paramstoupdate)
emit('update')
mounted()
}
function getRisparmio(): string {
return ((order.value.product!.price * order.value.quantity) - order.value.TotalPriceProduct).toFixed(2)
}
function mounted() {
endload.value = false
if (props.order.quantity !== 0) {
orderQuantity.value = props.order.quantity
enableQty.value = true
}
if (props.order.quantitypreordered !== 0) {
orderQuantityPreordered.value = props.order.quantitypreordered
enableQtyPreordered.value = true
}
orderTotalPriceProduct.value = props.order.TotalPriceProduct
endload.value = true
}
function changeTotalPrice() {
console.log('changeTotalPrice')
enableChangeTotalPrice.value = true
}
onMounted(mounted)
return {
myimgclass,
addsubqty,
@@ -129,6 +194,13 @@ export default defineComponent({
products,
t,
updateOrder,
orderQuantity,
orderQuantityPreordered,
enableQty,
enableQtyPreordered,
changeTotalPrice,
orderTotalPriceProduct,
endload,
}
},
})

View File

@@ -24,7 +24,13 @@
v-if="order.product.productInfo.unit"
>
{{ tools.getWeightTotalByOrder(order) }}
{{ tools.getUnitsMeasure(order.product.productInfo.unit, true, order.product.productInfo.weight) }}
{{
tools.getUnitsMeasure(
order.product.productInfo.unit,
true,
order.product.productInfo.weight
)
}}
</div>
<div class="row q-mb-xs no-wrap items-center centeritems">
<q-btn
@@ -43,7 +49,8 @@
></q-btn>
<div v-if="editmode">
<q-input
v-model="order.quantity"
v-if="enableQty"
v-model="orderQuantity"
autofocus
debounce="500"
borderless
@@ -52,16 +59,28 @@
:label="t('products.quantity')"
></q-input>
<q-input
v-model="order.quantitypreordered"
v-if="enableQtyPreordered"
v-model="orderQuantityPreordered"
autofocus
debounce="500"
borderless
rounded
densep
:label="t('ecomm.preord')"
></q-input>
</div>
<div v-if="editmode">
<q-input
v-model="orderTotalPriceProduct"
autofocus
debounce="500"
borderless
rounded
dense
:label="t('ecomm.preord')"
@change="changeTotalPrice"
:label="t('orderscart.TotalPriceProduct')"
></q-input>
</div>
<div v-if="tools.isManager">
<q-btn
outline
rounded
@@ -69,7 +88,12 @@
color="green"
icon="fas fa-redo"
:label="t('orderscart.update_order')"
@click="updateOrder({quantitypreordered: order.quantitypreordered, quantity: order.quantity})"
@click="
updateOrder({
quantitypreordered: order.quantitypreordered,
quantity: order.quantity,
})
"
>
</q-btn>
</div>
@@ -108,30 +132,40 @@
: 0
}}
</span>
<span v-if="tools.isManager() && order.TotalPriceProduct !== order.TotalPriceProductCalc"
:class="isApplicatoSconto() ? 'ordine_scontato_nuovo' : ''">
(Calc:
{{
order.TotalPriceProductCalc
? order.TotalPriceProductCalc.toFixed(2)
: 0
}})
</span>
<span v-if="isApplicatoSconto()">
&nbsp;<span class="ordine_scontato"
>(<span class="barrato"
>
{{
(
order.price * order.quantity +
order.price * order.quantitypreordered
(order.price * order.quantity) +
(order.price * order.quantitypreordered)
).toFixed(2)
}}</span
>)</span
>&nbsp;
</span>
<span v-if="isApplicatoSconto()" class="ordine_scritta_sconto">{{
<span v-if="isApplicatoSconto() && !editmode" class="ordine_scritta_sconto">{{
$t('ecomm.sconto_applicato', { risparmio: getRisparmio() })
}}</span>
</div>
</q-item-label>
</q-item-section>
<q-item-section side top>
<q-item-section side>
<q-item-label>
<div class="col-1">
<div class="col-2">
<q-btn
v-if="!nomodif && editmode"
v-if="!nomodif"
icon="fas fa-trash"
color="negative"
round

View File

@@ -222,7 +222,7 @@ export default defineComponent({
function setLangAtt(mylang: string) {
console.log('LANG =', mylang)
// console.log('LANG =', mylang)
// console.log('PRIMA $q.lang.isoName', $q.lang.isoName)
// dynamic import, so loading on demand only