index.blade.php 5.9 KB

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