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">
|
|
|
|
<div class="text-h6 col-6">
|
|
|
|
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>
|
|
|
|
</q-card-section>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { ref, computed, defineComponent, onBeforeMount } from '@vue/composition-api';
|
|
|
|
import UserSelector from 'src/plugins/user/components/UserSelector.vue';
|
2021-01-26 15:37:45 +00:00
|
|
|
import { StateInterfaceBalance } from '../store/balance';
|
2021-01-21 13:24:46 +00:00
|
|
|
import { Store } from 'vuex';
|
|
|
|
|
|
|
|
interface Props {
|
2021-01-26 15:37:45 +00:00
|
|
|
showSelector: boolean;
|
2021-01-21 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'BalanceHeader',
|
|
|
|
components: { UserSelector },
|
|
|
|
props: ['showSelector'],
|
|
|
|
setup(props: Props, { root, emit }) {
|
|
|
|
onBeforeMount(() => void store.dispatch('balance/getBalance'));
|
|
|
|
const store = <Store<StateInterfaceBalance>>root.$store;
|
|
|
|
const user = ref(<FG.User>store.state.user.currentUser);
|
2021-01-26 15:37:45 +00:00
|
|
|
const balance = computed(() => {
|
|
|
|
const balances = store.state.balance.balances;
|
|
|
|
return balances.get(user.value.userid) || { balance: 0, limit: null };
|
|
|
|
});
|
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);
|
|
|
|
user.value = selectedUser;
|
|
|
|
emit('update:user', selectedUser);
|
2021-01-21 13:24:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return { user, balance, isLocked, userUpdated };
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|