Conto Comunitario...

This commit is contained in:
Surya Paolo
2023-01-12 01:03:19 +01:00
parent 2acf161d5d
commit 3d77cf671d
21 changed files with 436 additions and 65 deletions

View File

@@ -8,6 +8,7 @@ import { useCircuitStore } from '@store/CircuitStore'
import { useQuasar } from 'quasar'
import { useI18n } from '@/boot/i18n'
import { CMyUserOnlyView } from '@/components/CMyUserOnlyView'
import { CMyGroupOnlyView } from '@/components/CMyGroupOnlyView'
import { costanti } from '@costanti'
export default defineComponent({
@@ -22,6 +23,11 @@ export default defineComponent({
type: String,
default: ''
},
qtydefault: {
type: String,
required: false,
default: '1'
},
to_user: {
type: Object as PropType<IUserFields>,
required: false,
@@ -38,7 +44,7 @@ export default defineComponent({
default: null,
},
},
components: { CSaldo, CMyUserOnlyView },
components: { CSaldo, CMyUserOnlyView, CMyGroupOnlyView },
setup(props, { emit }) {
const $q = useQuasar()
@@ -48,18 +54,22 @@ export default defineComponent({
const circuitStore = useCircuitStore()
const from_username = ref(userStore.my.username)
const from_groupname = ref('')
const circuitsel = ref('')
const qty = ref(<string | number>'')
const causal = ref('')
const bothcircuits = ref(<any>[])
const groupSel = ref(<IMyGroup | null | undefined>null)
const circuitloaded = ref(<ICircuit | undefined>undefined)
const circuitdest = ref(<ICircuit | undefined>undefined)
const accountloaded = ref(<IAccount | undefined>undefined)
const accountloaded = ref(<IAccount | undefined | null>undefined)
const accountdest = ref(<IAccount | undefined>undefined)
const remainingCoins = ref(0)
const maxsendable = ref(0)
const numstep = ref(0)
const tipoConto = ref(0)
const priceLabel = computed(() => circuitloaded.value ? `${qty.value} ` + circuitloaded.value.symbol : '')
const arrayMarkerLabel = ref(<any>[])
@@ -67,20 +77,52 @@ export default defineComponent({
const qtyRef = ref(<any>null)
const causalRef = ref(<any>null)
const groupsListAdmin = ref(<IMyGroup[]>[])
const arrGroupsList = ref(<any[]>[])
watch(() => circuitsel.value, (newval, oldval) => {
tools.setCookie(tools.CIRCUIT_USE, newval)
aggiorna()
})
watch(() => tipoConto.value, (newval, oldval) => {
aggiorna()
})
watch(() => from_groupname.value, (newval, oldval) => {
aggiorna()
})
watch(() => from_username.value, (newval, oldval) => {
aggiorna()
})
watch(() => props.showprop, (newval, oldval) => {
console.log('props.showprop', props.showprop, newval)
show.value = newval
})
function aggiorna() {
groupSel.value = null
accountloaded.value = null
circuitloaded.value = circuitStore.listcircuits.find((rec: ICircuit) => rec.name === circuitsel.value)
if (circuitloaded.value) {
accountloaded.value = userStore.getAccountByCircuitId(circuitloaded.value._id)
if (tipoConto.value === costanti.AccountType.USER) {
accountloaded.value = userStore.getAccountByCircuitId(circuitloaded.value._id)
} else if (tipoConto.value === costanti.AccountType.COMMUNITY_ACCOUNT) {
groupSel.value = userStore.my.profile.manage_mygroups.find((group: IMyGroup) => from_groupname.value === group.groupname)
accountloaded.value = groupSel.value ? groupSel.value.account : null
}
groupsListAdmin.value = userStore.GroupsListWhereIAmAdmin()
arrGroupsList.value = []
for (const group of groupsListAdmin.value) {
arrGroupsList.value.push({ label: group.groupname, value: group.groupname });
}
// accountdest.value = userStore.getAccountByCircuitId(circuitloaded.value._id)
if (accountloaded.value) {
remainingCoins.value = circuitStore.getRemainingCoinsToSend(accountloaded.value)
@@ -132,6 +174,8 @@ export default defineComponent({
circuitsel.value = bothcircuits.value[0]
}
qty.value = props.qtydefault
aggiorna()
show.value = true
@@ -191,6 +235,8 @@ export default defineComponent({
}
}
onMounted(mounted)
return {
@@ -217,6 +263,9 @@ export default defineComponent({
numstep,
costanti,
userStore,
tipoConto,
arrGroupsList,
from_groupname,
}
},
})

View File

@@ -1,6 +1,11 @@
<template>
<div>
<q-dialog v-model="show" :maximized="$q.screen.lt.sm" @hide="hide" @show="qtyRef ? qtyRef.focus() : ''">
<q-dialog
v-model="show"
:maximized="$q.screen.lt.sm"
@hide="hide"
@show="qtyRef ? qtyRef.focus() : ''"
>
<q-card class="dialog_card">
<q-toolbar class="bg-primary text-white">
<q-toolbar-title>
@@ -9,9 +14,14 @@
<q-btn flat round color="white" icon="close" v-close-popup></q-btn>
</q-toolbar>
<q-card-section class="q-pa-xs inset-shadow">
<q-select
:behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'" rounded outlined v-model="circuitsel" :options="bothcircuits" label="Circuito">
:behavior="$q.platform.is.ios === true ? 'dialog' : 'menu'"
rounded
outlined
v-model="circuitsel"
:options="bothcircuits"
label="Circuito"
>
</q-select>
<CSaldo
@@ -19,14 +29,58 @@
:symbol="circuitloaded.symbol"
:color="circuitloaded.color"
:saldo="accountloaded ? accountloaded.saldo : 0"
:qtarem="accountloaded ? circuitStore.getRemainingCoinsToSend(accountloaded) : 0"
>
:qtarem="
accountloaded
? circuitStore.getRemainingCoinsToSend(accountloaded)
: 0
"
>
</CSaldo>
<q-input v-model="from_username" label="Mittente" class="full-width" readonly>
<div>
<q-btn-toggle
v-model="tipoConto"
class="my-custom-toggle"
no-caps
rounded
unelevated
toggle-color="primary"
color="white"
text-color="primary"
:options="[
{ label: 'Utente', value: costanti.AccountType.USER },
{
label: 'Conto Comunitario',
value: costanti.AccountType.COMMUNITY_ACCOUNT,
},
]"
/>
</div>
<q-input
v-if="tipoConto === costanti.AccountType.USER"
v-model="from_username"
label="Mittente"
class="full-width"
readonly
>
</q-input>
<div v-else>
<q-select
v-model="from_groupname"
:options="arrGroupsList"
label="Gruppo"
rounded
emit-value
map-options
>
<!-- Mostra i gruppi su cui sei Admin -->
</q-select>
</div>
<!-- Destination -->
<CMyUserOnlyView
v-if="to_user"
:mycontact="to_user"
:visu="costanti.FIND_PEOPLE"
@setCmd="tools.setCmd"
@@ -34,44 +88,77 @@
>
</CMyUserOnlyView>
<CMyGroupOnlyView v-if="to_group" :mygrp="to_group" :visu="costanti.USER_GROUPS"
:circuitname="circuitloaded.name"
labelextra="Destinatario">
</CMyGroupOnlyView>
<div v-if="circuitloaded">
<q-banner
v-if="!circuitloaded.transactionsEnabled"
rounded
class="bg-red text-white"
style="text-align: center;"
style="text-align: center"
>
<em style="font-weight: bold">{{ $t('circuit.transactionsEnabled_text') }}</em><br>
<em style="font-weight: bold">{{
$t('circuit.transactionsEnabled_text')
}}</em
><br />
</q-banner>
<q-input
ref="qtyRef"
class="q-py-sm text-h5"
outlined v-model="qty" type="number"
outlined
v-model="qty"
type="number"
:rules="[
val => val <= circuitStore.getRemainingCoinsToSend(accountloaded) || t('circuit.qta_remaining_to_send', { maxqta: circuitStore.getRemainingCoinsToSend(accountloaded), symbol: circuitloaded.symbol }),
val => val > 0 || t('circuit.qta_not_valid')]"
:label="t('movement.amount_to_send', {qtamax: circuitStore.getRemainingCoinsToSend(accountloaded) ? circuitStore.getRemainingCoinsToSend(accountloaded).toFixed(2) : 0 + ` ` + circuitloaded.symbol})"
(val) =>
val <= circuitStore.getRemainingCoinsToSend(accountloaded) ||
t('circuit.qta_remaining_to_send', {
maxqta: circuitStore.getRemainingCoinsToSend(accountloaded),
symbol: circuitloaded.symbol,
}),
(val) => val > 0 || t('circuit.qta_not_valid'),
]"
:label="
t('movement.amount_to_send', {
qtamax: circuitStore.getRemainingCoinsToSend(accountloaded)
? circuitStore
.getRemainingCoinsToSend(accountloaded)
.toFixed(2)
: 0 + ` ` + circuitloaded.symbol,
})
"
input-class="text-right"
v-on:keyup.enter="$event.target.nextElementSibling.focus()"
>
<!--val => val > circuitStore.getMaxCoinsToSend(accountloaded) || t('circuit.qta_max_to_send', { maxqta: tools.getRemainingCoinsToSend(accountloaded), symbol: circuitloaded.symbol })]" -->
<template v-slot:append>
<div class="text-h5">
<em class="q-px-sm text-white rounded-borders"
:style="`background-color: ` + (circuitloaded.color ? circuitloaded.color : '#ff5500')">{{ circuitloaded.symbol }}</em>
<em
class="q-px-sm text-white rounded-borders"
:style="
`background-color: ` +
(circuitloaded.color ? circuitloaded.color : '#ff5500')
"
>{{ circuitloaded.symbol }}</em
>
</div>
</template>
</q-input>
<q-slider
class="q-ma-xs"
v-if="(qty !== '') && circuitStore.getRemainingCoinsToSend(accountloaded) > 0"
v-if="
qty !== '' &&
circuitStore.getRemainingCoinsToSend(accountloaded) > 0
"
v-model="qty"
color="green"
markers
track-size="10px"
:step="numstep/2"
:step="numstep / 2"
:marker-labels="arrayMarkerLabel"
label-always
:label-value="priceLabel"
@@ -79,23 +166,42 @@
switch-marker-labels-side
:inner-max="remainingCoins"
:min="0"
:max="Number(maxsendable ? maxsendable: 0)"
:max="Number(maxsendable ? maxsendable : 0)"
/>
</div>
<q-input
ref="causalRef"
v-model="causal" label="Note" class="q-my-sm full-width">
v-model="causal"
label="Note"
class="q-my-sm full-width"
>
</q-input>
</q-card-section>
<q-card-actions align="center">
<q-btn
v-if="circuitloaded"
:disable="qtyRef ? (qtyRef.hasError || !circuitloaded.transactionsEnabled) : false"
:label="$t('circuit.sendcoinsto', {qty, coin: circuitsel, dest: to_group ? to_group.groupname : to_user.username })" color="positive"
@click="sendCoin()"></q-btn>
<q-btn flat :label="$t('dialog.cancel')" color="primary" v-close-popup></q-btn>
:disable="
qtyRef
? qtyRef.hasError || !circuitloaded.transactionsEnabled
: false
"
:label="
$t('circuit.sendcoinsto', {
qty,
coin: circuitsel,
dest: to_group ? to_group.groupname : to_user.username,
})
"
color="positive"
@click="sendCoin()"
></q-btn>
<q-btn
flat
:label="$t('dialog.cancel')"
color="primary"
v-close-popup
></q-btn>
</q-card-actions>
</q-card>
</q-dialog>