index.blade.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. @extends('layouts.app')
  2. @section('title','装卸队')
  3. @section('content')
  4. <nav id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. </nav>
  7. <div class="container-fluid d-none" id="facilitator">
  8. <div class="card">
  9. @can('装卸队-创建')
  10. @include('maintenance.facilitator._create')
  11. @endcan
  12. @can('装卸队-编辑')
  13. @include('maintenance.facilitator._edit')
  14. @endcan
  15. <div class="card-body">
  16. <div class="row pull-left m-1">
  17. <button class="btn btn-outline-info mb-1 mr-3" @click="showCreatedModal(true)"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>
  18. </div>
  19. </div>
  20. @include('maintenance.facilitator._table')
  21. </div>
  22. </div>
  23. @endsection
  24. @section('lastScript')
  25. <script>
  26. let facilitatorVue = new Vue({
  27. el:'#facilitator',
  28. data:{
  29. facilitators:{!! $facilitators->toJson() !!}['data'],
  30. checkData:[],
  31. createFacilitator:{},
  32. editFacilitator:{},
  33. selectIndex:null,
  34. facilitatorError:{},
  35. selectTr:0,
  36. },
  37. watch:{
  38. checkData: {
  39. handler() {
  40. if (this.facilitators.length === this.checkData.length) {
  41. document.querySelector('#selectAll').checked = true;
  42. } else {
  43. document.querySelector('#selectAll').checked = false;
  44. }
  45. },
  46. deep: true
  47. },
  48. },
  49. created(){
  50. },
  51. mounted() {
  52. $('#facilitator').removeClass('d-none');
  53. },
  54. methods:{
  55. checkAll(e) {
  56. if (!e.target.checked) this.checkData = [];
  57. else {
  58. this.providerStatements.forEach((item, i) => {
  59. if (this.checkData.indexOf(item.id) === -1) this.checkData.push(item.id);
  60. });
  61. }
  62. },
  63. // 显示隐藏添加页面
  64. showCreatedModal(isDisplay){
  65. this.createFacilitator = {};
  66. if(isDisplay){
  67. $('#createdModal').modal('show');
  68. }else{
  69. $('#createdModal').modal('hide');
  70. }
  71. },
  72. // 显示隐藏更新页面
  73. showUpDateModal(isDisplay,index = null,facilitator = {}){
  74. this.selectIndex = index;
  75. this.editFacilitator = JSON.parse(JSON.stringify(facilitator));
  76. if(isDisplay){
  77. $('#updatedModal').modal('show');
  78. }else{
  79. this.selectIndex = null;
  80. $('#updatedModal').modal('hide');
  81. }
  82. },
  83. // 创建服务商
  84. storeFacilitator(){
  85. let url = '{{url('apiLocal/facilitator/store')}}';
  86. tempTip.setIndex(999);
  87. tempTip.setDuration(1999);
  88. axios.post(url,this.createFacilitator).then(res=>{
  89. if(res.data.success){
  90. this.facilitators.unshift(res.data.data);
  91. tempTip.showSuccess('添加装卸队成功');
  92. this.showCreatedModal(false)
  93. return ;
  94. }else if(res.data.error){
  95. this.facilitatorError = res.data.error;
  96. return
  97. }
  98. tempTip.show(res.data.data);
  99. }).catch(err=>{
  100. tempTip.show('服务商添加异常'+err);
  101. });
  102. },
  103. // 更新服务商
  104. updateFacilitator(){
  105. let url = '{{url('apiLocal/facilitator/update')}}';
  106. tempTip.setIndex(999);
  107. tempTip.setDuration(1999);
  108. axios.put(url,this.editFacilitator).then(res=>{
  109. if(res.data.success){
  110. this.$set(this.facilitators,this.selectIndex,res.data.data);
  111. tempTip.showSuccess('装卸队更新成功');
  112. this.showUpDateModal(false);
  113. return ;
  114. }else if(res.data.error){
  115. this.facilitatorError = res.data.error;
  116. return
  117. }
  118. tempTip.show(res.data.data);
  119. }).catch(err=>{
  120. tempTip.show(''+err);
  121. });
  122. },
  123. // 删除服务商
  124. destroyFacilitator(facilitator,index){
  125. let url = '{{url('apiLocal/facilitator/destroy?id=')}}'+facilitator['id'];
  126. tempTip.setIndex(999);
  127. tempTip.setDuration(1999);
  128. axios.delete(url).then(res=>{
  129. if(res.data.success){
  130. tempTip.showSuccess("装卸队删除成功");
  131. this.$delete(this.facilitators,index);
  132. return ;
  133. }else if(res.data.error){
  134. tempTip.show(res.data.error.id[0]);
  135. return ;
  136. }
  137. tempTip.show(res.data.data ?? '删除异常');
  138. }).catch(err=>{
  139. tempTip.show(err);
  140. })
  141. }
  142. }
  143. });
  144. </script>
  145. @endsection