corretto problema che si aggiornava a fatica... si bloccava... era una label che veniva continuamente azzerata e riscritta...

This commit is contained in:
Surya Paolo
2024-02-09 00:25:51 +01:00
parent 288318fdb6
commit aa108d9213
8 changed files with 141 additions and 29 deletions

View File

@@ -672,7 +672,7 @@ export default defineComponent({
sortBy = sortBy + '' sortBy = sortBy + ''
// descending = descending + '' // descending = descending + ''
let arrsort = (sortBy && sortBy.indexOf(',') > 0) ? sortBy.split(',') : []; let arrsort = (sortBy && sortBy.indexOf(',') > 0) ? sortBy.split(',') : [];
let arrdescending = (descending && descending.lenght > 1 && descending.indexOf(',') > 0) ? descending.split(',') : []; let arrdescending = (descending && descending.length > 1 && descending.indexOf(',') > 0) ? descending.split(',') : [];
if (arrsort.length > 0) { if (arrsort.length > 0) {
for (let i = 0; i < arrsort.length; i++) { for (let i = 0; i < arrsort.length; i++) {
let field = arrsort[i].trim() let field = arrsort[i].trim()

View File

@@ -652,7 +652,7 @@ export default defineComponent({
sortBy = sortBy + '' sortBy = sortBy + ''
// descending = descending + '' // descending = descending + ''
let arrsort = (sortBy && sortBy.indexOf(',') > 0) ? sortBy.split(',') : []; let arrsort = (sortBy && sortBy.indexOf(',') > 0) ? sortBy.split(',') : [];
let arrdescending = (descending && descending.lenght > 1 && descending.indexOf(',') > 0) ? descending.split(',') : []; let arrdescending = (descending && descending.length > 1 && descending.indexOf(',') > 0) ? descending.split(',') : [];
if (arrsort.length > 0) { if (arrsort.length > 0) {
for (let i = 0; i < arrsort.length; i++) { for (let i = 0; i < arrsort.length; i++) {
let field = arrsort[i].trim() let field = arrsort[i].trim()

View File

@@ -98,12 +98,6 @@ export default defineComponent({
const scale = ref(1) const scale = ref(1)
const valoriopt = computed(() => (item: any, addall: boolean, addnone: boolean) => {
// console.log('valoriopt', item.table)
return globalStore.getTableJoinByName(item.table, addall, addnone, item.filter)
})
watch(() => editOn.value, (to: any, from: any) => { watch(() => editOn.value, (to: any, from: any) => {
if (!editOn.value) if (!editOn.value)
ricarica() ricarica()
@@ -266,15 +260,26 @@ export default defineComponent({
}) })
function updateLabel() { function updateLabel() {
if (myproduct.value.gasordine) { let dataArrivoMerce = ''
if (myproduct.value.gasordine.data_arrivo_merce) let dataRitiro = ''
labelDataArrivoMerce.value = tools.getstrDateShort(myproduct.value.gasordine.data_arrivo_merce) try {
if (myproduct.value.gasordine.dataora_ritiro) if (myproduct.value && myproduct.value.gasordine) {
labelDataRitiro.value = tools.getstrDateTime(myproduct.value.gasordine.dataora_ritiro) if (myproduct.value.gasordine.data_arrivo_merce)
} else { dataArrivoMerce = tools.getstrDateShort(myproduct.value.gasordine.data_arrivo_merce)
labelDataArrivoMerce.value = '' if (myproduct.value.gasordine.dataora_ritiro)
labelDataRitiro.value = '' dataRitiro = tools.getstrDateTime(myproduct.value.gasordine.dataora_ritiro)
} else {
dataArrivoMerce = ''
dataRitiro = ''
}
} catch (e) {
} }
if (labelDataArrivoMerce.value !== dataArrivoMerce)
labelDataArrivoMerce.value = dataArrivoMerce
if (labelDataRitiro.value !== dataRitiro)
labelDataRitiro.value = dataRitiro
updateTimerLabel() updateTimerLabel()
} }
@@ -291,7 +296,7 @@ export default defineComponent({
} }
function updateTimerLabel() { function updateTimerLabel() {
if (myproduct.value.gasordine && myproduct.value.gasordine._id && myproduct.value.gasordine.dataora_chiusura_ordini) if (myproduct.value && myproduct.value.gasordine && myproduct.value.gasordine._id && myproduct.value.gasordine.dataora_chiusura_ordini)
timerLabelScadenza.value = tools.getCountDown(myproduct.value.gasordine.dataora_chiusura_ordini) timerLabelScadenza.value = tools.getCountDown(myproduct.value.gasordine.dataora_chiusura_ordini)
else else
timerLabelScadenza.value = '' timerLabelScadenza.value = ''
@@ -304,12 +309,14 @@ export default defineComponent({
function startTimer() { function startTimer() {
// Update the timer label every second // Update the timer label every second
timerInterval.value = setInterval(() => updateTimerLabel(), 1000); timerInterval.value = setInterval(() => updateTimerLabel(), 60000);
} }
function load() { function load() {
initproduct() initproduct()
updateproduct() updateproduct()
labelDataArrivoMerce.value = ''
labelDataRitiro.value = ''
// console.log('Load', myproduct.value.name) // console.log('Load', myproduct.value.name)
// console.log('created Cproductcard', code) // console.log('created Cproductcard', code)

View File

@@ -637,6 +637,7 @@
</q-item-label> </q-item-label>
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-item <q-item
v-if=" v-if="
myproduct.gasordine && myproduct.gasordine &&

View File

@@ -2097,12 +2097,6 @@ export const colTableProducts = [
fieldtype: costanti.FieldType.select, fieldtype: costanti.FieldType.select,
jointable: 'gasordines', jointable: 'gasordines',
}), }),
AddCol({
name: 'idGasordine',
label_trans: 'gas.name',
fieldtype: costanti.FieldType.select,
jointable: 'gasordines',
}),
AddCol({ AddCol({
name: 'idProvider', name: 'idProvider',
label_trans: 'provider.name', label_trans: 'provider.name',

View File

@@ -8354,6 +8354,31 @@ export const tools = {
// Calculate the difference in milliseconds // Calculate the difference in milliseconds
const countdown = targetTime - currentDate.getTime(); const countdown = targetTime - currentDate.getTime();
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 gg = days > 0 ? 'giorni' : ''
const strgg = gg ? `${days} giorni` : ''
return (`${strgg} ${this.pad(hours)}h ${this.pad(minutes)}m`);
} else {
return '';
}
},
getCountDownWithSeconds(mydate: Date) {
const currentDate = new Date();
const targetTime = new Date(mydate).getTime();
// Calculate the difference in milliseconds
const countdown = targetTime - currentDate.getTime();
if (countdown > 0) { if (countdown > 0) {
// Convert milliseconds to seconds // Convert milliseconds to seconds
const countdownInSeconds = Math.floor(countdown / 1000); const countdownInSeconds = Math.floor(countdown / 1000);

View File

@@ -32,14 +32,26 @@ export default defineComponent({
const cat = ref('') const cat = ref('')
const loadpage = ref(false) const loadpage = ref(false)
const refreshpage = ref(false) const refreshpage = ref(false)
const show_hide = ref(false)
const arrProducts = ref<any>([]) const arrProducts = ref<any>([])
const numRecLoaded = ref(0)
// Create a ref for the component to fix // Create a ref for the component to fix
const componentToFixRef = ref(<any>null); const componentToFixRef = ref(<any>null);
const isFixed = ref(false); const isFixed = ref(false);
const arrLoaded = computed(() => {
if (arrProducts.value && numRecLoaded.value)
return arrProducts.value.slice(0, numRecLoaded.value)
else {
return []
}
})
// Register the scroll event on component mount // Register the scroll event on component mount
const handleScroll = () => { const handleScroll = () => {
const scrollTop = window.scrollY || document.documentElement.scrollTop; const scrollTop = window.scrollY || document.documentElement.scrollTop;
@@ -69,6 +81,8 @@ export default defineComponent({
}) })
function calcArrProducts() { function calcArrProducts() {
console.log('calcArrProducts')
refreshpage.value = true refreshpage.value = true
let arrprod = productStore.getProducts(cosa.value) let arrprod = productStore.getProducts(cosa.value)
let catstr = cat.value; let catstr = cat.value;
@@ -93,6 +107,7 @@ export default defineComponent({
} }
arrProducts.value = arrprod arrProducts.value = arrprod
loaddata()
refreshpage.value = false refreshpage.value = false
} }
@@ -121,6 +136,12 @@ export default defineComponent({
window.addEventListener('scroll', handleScroll); window.addEventListener('scroll', handleScroll);
calcArrProducts() calcArrProducts()
loaddata()
}
function loaddata() {
numRecLoaded.value = 20
} }
// Remove the event listener on component destroy // Remove the event listener on component destroy
@@ -138,6 +159,26 @@ export default defineComponent({
return riscat return riscat
} }
function onLoadScroll(index: number, done: any) {
if (index >= 1) {
if (numRecLoaded.value < arrProducts.value.length) {
const step = 10
let mynrec = numRecLoaded.value + step
if (mynrec > arrProducts.value.length)
mynrec = arrProducts.value.length
numRecLoaded.value = mynrec
done()
}
} else {
done(true)
}
}
onMounted(mounted) onMounted(mounted)
return { return {
@@ -157,6 +198,10 @@ export default defineComponent({
componentToFixRef, componentToFixRef,
isFixed, isFixed,
arrProducts, arrProducts,
show_hide,
onLoadScroll,
numRecLoaded,
arrLoaded,
} }
} }
}) })

View File

@@ -116,14 +116,54 @@
}) })
}}</span> }}</span>
</div> </div>
<div class="row justify-around" v-if="tools.isManager()">
<q-toggle
v-model="show_hide"
push
label="Mostra Nascosti"
rounded
glossy
toggle-color="primary"
></q-toggle>
</div>
<div class="row justify-around"> <div class="row justify-around">
<div <q-infinite-scroll
v-if="arrLoaded && arrLoaded.length > 0"
ref="myinfscroll"
:initial-index="0"
@load="onLoadScroll"
:offset="2000"
debounce="200"
class="q-pa-xs row items-start" class="q-pa-xs row items-start"
v-for="(product, index) in arrProducts"
:key="index"
> >
<CProductCard :id="product._id" :complete="false" :cosa="cosa" /> <div
</div> class="q-pa-xs"
v-for="(product, index) in arrLoaded"
:key="index"
>
<CProductCard
v-if="product.active || show_hide"
:id="product._id"
:complete="false"
:cosa="cosa"
/>
</div>
<template v-slot:loading>
<div class="text-center">
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
<br />
<q-btn
dense
size="md"
color="primary"
rounded
label="Vedi altri Prodotti..."
@click="numRecLoaded += 10"
>
</q-btn>
</div> </div>
</div> </div>
</div> </div>