index.blade.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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" id="list">
  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. <div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
  15. <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
  16. <div class="modal-content">
  17. <div class="modal-body" style="text-align:center;height: 150px">
  18. <div class="row col-12 mt-5">
  19. <label class="col-2 text-info">选择货主:</label>
  20. <select class="form-control form-control-sm col-6" name="owner_code" v-model="owner_code">
  21. <option v-for="owner in owners" :value="owner.code">@{{ owner.name }}</option>
  22. </select>
  23. <input placeholder="搜索货主" @input="seekOwner($event)" class="form-control form-control-sm col-3">
  24. </div>
  25. </div>
  26. <div class="modal-footer">
  27. <button class="col-12 btn btn-success" @click="syncCommodity()">开始同步</button>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. @can('商品信息-编辑')<button class="btn btn-sm btn-outline-info mb-1" @click="openModal()" >同步商品</button>@endcan
  33. <table class="table table-striped table-sm">
  34. <tr>
  35. <th>ID</th>
  36. <th>SKU</th>
  37. <th>商品名</th>
  38. <th>条码</th>
  39. <th>货主</th>
  40. <th>创建时间</th>
  41. <th>操作</th>
  42. </tr>
  43. <tr v-for="commodity in commodities" @click="selectTr===commodity.id?selectTr=0:selectTr=commodity.id" :class="selectTr===commodity.id?'focusing' : ''">
  44. <td class="text-muted">@{{commodity.id}}</td>
  45. <td>@{{commodity.sku}}</td>
  46. <td>@{{commodity.name}}</td>
  47. <td>@{{commodity.barcode}}</td>
  48. <td>@{{commodity.owner_name}}</td>
  49. <td class="text-muted">@{{commodity.created_at}}</td>
  50. <td>
  51. @can('商品信息-编辑')
  52. <button class="btn btn-sm btn-outline-primary" @click="edit(commodity.id)">改</button> @endcan
  53. @can('商品信息-删除')
  54. <button class="btn btn-sm btn-outline-dark" @click="destroy(commodity)">删</button> @endcan
  55. </td>
  56. </tr>
  57. </table>
  58. {{$commodities->links()}}
  59. </div>
  60. </div>
  61. </div>
  62. @endsection
  63. @section('lastScript')
  64. <script>
  65. new Vue({
  66. el:"#list",
  67. data:{
  68. commodities:[
  69. @foreach( $commodities as $commodity )
  70. {
  71. id:'{{$commodity->id}}',name:'{{$commodity->name}}',created_at:'{{$commodity->created_at}}',
  72. sku:'{{$commodity->sku}}',barcode:'{{$commodity->barcode}}',owner_name:'{{$commodity->owner_name}}'
  73. },
  74. @endforeach
  75. ],
  76. owners : [],
  77. owner_code : '',
  78. selectTr:0
  79. },
  80. methods:{
  81. edit:function(id){
  82. location.href = "{{url('maintenance/commodity')}}/"+id+"/edit";
  83. },
  84. destroy:function(commodity){
  85. if(!confirm('确定要删除商品信息“' + commodity.name + '”吗?')){return};
  86. let data=this;
  87. let url = "{{url('maintenance/commodity')}}/"+commodity.id;
  88. axios.delete(url,{id:commodity.id})
  89. .then(function (response) {
  90. if(response.data.success){
  91. for (let i = 0; i < data.commodities.length; i++) {
  92. if (data.commodities[i].id===commodity.id){
  93. data.commodities.splice(i,1);
  94. break;
  95. }
  96. }
  97. tempTip.setDuration(1000);
  98. tempTip.showSuccess('删除商品信息"'+commodity.name+'"成功!')
  99. }else{
  100. tempTip.setDuration(1000);
  101. tempTip.show('删除商品信息"'+commodity.name+'"失败!')
  102. }
  103. })
  104. .catch(function (err) {
  105. tempTip.setDuration(3000);
  106. tempTip.show('删除商品信息失败!'+'网络错误:' + err)
  107. });
  108. },
  109. openModal(){
  110. axios.post('{{url('apiLocal/maintenance/owner/getOwners')}}')
  111. .then(res=>{
  112. this.owners = res.data;
  113. $("#modal").modal('show');
  114. });
  115. },
  116. syncCommodity(){
  117. if (!this.owner_code){
  118. tempTip.setDuration(3000);
  119. tempTip.show('未选择货主');
  120. return;
  121. }
  122. let owner_id = "";
  123. this.owners.some(owner => {
  124. if (owner.code === this.owner_code){
  125. owner_id = owner.id;
  126. return true;
  127. }
  128. });
  129. window.tempTip.setIndex(1099);
  130. window.tempTip.setDuration(9999999);
  131. window.tempTip.waitingTip("处理中(如若数据量过多,因需要逐条对比矫正耗时较长,请耐心等候)。。。");
  132. axios.post('{{url('maintenance/commodity/syncWMS')}}',{owner_code : this.owner_code, owner_id : owner_id})
  133. .then(res => {
  134. if (res.data.success){
  135. tempTip.setDuration(2000);
  136. tempTip.cancelWaitingTip();
  137. tempTip.setIndex(1099);
  138. tempTip.showSuccess("同步成功");
  139. return true;
  140. }
  141. tempTip.setDuration(3000);
  142. tempTip.show(res.data.data);
  143. }).catch(err => {
  144. tempTip.setDuration(3000);
  145. tempTip.showSuccess("网络错误:"+err);
  146. });
  147. },
  148. seekOwner(e){
  149. this.owners.some(owner => {
  150. if (owner.name.indexOf(e.target.value) !== -1){
  151. this.owner_code = owner.code;
  152. return true;
  153. }
  154. });
  155. }
  156. }
  157. });
  158. </script>
  159. @endsection