index.blade.php 4.0 KB

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