| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  | <template> | 
					
						
							|  |  |  |     <div> | 
					
						
							|  |  |  |         <TitleBar/> | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |         <v-content> | 
					
						
							|  |  |  |             <SearchBar @add:creditList="addCreditList"/> | 
					
						
							|  |  |  |             <CreditLists v-bind:users="users" @add:amount="addAmount"></CreditLists> | 
					
						
							|  |  |  |         </v-content> | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |     </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  |     import TitleBar from "@/components/TitleBar"; | 
					
						
							|  |  |  |     import CreditLists from "@/components/baruser/CreditLists"; | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |     import httpClient from "../plugins/restService"; | 
					
						
							| 
									
										
										
										
											2019-12-21 12:16:37 +00:00
										 |  |  |     // eslint-disable-next-line no-unused-vars
 | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |     import axios from "axios"; | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |     import SearchBar from "../components/baruser/SearchBar"; | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |     export default { | 
					
						
							|  |  |  |         name: "BarView", | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |         components: {SearchBar, CreditLists, TitleBar}, | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |         created() { | 
					
						
							|  |  |  |             this.getUser() | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |         data () { | 
					
						
							|  |  |  |             return { | 
					
						
							|  |  |  |                 users: [] | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |         methods: { | 
					
						
							|  |  |  |             getUser() { | 
					
						
							| 
									
										
										
										
											2019-12-21 12:16:37 +00:00
										 |  |  |                 this. users = [] | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |                 httpClient.getUserBar(this.$store.getters.getToken) | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |                 .then(response => { | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |                     for (let user in response.data) { | 
					
						
							|  |  |  |                         const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0 | 
					
						
							|  |  |  |                         this.users.push({ | 
					
						
							|  |  |  |                             id: lastId + 1, | 
					
						
							|  |  |  |                             username: response.data[user].username, | 
					
						
							|  |  |  |                             firstname: response.data[user].firstname, | 
					
						
							|  |  |  |                             lastname: response.data[user].lastname, | 
					
						
							| 
									
										
										
										
											2019-12-29 11:37:46 +00:00
										 |  |  |                             locked: response.data[user].locked, | 
					
						
							| 
									
										
										
										
											2019-12-21 12:16:37 +00:00
										 |  |  |                             amount: response.data[user].amount, | 
					
						
							|  |  |  |                             type: response.data[user].type | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |                         }) | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |                 }) | 
					
						
							|  |  |  |                 .catch(error => { | 
					
						
							| 
									
										
										
										
											2019-12-28 21:33:37 +00:00
										 |  |  |                     if (error.response) { | 
					
						
							| 
									
										
										
										
											2019-12-29 11:37:46 +00:00
										 |  |  |                         if (error.response.status === 401) { | 
					
						
							| 
									
										
										
										
											2019-12-28 21:33:37 +00:00
										 |  |  |                             this.$store.dispatch('logout') | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |                     this.users = [] | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |                 this.users = this.users.sort((a,b) => { | 
					
						
							|  |  |  |                     if (a.username > b.username) return 1 | 
					
						
							|  |  |  |                     if (a.username < b.username) return -1 | 
					
						
							|  |  |  |                     return 0 | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2019-12-21 12:16:37 +00:00
										 |  |  |             // eslint-disable-next-line no-unused-vars
 | 
					
						
							| 
									
										
										
										
											2019-12-21 11:22:21 +00:00
										 |  |  |             addAmount(username, amount) { | 
					
						
							| 
									
										
										
										
											2019-12-21 12:16:37 +00:00
										 |  |  |                 httpClient.addAmountBar(this.$store.getters.getToken, {userId: username, amount: amount}) | 
					
						
							|  |  |  |                 .then((response) => { | 
					
						
							|  |  |  |                     let user = this.users.find(user => { | 
					
						
							|  |  |  |                         return user.username === username ? user : false | 
					
						
							|  |  |  |                     }) | 
					
						
							|  |  |  |                     user.amount = response.data.amount | 
					
						
							| 
									
										
										
										
											2019-12-29 16:56:50 +00:00
										 |  |  |                     user.locked = response.data.locked | 
					
						
							| 
									
										
										
										
											2019-12-29 20:57:18 +00:00
										 |  |  |                     user.type = response.data.type | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2019-12-28 21:33:37 +00:00
										 |  |  |                 .catch(error => { | 
					
						
							|  |  |  |                     if (error.response) { | 
					
						
							| 
									
										
										
										
											2019-12-29 11:37:46 +00:00
										 |  |  |                         if (error.response.status === 401) { | 
					
						
							| 
									
										
										
										
											2019-12-28 21:33:37 +00:00
										 |  |  |                             this.$store.dispatch('logout') | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     this.users = [] | 
					
						
							|  |  |  |                 }) | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |             }, | 
					
						
							|  |  |  |             addCreditList(user) { | 
					
						
							|  |  |  |                 if (!this.users.find(user1 => { | 
					
						
							|  |  |  |                     return user1.username === user.username | 
					
						
							|  |  |  |                 })) { | 
					
						
							| 
									
										
										
										
											2019-12-29 16:56:50 +00:00
										 |  |  |                     httpClient.getOneUserBar(this.$store.getters.getToken, {userId: user.username}) | 
					
						
							|  |  |  |                     .then(response => { | 
					
						
							|  |  |  |                         const lastId = this.users.length > 0 ? this.users[this.users.length - 1].id : 0 | 
					
						
							|  |  |  |                         this.users.push({ | 
					
						
							|  |  |  |                             id: lastId + 1, | 
					
						
							|  |  |  |                             username: response.data.username, | 
					
						
							|  |  |  |                             firstname: response.data.firstname, | 
					
						
							|  |  |  |                             lastname: response.data.lastname, | 
					
						
							|  |  |  |                             locked: response.data.locked, | 
					
						
							| 
									
										
										
										
											2020-01-05 13:17:06 +00:00
										 |  |  |                             amount: response.data.amount, | 
					
						
							|  |  |  |                             type: response.data.type | 
					
						
							| 
									
										
										
										
											2019-12-29 16:56:50 +00:00
										 |  |  |                         }) | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |                     }) | 
					
						
							| 
									
										
										
										
											2019-12-29 16:56:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-26 09:31:36 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-12-21 07:20:25 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style scoped> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </style> |