2021-01-21 13:24:46 +00:00
|
|
|
<template>
|
|
|
|
<q-card-section class="fit row justify-left content-center items-center q-col-gutter-sm">
|
2021-01-29 21:57:10 +00:00
|
|
|
<div class="text-h6 col-5">
|
2021-01-21 13:24:46 +00:00
|
|
|
Aktueller Stand: {{ balance.balance.toFixed(2) }} €
|
|
|
|
<q-badge color="negative" align="top" v-if="isLocked"> gesperrt </q-badge>
|
|
|
|
</div>
|
|
|
|
<div v-if="showSelector" class="col-6">
|
|
|
|
<UserSelector :user="user" @update:user="userUpdated" />
|
|
|
|
</div>
|
2021-01-29 21:57:10 +00:00
|
|
|
<div class="col-1 justify-end">
|
|
|
|
<q-btn round flat icon="mdi-format-list-checks" @click="openHistory" />
|
|
|
|
</div>
|
2021-01-21 13:24:46 +00:00
|
|
|
</q-card-section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 03:16:17 +00:00
|
|
|
import { ref, computed, defineComponent, onBeforeMount } from 'vue';
|
2021-01-21 13:24:46 +00:00
|
|
|
import UserSelector from 'src/plugins/user/components/UserSelector.vue';
|
2021-01-31 21:01:38 +00:00
|
|
|
import { StateInterfaceBalance, UserBalance } from '../store/balance';
|
2021-01-31 21:21:49 +00:00
|
|
|
import { useStore, mapGetters } from 'vuex';
|
2021-01-21 13:24:46 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'BalanceHeader',
|
|
|
|
components: { UserSelector },
|
2021-01-31 21:21:49 +00:00
|
|
|
props: { showSelector: Boolean },
|
|
|
|
emits: { 'update:user': (u: FG.User) => !!u, 'open-history': () => true },
|
2021-01-31 21:01:38 +00:00
|
|
|
setup(_, { emit }) {
|
2021-01-21 13:24:46 +00:00
|
|
|
onBeforeMount(() => void store.dispatch('balance/getBalance'));
|
2021-01-31 19:40:18 +00:00
|
|
|
const store = useStore<StateInterfaceBalance>();
|
2021-01-31 21:01:38 +00:00
|
|
|
const userGetters = mapGetters('users', ['currentUser']);
|
|
|
|
const balanceGetters = mapGetters('balance', ['balances']);
|
2021-01-31 21:21:49 +00:00
|
|
|
const user = ref(<FG.User>userGetters.currentUser());
|
2021-01-26 15:37:45 +00:00
|
|
|
const balance = computed(() => {
|
2021-01-31 21:01:38 +00:00
|
|
|
return (
|
|
|
|
(<Map<string, UserBalance>>balanceGetters.balances()).get(user.value.userid) || {
|
|
|
|
balance: 0,
|
|
|
|
limit: null,
|
|
|
|
}
|
|
|
|
);
|
2021-01-26 15:37:45 +00:00
|
|
|
});
|
2021-01-21 13:24:46 +00:00
|
|
|
|
2021-01-26 15:37:45 +00:00
|
|
|
const isLocked = computed(
|
|
|
|
() => balance.value.limit !== null && balance.value.balance >= balance.value.limit
|
|
|
|
);
|
2021-01-21 13:24:46 +00:00
|
|
|
|
|
|
|
function userUpdated(selectedUser: FG.User) {
|
2021-01-26 15:37:45 +00:00
|
|
|
void store.dispatch('balance/getBalance', selectedUser);
|
2021-01-31 21:21:49 +00:00
|
|
|
user.value = selectedUser;
|
2021-01-26 15:37:45 +00:00
|
|
|
emit('update:user', selectedUser);
|
2021-01-21 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 21:57:10 +00:00
|
|
|
function openHistory() {
|
|
|
|
emit('open-history');
|
|
|
|
}
|
|
|
|
|
|
|
|
return { user, balance, isLocked, userUpdated, openHistory };
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
2021-01-21 13:24:46 +00:00
|
|
|
});
|
|
|
|
</script>
|