Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. <template>
  2. <div>
  3. <div class="row">
  4. <div class="col-md-12">
  5. <h5>Todos os Empréstimos</h5>
  6. </div>
  7. </div>
  8.  
  9. <table class="table table-striped">
  10. <thead>
  11. <tr>
  12. <th>Book</th>
  13. <th>User ID</th>
  14. </tr>
  15. </thead>
  16. <tbody>
  17. <tr v-for="(loan, index) in loans" :key="index">
  18. <td>{{ loan.book.title }}</td>
  19. <td>{{ loan.user_id }}</td>
  20. <td>
  21. <div class="text-center">
  22. <button v-if="loan.status=='P' " class="btn btn-primary" @click.prevent="entregar(loan)">Entregar</button>
  23. <button v-if="loan.status=='E'" class="btn btn-primary" @click.prevent="devolver(loan)">Devolver </button>
  24. </div>
  25. </td>
  26. </tr>
  27. </tbody>
  28. </table>
  29. </div>
  30. </template>
  31.  
  32. <script>
  33. export default {
  34. props:["books","loans"],
  35. data: function () {
  36. return {
  37.  
  38.  
  39. };
  40. },
  41. methods:{
  42. loan: function(loan){
  43. axios.post('api/books/loans')
  44. // .then(response => console.log("Success"))
  45. .then(response => {
  46. console.log(response);
  47. this.$socket.emit('loanRequested', loan)
  48. })
  49. .catch(error => console.log('Whoops'));
  50. },
  51.  
  52. entregar : function(loan){
  53. if (loan.status === 'E') {
  54. this.message = "Livro Entregue";
  55. this.showMessage = true;
  56. } else {
  57. this.message = "Livro devolvido";
  58. this.showMessage = true;
  59. }
  60. axios.put("api/loans/entregar/" + loan.id).then(response => {
  61. // Copy object properties from response.data.data to this.user
  62. // without creating a new reference
  63. //Object.assign(item, response.data.data);
  64.  
  65. this.$emit('updateAll');
  66. this.$socket.emit('bookDelivered', loan)
  67. this.$socket.emit('reloadRequired')
  68.  
  69.  
  70. });
  71. },
  72. devolver : function(loan){
  73. axios.put("api/loans/devolver/" + loan.id).then(response => {
  74. // Copy object properties from response.data.data to this.user
  75. // without creating a new reference
  76. //Object.assign(item, response.data.data);
  77. this.$emit('updateAll');
  78. this.$socket.emit('bookReturned', loan)
  79. this.$socket.emit('reloadRequired')
  80.  
  81. });
  82. }
  83.  
  84.  
  85. },
  86. }
  87. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement