baruser cann add amount to a user

This commit is contained in:
Tim Gröger 2019-12-21 13:16:37 +01:00
parent e59429ddd6
commit 9e32270f10
3 changed files with 31 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<template>
<v-content>
<v-container>
<v-card v-for="user in users" :key="user.id" raised shaped>
<v-container v-for="user in users" :key="user.id">
<v-card raised shaped>
<v-list-item three-line>
<v-list-item-content>
@ -56,7 +56,7 @@
<v-container>
<v-row>
<v-container>
<v-list-item-action-text class="title">{{(user.amount/100).toFixed(2)}} </v-list-item-action-text>
<v-list-item-action-text :class="getColor(user.type)">{{(user.amount/100).toFixed(2)}} </v-list-item-action-text>
</v-container>
</v-row>
</v-container>
@ -70,6 +70,7 @@
</template>
<script>
export default {
name: "CreditLists",
props: {
@ -83,7 +84,14 @@
methods: {
addAmount(username, amount) {
this.$emit("add:amount", username, amount)
},
getColor(type) {
return type === 'credit' ? 'title green--text' : 'title red--text'
}
},
computed: {
}
}
</script>

View File

@ -15,7 +15,9 @@ class Service {
return axios.get(this.url+'bar', {headers: {Token: token}})
}
addAmountBar(token, data) {
return axios.post(this.url+'baradd', ...data, {headers: {Token: token}})
// eslint-disable-next-line no-console
console.log("addAmountdata: ", data)
return axios.post(this.url+'baradd', {...data}, {headers: {Token: token}})
}
}

View File

@ -9,6 +9,7 @@
import TitleBar from "@/components/TitleBar";
import CreditLists from "@/components/baruser/CreditLists";
import httpClient from "../plugins/restService";
// eslint-disable-next-line no-unused-vars
import axios from "axios";
export default {
name: "BarView",
@ -24,6 +25,7 @@
methods: {
getUser() {
// eslint-disable-next-line no-console
this. users = []
httpClient.getUserBar(this.$store.getters.getToken)
.then(response => {
// eslint-disable-next-line no-console
@ -35,27 +37,33 @@
username: response.data[user].username,
firstname: response.data[user].firstname,
lastname: response.data[user].lastname,
amount: response.data[user].amount
amount: response.data[user].amount,
type: response.data[user].type
})
}
})
.catch(error => {
// eslint-disable-next-line no-console
console.log(error)
this.$store.dispatch("logout")
this.users = []
})
},
// eslint-disable-next-line no-unused-vars
addAmount(username, amount) {
axios.post('http://192.168.5.118:5000/baradd', {userId: username, amount: amount}, {headers: {Token: this.$store.getters.getToken}})
//httpClient.addAmountBar(this.$store.getters.getToken, {username: username, amount: amount})
/*.then(response => {
httpClient.addAmountBar(this.$store.getters.getToken, {userId: username, amount: amount})
.then((response) => {
// eslint-disable-next-line no-console
console.log("responsedata: ", response.data)
console.log(response.data)
let user = this.users.find(user => {
// eslint-disable-next-line no-console
console.log(user)
return user.username === username ? user : false
})
user.amount = response.data.amount
})
.catch(error => {
// eslint-disable-next-line no-console
console.log("error: ", error.response.data.error)
})*/
}
}
}