index.blade.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. @extends('layouts.app')
  2. @section('title')城市@endsection
  3. @section('content')
  4. <span id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. @component('maintenance.city.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. <th>操作</th>
  21. </tr>
  22. <tr v-for="city in cities">
  23. <td class="text-muted">@{{city.id}}</td>
  24. <td>
  25. @{{ city.province }}
  26. </td>
  27. <td>@{{city.name}}</td>
  28. <td class="text-muted">@{{city.created_at}}</td>
  29. <td>
  30. @can('省份-编辑')
  31. <button class="btn btn-sm btn-outline-primary" @click="edit(city.id)">改</button> @endcan
  32. @can('省份-删除')
  33. <button class="btn btn-sm btn-outline-dark" @click="destroy(city)">删</button> @endcan
  34. </td>
  35. </tr>
  36. </table>
  37. {{$cities->links()}}
  38. </div>
  39. </div>
  40. </div>
  41. @endsection
  42. @section('lastScript')
  43. <script>
  44. new Vue({
  45. el:"#list",
  46. data:{
  47. cities:[
  48. @foreach( $cities as $city )
  49. {id:'{{$city->id}}',province:'{{$city->province_name}}', name:'{{$city->name}}',created_at:'{{$city->created_at}}'},
  50. @endforeach
  51. ],
  52. },
  53. methods:{
  54. edit:function(id){
  55. location.href = "{{url('maintenance/city')}}/"+id+"/edit";
  56. },
  57. destroy:function(city){
  58. if(!confirm('确定要删除城市“' + city.name + '”吗?')){return};
  59. let data=this;
  60. let url = "{{url('maintenance/city')}}/"+city.id;
  61. axios.delete(url,{id:city.id})
  62. .then(function (response) {
  63. if(response.data.success){
  64. for (let i = 0; i < data.cities.length; i++) {
  65. if (data.cities[i].id===city.id){
  66. data.cities.splice(i,1);
  67. break;
  68. }
  69. }
  70. tempTip.setDuration(1000);
  71. tempTip.showSuccess('删除单位"'+city.name+'"成功!')
  72. }else{
  73. tempTip.setDuration(1000);
  74. tempTip.show('删除单位"'+city.name+'"失败!')
  75. }
  76. })
  77. .catch(function (err) {
  78. tempTip.setDuration(3000);
  79. tempTip.show('删除车辆失败!'+'网络错误:' + err);
  80. });
  81. },
  82. }
  83. });
  84. </script>
  85. @endsection