index.blade.php 4.0 KB

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