From 3ffa2893e5294e3ce47070136bfd148c19a92779 Mon Sep 17 00:00:00 2001 From: Surya Paolo Date: Sat, 13 Jan 2024 00:29:02 +0100 Subject: [PATCH] - edit campi prodotti - edit ordini --- src/components/CCart/CCart.vue | 2 +- src/components/CDateTime/CDateTime.ts | 7 + src/components/CDateTime/CDateTime.vue | 6 +- src/components/CMyCart/CMyCart.ts | 5 + src/components/CMyCart/CMyCart.vue | 6 +- src/components/CMyValueDb/CMyValueDb.scss | 24 ++ src/components/CMyValueDb/CMyValueDb.ts | 194 +++++++++++++++ src/components/CMyValueDb/CMyValueDb.vue | 78 ++++++ src/components/CMyValueDb/index.ts | 1 + src/components/COrdersCart/COrdersCart.ts | 13 + src/components/COrdersCart/COrdersCart.vue | 1 + src/components/CProductCard/CProductCard.scss | 6 +- src/components/CProductCard/CProductCard.ts | 54 ++++- src/components/CProductCard/CProductCard.vue | 223 +++++++++++++++++- src/components/CSingleCart/CSingleCart.ts | 7 +- src/components/CSingleCart/CSingleCart.vue | 27 ++- src/mixins/mixin-base.ts | 12 +- src/model/UserStore.ts | 2 +- src/statics/lang/it.js | 4 + src/store/Modules/tools.ts | 32 +-- src/store/Products.ts | 94 +++++++- src/views/ecommerce/orderInfo/orderInfo.ts | 4 +- src/views/ecommerce/orderInfo/orderInfo.vue | 12 +- 23 files changed, 749 insertions(+), 65 deletions(-) create mode 100755 src/components/CMyValueDb/CMyValueDb.scss create mode 100755 src/components/CMyValueDb/CMyValueDb.ts create mode 100755 src/components/CMyValueDb/CMyValueDb.vue create mode 100755 src/components/CMyValueDb/index.ts diff --git a/src/components/CCart/CCart.vue b/src/components/CCart/CCart.vue index 573e2cfd..acfa23dc 100755 --- a/src/components/CCart/CCart.vue +++ b/src/components/CCart/CCart.vue @@ -5,7 +5,7 @@
- +
diff --git a/src/components/CDateTime/CDateTime.ts b/src/components/CDateTime/CDateTime.ts index c6371de8..fcad4f36 100755 --- a/src/components/CDateTime/CDateTime.ts +++ b/src/components/CDateTime/CDateTime.ts @@ -172,6 +172,12 @@ export default defineComponent({ } } + function azzera() { + saveit.value = true + showDateTimeScroller.value = false + emit('savetoclose', null, valueprec.value) + } + created() return { @@ -190,6 +196,7 @@ export default defineComponent({ mydate, mytime, tools, + azzera, } }, }) diff --git a/src/components/CDateTime/CDateTime.vue b/src/components/CDateTime/CDateTime.vue index 22c18d4b..ebf36ec9 100755 --- a/src/components/CDateTime/CDateTime.vue +++ b/src/components/CDateTime/CDateTime.vue @@ -79,6 +79,10 @@ } " /> +
+ +
- +
- +
@@ -36,7 +36,7 @@ rounded icon="fas fa-shopping-cart" color="primary" - :label="$t('ecomm.btn_cassa')" + :label="t('ecomm.btn_cassa')" @click="globalStore.rightCartOpen = false" class="q-mb-sm" to="/checkout" @@ -50,7 +50,7 @@ rounded icon="fas fa-clipboard-list" color="positive" - :label="$t('ecomm.btn_ordini')" + :label="t('ecomm.btn_ordini')" class="q-mb-sm" @click="globalStore.rightCartOpen = false" to="/orderinfo" diff --git a/src/components/CMyValueDb/CMyValueDb.scss b/src/components/CMyValueDb/CMyValueDb.scss new file mode 100755 index 00000000..232ae4f0 --- /dev/null +++ b/src/components/CMyValueDb/CMyValueDb.scss @@ -0,0 +1,24 @@ +.colmodif { + cursor: pointer; +} + + +.colmodif:hover { + background-color: #a8f0ff; + cursor: pointer; +} + +.colsel { + background-color: #81b8ff; +} + +.cldisable{ + color: gray !important; +} + +.clinput{ + @media (max-width: 500px) { + display: flex; + flex-grow: 1; + } +} diff --git a/src/components/CMyValueDb/CMyValueDb.ts b/src/components/CMyValueDb/CMyValueDb.ts new file mode 100755 index 00000000..bef46140 --- /dev/null +++ b/src/components/CMyValueDb/CMyValueDb.ts @@ -0,0 +1,194 @@ +import { defineComponent, onMounted, PropType, ref, watch } from 'vue' +import { useQuasar } from 'quasar' +import { useI18n } from '@/boot/i18n' +import { useGlobalStore } from '@store/globalStore' +import { fieldsTable } from '@store/Modules/fieldsTable' +import { tools } from '@store/Modules/tools' +import { costanti } from '@costanti' +import { CMyPopupEdit } from '@/components/CMyPopupEdit' +import { IColGridTable, IOperators, ISpecialField } from 'model' +import MixinBase from '@/mixins/mixin-base' + + +export default defineComponent({ + name: 'CMyValueDb', + emits: ['save'], + props: { + title: { + type: String, + required: true, + }, + hint: { + type: String, + required: false, + default: '', + }, + mykey: { + type: String, + required: true, + }, + mysubkey: { + type: String, + required: false, + default: '', + }, + specialField: { + type: Object as PropType, + required: false, + default: null, + }, + filter: { + type: [String, Function], + required: false, + default: null, + }, + indrec: { + type: Number, + required: false, + default: -1, + }, + maxlength: { + type: Number, + required: false, + default: 0, + }, + minlength: { + type: Number, + required: false, + default: 0, + }, + mysubsubkey: { + type: String, + required: false, + default: '', + }, + type: { + type: Number, + required: true, + }, + serv: { + type: Boolean, + required: false, + default: false, + }, + canModify: { + type: Boolean, + required: false, + default: true, + }, + disable: { + type: Boolean, + required: false, + default: false, + }, + jointable: { + type: String, + required: false, + default: '', + }, + table: { + type: String, + required: false, + default: 'settings', + }, + myimg: { + type: String, + required: false, + default: '', + }, + rec: { + type: Object, + required: false, + default: null, + }, + mycol: { + type: Object as PropType | undefined, + required: false, + default: () => { + return { } + }, + }, + id: { + type: String, + required: false, + default: '', + }, + idmain: { + type: String, + required: false, + default: '', + }, + tablesel: { + type: String, + required: false, + default: '', + }, + pickup: { + type: Boolean, + required: false, + default: false, + }, + }, + components: { CMyPopupEdit }, + setup(props, { emit }) { + const $q = useQuasar() + const { t } = useI18n() + const globalStore = useGlobalStore() + + const col = ref({ + name: 'test', fieldtype: 0, showWhen: costanti.showWhen.NewRec + costanti.showWhen.InEdit + costanti.showWhen.InView, visible: true, maxlength: props.maxlength, minlength: props.minlength + }) + const row = ref({}) + + const { setValDb, getValDb } = MixinBase() + + function showandsel(row: any, col: any, newval: any, valinitial: any) { + console.log('showandsel CMyFieldDb', row, col, newval) + + if (newval !== valinitial) { + setValDb($q, props.mykey, newval, props.type, props.serv, props.table, props.mysubkey, props.id, props.indrec, props.mysubsubkey, props.specialField) + } + + } + + function save(newval: any) { + emit('save', newval) + } + + function withBorder() { + if (col.value) + return col.value.fieldtype !== costanti.FieldType.onlydate && col.value.fieldtype !== costanti.FieldType.date + else + return false + } + + function mounted() { + if (props.rec) { + row.value = props.rec + } + if (props.mycol && props.mycol.name !== '') { + col.value = props.mycol + } else { + // console.log('Tab = ', props.table, 'key=', props.mykey, 'mycolProp', props.mycol) + col.value = fieldsTable.getColByTable(props.table, props.mykey) + } + + // console.log('COL = ', col.value, 'MyCol passed', props.mycol) + } + + onMounted(mounted) + + return { + tools, + costanti, + fieldsTable, + globalStore, + col, + row, + showandsel, + withBorder, + save, + } + }, +}) + diff --git a/src/components/CMyValueDb/CMyValueDb.vue b/src/components/CMyValueDb/CMyValueDb.vue new file mode 100755 index 00000000..f8487b7a --- /dev/null +++ b/src/components/CMyValueDb/CMyValueDb.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/src/components/CMyValueDb/index.ts b/src/components/CMyValueDb/index.ts new file mode 100755 index 00000000..103c1cef --- /dev/null +++ b/src/components/CMyValueDb/index.ts @@ -0,0 +1 @@ +export {default as CMyValueDb} from './CMyValueDb.vue' diff --git a/src/components/COrdersCart/COrdersCart.ts b/src/components/COrdersCart/COrdersCart.ts index 2dea713f..95701261 100755 --- a/src/components/COrdersCart/COrdersCart.ts +++ b/src/components/COrdersCart/COrdersCart.ts @@ -102,6 +102,7 @@ export default defineComponent({ } function load() { + endload.value = false recOrderCart.value = productStore.getOrdersCartById(props.idOrdersCart) if (recOrderCart.value) { oldrec.value = myrec.value @@ -181,6 +182,16 @@ export default defineComponent({ } } + function updateOrdersCart(paramstoupdate: any) { + productStore.updateOrdersCartById(props.idOrdersCart, paramstoupdate) + } + + function ordersUpdated() { + console.log('ordersUpdated') + load() + } + + onMounted(mounted) return { @@ -200,6 +211,8 @@ export default defineComponent({ endload, search, insertArticolo, + updateOrdersCart, + ordersUpdated, t, } } diff --git a/src/components/COrdersCart/COrdersCart.vue b/src/components/COrdersCart/COrdersCart.vue index 73623e79..39c7ccc3 100755 --- a/src/components/COrdersCart/COrdersCart.vue +++ b/src/components/COrdersCart/COrdersCart.vue @@ -28,6 +28,7 @@ :idOrdersCart="recOrderCart._id" :editmode="tools.isManager()" :nomodif="true" + @update="ordersUpdated()" />
diff --git a/src/components/CProductCard/CProductCard.scss b/src/components/CProductCard/CProductCard.scss index 53771852..ee4b4f26 100755 --- a/src/components/CProductCard/CProductCard.scss +++ b/src/components/CProductCard/CProductCard.scss @@ -126,4 +126,8 @@ width: 100%; height: 100%; object-fit: cover; -} \ No newline at end of file +} + +.q-card__section--vert{ + padding: 4px; +} diff --git a/src/components/CProductCard/CProductCard.ts b/src/components/CProductCard/CProductCard.ts index e3e4c2c7..d8ea7a37 100755 --- a/src/components/CProductCard/CProductCard.ts +++ b/src/components/CProductCard/CProductCard.ts @@ -7,6 +7,7 @@ import { useQuasar } from 'quasar' import { CTitleBanner } from '../CTitleBanner' import { CCardState } from '../CCardState' import { CCopyBtn } from '../CCopyBtn' +import { CMyValueDb } from '../CMyValueDb' import { func_tools, toolsext } from '@store/Modules/toolsext' @@ -17,6 +18,7 @@ import { useProducts } from '@store/Products' import { shared_consts } from '@src/common/shared_vuejs' import { useRouter } from 'vue-router' +import { costanti } from '@costanti' export default defineComponent({ name: 'CProductCard', props: { @@ -41,7 +43,7 @@ export default defineComponent({ default: false, }, }, - components: { CTitleBanner, CCardState, CCopyBtn }, + components: { CTitleBanner, CCardState, CCopyBtn, CMyValueDb }, setup(props, { emit }) { const $q = useQuasar() const { t } = useI18n() @@ -51,6 +53,7 @@ export default defineComponent({ const listord = ref([]) const sumval = ref(0) + const editOn = ref(false) const site = ref(globalStore.site) @@ -93,6 +96,13 @@ export default defineComponent({ return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter) }) + + watch(() => editOn.value, (to: any, from: any) => { + if (!editOn.value) + ricarica() + }) + + /*const myproduct = computed((): IProduct => { console.log('getproduct computed') const ris = products.getProduct(props.code) @@ -180,6 +190,30 @@ export default defineComponent({ // products.updateQuantityAvailable(myproduct.value._id) } + async function ricarica() { + endload.value = false + const prod = await products.loadProductById(myproduct.value._id) + if (prod) { + myproduct.value = prod + } + load() + endload.value = true + + } + + function updateproductmodif() { + + try { + myproduct.value = products.getProductById(props.id) + + recgasordineSelected.value = myproduct.value.gasordines.find((rec: any) => rec._id === gasordineSelected.value) + + updateLabel() + } catch (e) { + console.error('err', e) + } + } + function getStorehouses() { if (!myproduct.value) return [] @@ -223,7 +257,7 @@ export default defineComponent({ function checkifCartDisable() { // return !myorder.idStorehouse - return false + return isOrdineChiuso() } function getQtyWarn() { @@ -288,6 +322,11 @@ export default defineComponent({ timerLabelScadenza.value = '' } + function isOrdineChiuso() { + return recgasordineSelected.value && recgasordineSelected.value.dataora_chiusura_ordini && + tools.getCountDown(recgasordineSelected.value.dataora_chiusura_ordini) === '' + } + function startTimer() { // Update the timer label every second timerInterval.value = setInterval(() => updateTimerLabel(), 1000); @@ -350,7 +389,7 @@ export default defineComponent({ openlistorders.value = true sumval.value = products.getSumQtyOrderProductInOrdersCart(myproduct.value._id) - listord.value = arrordersCart.value.filter((ordercart: IOrderCart) => ordercart.items!.reduce((accumulator, item) => { + listord.value = arrordersCart.value.filter((orderscart: IOrderCart) => orderscart.items!.reduce((accumulator, item) => { return accumulator + item.order.quantity }, 0)) } @@ -359,7 +398,7 @@ export default defineComponent({ openlistorders.value = true sumval.value = products.getSumQtyPreOrderInOrdersCart(myproduct.value._id) - listord.value = arrordersCart.value.filter((ordercart: IOrderCart) => ordercart.items!.reduce((accumulator, item) => { + listord.value = arrordersCart.value.filter((orderscart: IOrderCart) => orderscart.items!.reduce((accumulator, item) => { return accumulator + item.order.quantitypreordered }, 0)) } @@ -460,6 +499,13 @@ export default defineComponent({ onTouchEnd, $router, naviga, + globalStore, + editOn, + costanti, + updateproduct, + updateproductmodif, + isOrdineChiuso, + ricarica, } } }) diff --git a/src/components/CProductCard/CProductCard.vue b/src/components/CProductCard/CProductCard.vue index bb86718f..edb4b25c 100755 --- a/src/components/CProductCard/CProductCard.vue +++ b/src/components/CProductCard/CProductCard.vue @@ -87,9 +87,19 @@ class="text-black q-ml-xs text-h8" v-if="myproduct.productInfo.unit" > - {{ tools.getWeightByUnit(myproduct.productInfo.unit, true, myproduct.productInfo.weight) }} {{ - tools.getUnitsMeasure(myproduct.productInfo.unit, true, myproduct.productInfo.weight) + tools.getWeightByUnit( + myproduct.productInfo.unit, + true, + myproduct.productInfo.weight + ) + }} + {{ + tools.getUnitsMeasure( + myproduct.productInfo.unit, + true, + myproduct.productInfo.weight + ) }} @@ -270,7 +280,7 @@ - + @@ -429,13 +439,21 @@ {{ t('ecomm.offerta_gas_raggiunta', { qta: myproduct.qtyToReachForGas, - unit: tools.getUnitsMeasure(myproduct.productInfo.unit, true, myproduct.productInfo.weight), + unit: tools.getUnitsMeasure( + myproduct.productInfo.unit, + true, + myproduct.productInfo.weight + ), }) }} {{ t('ecomm.offerta_gas', { qta: myproduct.qtyToReachForGas, - unit: tools.getUnitsMeasure(myproduct.productInfo.unit, true, myproduct.productInfo.weight), + unit: tools.getUnitsMeasure( + myproduct.productInfo.unit, + true, + myproduct.productInfo.weight + ), }) }} @@ -496,16 +514,35 @@ - + {{ t('gas.dataora_chiusura_ordini') }} - {{ timerLabelScadenza }} + {{ timerLabelScadenza }} + {{ + t('ecomm.ordine_scaduto', { + date: tools.getstrshortDateTime( + recgasordineSelected.dataora_chiusura_ordini + ), + }) + }} + + - + @@ -515,11 +552,25 @@ {{ t('gas.data_arrivo_merce') }} - {{ labelDataArrivoMerce }} + + +
+ {{ labelDataArrivoMerce }} +
- + @@ -529,7 +580,21 @@ {{ t('gas.dataora_ritiro') }} - {{ labelDataRitiro }} + + +
+ {{ labelDataRitiro }} +
@@ -563,6 +628,122 @@
{{ myorder.quantity + myorder.quantitypreordered }}
+
+ + + +
+ + + + + + + + +
+ +
+ + + + + + + + +
+
+ +
+
@@ -597,6 +778,26 @@ >
+ + + + diff --git a/src/components/CSingleCart/CSingleCart.ts b/src/components/CSingleCart/CSingleCart.ts index 47d4ca50..3efdf6da 100755 --- a/src/components/CSingleCart/CSingleCart.ts +++ b/src/components/CSingleCart/CSingleCart.ts @@ -38,7 +38,7 @@ export default defineComponent({ }, }, components: { CTitleBanner, CCardState, CCopyBtn }, - setup(props) { + setup(props, { emit }) { const products = useProducts() const order = toRef(props, 'order') const { t } = useI18n() @@ -110,8 +110,9 @@ export default defineComponent({ } - function updateOrder(val: any) { - + async function updateOrder(paramstoupdate: any) { + await products.updateOrderByOrder(props.idOrdersCart, order.value._id, paramstoupdate) + emit('update') } function getRisparmio(): string { diff --git a/src/components/CSingleCart/CSingleCart.vue b/src/components/CSingleCart/CSingleCart.vue index d2fba223..e0840e49 100755 --- a/src/components/CSingleCart/CSingleCart.vue +++ b/src/components/CSingleCart/CSingleCart.vue @@ -24,7 +24,7 @@ v-if="order.product.productInfo.unit" > {{ tools.getWeightTotalByOrder(order) }} - {{ tools.getUnitsMeasure(order.product.productInfo.unit, true) }} + {{ tools.getUnitsMeasure(order.product.productInfo.unit, true, order.product.productInfo.weight) }}
-
+
+ + +
+
{{ order.quantity + order.quantitypreordered }}
@@ -86,7 +97,7 @@
- {{ (order.quantity + order.quantitypreordered) }} x € + {{ order.quantity + order.quantitypreordered }} x € {{ order.price ? order.price : 0 }} @@ -103,8 +114,8 @@ >€ {{ ( - (order.price * order.quantity) + - (order.price * order.quantitypreordered) + order.price * order.quantity + + order.price * order.quantitypreordered ).toFixed(2) }}) rec._id === id) + if (idprod >= 0 && key) { + productStore.products[idprod][key as keyof IProduct] = value + } + } + console.log('mydatatosave', mydatatosave) // @ts-ignore diff --git a/src/model/UserStore.ts b/src/model/UserStore.ts index 5f32466a..ec560771 100755 --- a/src/model/UserStore.ts +++ b/src/model/UserStore.ts @@ -224,7 +224,7 @@ export interface IUserFields { numinvitati?: number numinvitatiattivi?: number cart?: ICart - ordercart?: IOrderCart + orderscart?: IOrderCart calcstat?: ICalcStat|null account?: IAccount diff --git a/src/statics/lang/it.js b/src/statics/lang/it.js index 9d1e11ed..a13a0e7c 100755 --- a/src/statics/lang/it.js +++ b/src/statics/lang/it.js @@ -240,6 +240,7 @@ const msg_it = { ricevo_dono_long: 'Evviva!!!
QUESTO MOVIMENTO È REALE E POSSIBILE SE LO FACCIAMO FUNZIONARE TUTTI INSIEME !', }, dialog: { + azzera: 'Azzera', continue: 'Continuare', close: 'Chiudi', copyclipboard: 'Copiato negli appunti', @@ -1713,6 +1714,8 @@ const msg_it = { offerta_gas_raggiunta: 'Complimenti! Gli ordini hanno superato il minimo quantitativo di {qta} {unit}', note: 'Note', apriordine: 'Vedi Ordine', + ordine_scaduto: 'l\'Ordine è stato chiuso il {date}!', + ricarica: 'Ricarica', }, gas: { name: 'Ordine Gas', @@ -1735,6 +1738,7 @@ const msg_it = { sendmail_test: 'Invia Email TEST', email_sent: '{inviate} email inviate !', email_not_send: 'Email non inviata', + update_order: 'Aggiorna Ordine', }, cash: { creatorUserId: 'Creatore', diff --git a/src/store/Modules/tools.ts b/src/store/Modules/tools.ts index 28459d1b..3984b8ad 100644 --- a/src/store/Modules/tools.ts +++ b/src/store/Modules/tools.ts @@ -8259,18 +8259,18 @@ export const tools = { let unitrec = shared_consts.Units_Of_Measure_ListBox.find((rec: any) => rec.value === unit) let mystr = '' if (unitrec && unitrec.value === shared_consts.UNITS_OF_MEASURE.CHILI && weight && weight < 1) { - unitrec = shared_consts.Units_Of_Measure_ListBox.find((rec: any) => rec.value === shared_consts.UNITS_OF_MEASURE.GRAMMI) + unitrec = shared_consts.Units_Of_Measure_ListBox.find((rec: any) => rec.value === shared_consts.UNITS_OF_MEASURE.GRAMMI) } if (unitrec && unitrec.value === shared_consts.UNITS_OF_MEASURE.LITRI && weight && weight < 1) { - unitrec = shared_consts.Units_Of_Measure_ListBox.find((rec: any) => rec.value === shared_consts.UNITS_OF_MEASURE.MILLILITRI) + unitrec = shared_consts.Units_Of_Measure_ListBox.find((rec: any) => rec.value === shared_consts.UNITS_OF_MEASURE.MILLILITRI) } - mystr = unitrec ? (short ? unitrec.short : unitrec.label) : '' + mystr = unitrec ? (short ? unitrec.short : unitrec.label) : '' return mystr }, - getWeightByUnit(unit: number, short: boolean, weight: number|undefined) { + getWeightByUnit(unit: number, short: boolean, weight: number | undefined) { let unitrec = shared_consts.Units_Of_Measure_ListBox.find((rec: any) => rec.value === unit) - if (unitrec && unitrec.value === shared_consts.UNITS_OF_MEASURE.CHILI && weight && weight < 1) { + if (unitrec && unitrec.value === shared_consts.UNITS_OF_MEASURE.CHILI && weight && weight < 1) { return weight * 1000 } if (unitrec && unitrec.value === shared_consts.UNITS_OF_MEASURE.LITRI && weight && weight < 1) { @@ -8323,18 +8323,22 @@ export const tools = { // Calculate the difference in milliseconds const countdown = targetTime - currentDate.getTime(); - // Convert milliseconds to seconds - const countdownInSeconds = Math.floor(countdown / 1000); + if (countdown > 0) { + // Convert milliseconds to seconds + const countdownInSeconds = Math.floor(countdown / 1000); - const days = Math.floor(countdownInSeconds / (60 * 60 * 24)); - const hours = Math.floor((countdownInSeconds % (60 * 60 * 24)) / (60 * 60)); - const minutes = Math.floor((countdownInSeconds % (60 * 60)) / 60); - const seconds = countdownInSeconds % 60; + const days = Math.floor(countdownInSeconds / (60 * 60 * 24)); + const hours = Math.floor((countdownInSeconds % (60 * 60 * 24)) / (60 * 60)); + const minutes = Math.floor((countdownInSeconds % (60 * 60)) / 60); + const seconds = countdownInSeconds % 60; - const gg = days > 0 ? 'giorni' : '' - const strgg = gg ? `${days} giorni` : '' + const gg = days > 0 ? 'giorni' : '' + const strgg = gg ? `${days} giorni` : '' - return (`${strgg} ${this.pad(hours)}:${this.pad(minutes)}:${this.pad(seconds)}`); + return (`${strgg} ${this.pad(hours)}:${this.pad(minutes)}:${this.pad(seconds)}`); + } else { + return ''; + } }, diff --git a/src/store/Products.ts b/src/store/Products.ts index 03d9fbed..430248d4 100755 --- a/src/store/Products.ts +++ b/src/store/Products.ts @@ -303,8 +303,8 @@ export const useProducts = defineStore('Products', { getOrdersCartByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => { try { if (state.orders) { - const ris = state.orders.filter((ordercart: IOrderCart) => { - return ordercart.items!.some(item => { + const ris = state.orders.filter((orderscart: IOrderCart) => { + return orderscart.items!.some(item => { if (item.order) return (item.order.idProduct === idproduct) && (item.order.status! < shared_consts.OrderStatus.CHECKOUT_SENT) @@ -322,8 +322,8 @@ export const useProducts = defineStore('Products', { getOrdersCartInAttesaByIdProduct: (state: IProductsState) => (idproduct: string): IOrderCart[] | [] => { try { if (state.orders) { - const ris = state.orders.filter((ordercart: IOrderCart) => { - return ordercart.items!.some(item => { + const ris = state.orders.filter((orderscart: IOrderCart) => { + return orderscart.items!.some(item => { if (item.order) return (item.order.idProduct === idproduct) && (item.order.status! <= shared_consts.OrderStatus.CHECKOUT_SENT) @@ -435,24 +435,100 @@ export const useProducts = defineStore('Products', { return ris }, - async loadProduct({ code }: { code: any }) { + async updateOrderByOrder(idOrdersCart: string, idOrder: string, paramstoupdate: any) { + + const userStore = useUserStore() + const globalStore = useGlobalStore() + + // console.log('loadProducts') + + if (!globalStore.site.confpages.enableEcommerce) + return null + + console.log('updateOrderByOrder', 'userid=', userStore.my._id) + + let ris = null + + ris = await Api.SendReq('/orders/updateord', 'POST', { idOrdersCart, idOrder, paramstoupdate }) + .then((res) => { + let myorderscart = res.data.orderscart + if (res) { + myorderscart = res.data && res.data.orderscart ? res.data.orderscart : null + if (myorderscart) { + const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id) + if (idord >= 0) { + console.log('aggiorna ordine') + this.orders[idord] = {...myorderscart} + } + } + } + return myorderscart + }) + .catch((error) => { + console.log('error updateOrderByOrder', error) + userStore.setErrorCatch(error) + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) + }) + + // ApiTables.aftercalling(ris, checkPending, 'categories') + + return ris + }, + + async updateOrdersCartById(idOrdersCart: string, paramstoupdate: any) { + + const userStore = useUserStore() + const globalStore = useGlobalStore() + + // console.log('loadProducts') + + if (!globalStore.site.confpages.enableEcommerce) + return null + + console.log('updateOrdersCartById', 'userid=', userStore.my._id) + + let ris = null + + ris = await Api.SendReq('/orders/update', 'POST', { idOrdersCart, paramstoupdate }) + .then((res) => { + let myorderscart = res.data.orderscart + if (res) { + if (myorderscart) { + const idord = this.orders.findIndex((ord: IOrderCart) => ord._id === myorderscart._id) + if (idord >= 0) { + console.log('aggiorna orderscart') + this.orders[idord] = myorderscart + } + } + } + return myorderscart + }) + .catch((error) => { + console.log('error updateOrderByOrder', error) + userStore.setErrorCatch(error) + return new Types.AxiosError(serv_constants.RIS_CODE_ERR, null, toolsext.ERR_GENERICO, error) + }) + + // ApiTables.aftercalling(ris, checkPending, 'categories') + + return ris + }, + + async loadProductById(id: string) { - console.log('loadProduct', code) const userStore = useUserStore() const globalStore = useGlobalStore() if (!globalStore.site.confpages.enableEcommerce) return null - console.log('getProduct', 'code', code) - // if (userStore.my._id === '') { // return new Types.AxiosError(0, null, 0, '') // } let ris = null - ris = await Api.SendReq('/products/' + code, 'POST', { code }) + ris = await Api.SendReq('/products/id/' + id, 'GET', null) .then((res) => { console.log('product', res.data.product) if (res.data.product) { // console.log('RISULTANTE CATEGORIES DAL SERVER = ', res.data.categories) diff --git a/src/views/ecommerce/orderInfo/orderInfo.ts b/src/views/ecommerce/orderInfo/orderInfo.ts index 2ee0d469..668c3142 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.ts +++ b/src/views/ecommerce/orderInfo/orderInfo.ts @@ -221,8 +221,8 @@ export default defineComponent({ function updateorders() { myorderscart.value = getOrdersCart() if (myorderscart.value) { - for (const ordercart of myorderscart.value) { - myarrrec.value[ordercart._id] = Object.keys(ordercart) + for (const orderscart of myorderscart.value) { + myarrrec.value[orderscart._id] = Object.keys(orderscart) } } diff --git a/src/views/ecommerce/orderInfo/orderInfo.vue b/src/views/ecommerce/orderInfo/orderInfo.vue index 35039144..99bd8485 100755 --- a/src/views/ecommerce/orderInfo/orderInfo.vue +++ b/src/views/ecommerce/orderInfo/orderInfo.vue @@ -300,14 +300,14 @@