index.blade.php 3.5 KB

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