index.blade.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. @extends('layouts.app')
  2. @section('title','站规则')
  3. @section('content')
  4. <span id="nav2">
  5. @component('station.menu')@endcomponent
  6. @component('station.rule.menu')@endcomponent
  7. </span>
  8. <div class="container-fluid d-none" id="list">
  9. @can('站管理-站规则-创建')
  10. <button class="btn btn-md btn-outline-primary ml-1" @click="createStationRuleBatch">创建</button>
  11. @endcan
  12. @include('station.rule._table')
  13. @include('station.rule._edit')
  14. </div>
  15. @endsection
  16. @section('lastScript')
  17. <script>
  18. let vue = new Vue({
  19. el: '#list',
  20. data: {
  21. selectTr: null,
  22. stationRuleBatches: {!! $stationRuleBatches->toJson() !!}['data'],
  23. owners:{!! $owners !!},
  24. ownerFilters: [],
  25. filterName: null,
  26. tag: null,
  27. tagIndex: null,
  28. stationRuleBatch: {},
  29. errors: {}
  30. },
  31. mounted() {
  32. $('#list').removeClass('d-none');
  33. this.filterOwner();
  34. },
  35. methods: {
  36. createStationRuleBatch() {
  37. this.tag = 'create';
  38. this.filterOwner();
  39. this.stationRuleBatch = {};
  40. this.errors = {};
  41. $('#box').modal('show');
  42. },
  43. editStationRuleBatch(item, index) {
  44. this.stationRuleBatch = JSON.parse(JSON.stringify(item));
  45. this.tag = 'update';
  46. this.tagIndex = index;
  47. this.filterOwner();
  48. this.errors = {};
  49. $('#box').modal('show');
  50. },
  51. deleteStationRuleBatch(item, index) {
  52. if (!confirm("确定要删除对应的栈规则")) {
  53. return;
  54. }
  55. let url = '{{url('apiLocal/station/rule/destroy')}}' + '/?id=' + item['id'];
  56. window.axios.delete(url).then(res => {
  57. if (res.data.success) {
  58. window.tempTip.showSuccess('删除成功');
  59. this.$delete(this.stationRuleBatches, index);
  60. return;
  61. }
  62. window.tempTip.show('删除异常,刷新页面重试');
  63. }).catch(err => {
  64. window.tempTip.show('网络异常,' + err);
  65. });
  66. },
  67. _create() {
  68. let url = '{{url('apiLocal/station/rule/store')}}';
  69. console.log(this.stationRuleBatch);
  70. window.axios.post(url, this.stationRuleBatch).then(res => {
  71. if (res.data.success) {
  72. this.stationRuleBatches.unshift(res.data.data);
  73. window.tempTip.showSuccess('创建成功');
  74. $('#box').modal('hide');
  75. this.$forceUpdate();
  76. this.tag = null;
  77. this.tagIndex = null;
  78. this.stationRuleBatch = {};
  79. return;
  80. }else if(res.data.errors){
  81. this.errors = res.data.errors;
  82. this.$forceUpdate();
  83. return;
  84. }
  85. window.tempTip.show('创建异常');
  86. }).catch(err => {
  87. window.tempTip.show('网络异常,' + err);
  88. });
  89. },
  90. _edit() {
  91. let url = '{{url('apiLocal/station/rule/update')}}';
  92. window.axios.put(url, this.stationRuleBatch).then(res => {
  93. if (res.data.success) {
  94. this.$set(this.stationRuleBatches, this.tagIndex, res.data.data);
  95. window.tempTip.showSuccess('修改成功!');
  96. $('#box').modal('hide');
  97. this.tag = null;
  98. this.tagIndex = null;
  99. this.stationRuleBatch = {};
  100. this.$forceUpdate();
  101. return;
  102. }else if(res.data.errors){
  103. this.errors =res.data.errors;
  104. this.$forceUpdate();
  105. return;
  106. }
  107. window.tempTip.show('编辑异常,刷新页面重试');
  108. }).catch(err => {
  109. window.tempTip.show('网络异常,' + err);
  110. });
  111. },
  112. setStationRuleBatchName($e){
  113. let selectValue = $($e.target).find('option:selected').text();
  114. if(selectValue && !this.stationRuleBatch.name )
  115. this.$set(this.stationRuleBatch,'name',selectValue)
  116. },
  117. filterOwner($e = null) {
  118. let copyOwner = JSON.parse(JSON.stringify(this.owners));
  119. this.ownerFilters = copyOwner;
  120. if ($e !== null) {
  121. let value = $($e.target).val();
  122. this.ownerFilters = copyOwner.filter(function (owner) {
  123. return owner.name.indexOf(value) !== -1;
  124. });
  125. if (this.ownerFilters.length !== this.owners.length && this.ownerFilters.length > 0) {
  126. this.$set(this.stationRuleBatch,'owner_id',this.ownerFilters[0]['id']);
  127. this.$set(this.stationRuleBatch,'name',this.ownerFilters[0]['name']);
  128. } else {
  129. this.$set(this.stationRuleBatch,'owner_id',null);
  130. }
  131. }
  132. this.$forceUpdate();
  133. }
  134. }
  135. })
  136. </script>
  137. @endsection