index.blade.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. @extends('layouts.app')
  2. @section('title')单位@endsection
  3. @section('content')
  4. <span id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. @component('maintenance.unit.menu')@endcomponent
  7. </span>
  8. <div class="container-fluid">
  9. <div class="card">
  10. <div class="card-body">
  11. @if(Session::has('successTip'))
  12. <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
  13. @endif
  14. <table class="table table-striped table-sm" id="list">
  15. <tr>
  16. <th>ID</th>
  17. <th>计量单位名称</th>
  18. <th>录入时间</th>
  19. <th>操作</th>
  20. </tr>
  21. <tr v-for="unit in units">
  22. <td class="text-muted">@{{unit.id}}</td>
  23. <td>@{{unit.name}}</td>
  24. <td class="text-muted">@{{unit.created_at}}</td>
  25. <td>
  26. @can('计量单位-编辑')
  27. <button class="btn btn-sm btn-outline-primary" @click="edit(unit.id)">改</button> @endcan
  28. @can('计量单位-删除')
  29. <button class="btn btn-sm btn-outline-dark" @click="destroy(unit)">删</button> @endcan
  30. </td>
  31. </tr>
  32. </table>
  33. {{$units->links()}}
  34. </div>
  35. </div>
  36. </div>
  37. @endsection
  38. @section('lastScript')
  39. <script>
  40. new Vue({
  41. el:"#list",
  42. data:{
  43. units:[
  44. @foreach( $units as $unit )
  45. {id:'{{$unit->id}}',name:'{{$unit->name}}',created_at:'{{$unit->created_at}}'},
  46. @endforeach
  47. ],
  48. },
  49. methods:{
  50. edit:function(id){
  51. location.href = "{{url('maintenance/unit')}}/"+id+"/edit";
  52. },
  53. destroy:function(unit){
  54. if(!confirm('确定要删除单位“' + unit.name + '”吗?')){return};
  55. let data=this;
  56. let url = "{{url('maintenance/unit')}}/"+unit.id;
  57. axios.delete(url,{id:unit.id})
  58. .then(function (response) {
  59. if(response.data.success){
  60. for (let i = 0; i < data.units.length; i++) {
  61. if (data.units[i].id===unit.id){
  62. data.units.splice(i,1);
  63. break;
  64. }
  65. }
  66. tempTip.setDuration(1000);
  67. tempTip.showSuccess('删除单位"'+unit.name+'"成功!')
  68. }else{
  69. tempTip.setDuration(1000);
  70. tempTip.show('删除单位"'+unit.name+'"失败!')
  71. }
  72. })
  73. .catch(function (err) {
  74. tempTip.setDuration(3000);
  75. tempTip.show('删除单位失败!'+'网络错误:' + err);
  76. console.log(err);
  77. });
  78. },
  79. }
  80. });
  81. </script>
  82. @endsection