index.blade.php 3.5 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.province.menu')@endcomponent
  7. </span>
  8. <div class="container-fluid mt-3">
  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="province in provinces">
  22. <td class="text-muted">@{{province.id}}</td>
  23. <td>@{{province.name}}</td>
  24. <td class="text-muted">@{{province.created_at}}</td>
  25. <td>
  26. @can('省份-编辑')
  27. <button class="btn btn-sm btn-outline-primary" @click="edit(province.id)">改</button> @endcan
  28. @can('省份-删除')
  29. <button class="btn btn-sm btn-outline-dark" @click="destroy(province)">删</button> @endcan
  30. </td>
  31. </tr>
  32. </table>
  33. {{$provinces->links()}}
  34. </div>
  35. </div>
  36. </div>
  37. @endsection
  38. @section('lastScript')
  39. <script>
  40. new Vue({
  41. el:"#list",
  42. data:{
  43. provinces:[
  44. @foreach( $provinces as $province )
  45. {id:'{{$province->id}}',name:'{{$province->name}}',created_at:'{{$province->created_at}}'},
  46. @endforeach
  47. ],
  48. },
  49. methods:{
  50. edit:function(id){
  51. location.href = "{{url('maintenance/province')}}/"+id+"/edit";
  52. },
  53. destroy:function(province){
  54. if(!confirm('确定要删除省份“' + province.name + '”吗?')){return};
  55. let data=this;
  56. let url = "{{url('maintenance/province')}}/"+province.id;
  57. axios.delete(url,{id:province.id})
  58. .then(function (response) {
  59. if(response.data.success){
  60. for (let i = 0; i < data.provinces.length; i++) {
  61. if (data.provinces[i].id===province.id){
  62. data.provinces.splice(i,1);
  63. break;
  64. }
  65. }
  66. tempTip.setDuration(1000);
  67. tempTip.showSuccess('删除单位"'+province.name+'"成功!')
  68. }else{
  69. tempTip.setDuration(1000);
  70. tempTip.show('删除单位"'+province.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