index.blade.php 7.6 KB

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