index.blade.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. @extends('layouts.app')
  2. @section('title','系统配置')
  3. @section('content')
  4. <div class="container-fluid d-none" id="configuration">
  5. <div class="card">
  6. @can('系统配置-编辑')
  7. @include('maintenance.configuration._create')
  8. @include('maintenance.configuration._edit')
  9. @endcan
  10. <div class="card-body">
  11. <div class="row pull-left m-1">
  12. @can('系统配置-编辑')
  13. <button class="btn btn-outline-info mb-1 mr-3" @click="store"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>
  14. @endcan
  15. </div>
  16. @include('maintenance.configuration._table')
  17. </div>
  18. </div>
  19. </div>
  20. @endsection
  21. @section('lastScript')
  22. <script>
  23. let vue = new Vue({
  24. el:"#configuration",
  25. data:{
  26. configurations:{!! $configurations->toJson() !!}['data'],
  27. addConfiguration:{},
  28. editConfiguration:{},
  29. index:'',
  30. selectTr:'',
  31. configurationErrors:{},
  32. },
  33. mounted(){
  34. $('#configuration').removeClass('d-none');
  35. },
  36. methods:{
  37. destroy(id,index){
  38. if (!confirm('是否删除当前项目耗材')) return;
  39. axios.delete('{{url('apiLocal/configuration')}}/'+id).then(res=>{
  40. if(res.data.success){
  41. tempTip.setIndex(100);
  42. tempTip.setDuration(3000);
  43. tempTip.showSuccess('删除成功');
  44. this.$delete(this.configurations,index);
  45. return ;
  46. }
  47. tempTip.setDuration(3000);
  48. tempTip.show(res.data.message);
  49. }).catch(err=>{
  50. tempTip.setDuration(3000);
  51. tempTip.show('删除当前项目耗材失败:'+err);
  52. });
  53. },
  54. edit(configuration,i){
  55. this.editConfiguration = JSON.parse(JSON.stringify(configuration));
  56. this.index = i;
  57. this.configurationErrors ={};
  58. $('#edit-configuration').modal('show');
  59. },
  60. update(){
  61. let url = '{{url('apiLocal/configuration/update')}}';
  62. let params = this.editConfiguration;
  63. if(!this.validateConfiguration(params))return;
  64. window.axios.post(url,params).then(res=>{
  65. if(res.data.success){
  66. this.$set(this.configurations,this.index,res.data.data);
  67. this.index = null;
  68. this.editConfiguration = {};
  69. $("#edit-configuration").modal('hide');
  70. window.tempTip.showSuccess('修改成功');
  71. return ;
  72. }
  73. if(res.data.errors){
  74. this.configurationErrors = res.data.errors;
  75. return;
  76. }
  77. window.tempTip.show(res.data.message ?? '修改失败');
  78. }).catch(err=>{
  79. window.tempTip.show('修改失败'+err);
  80. });
  81. },
  82. store(){
  83. this.addConfiguration = {};
  84. this.configurationErrors ={};
  85. $('#add-configuration').modal('show');
  86. },
  87. create(params){
  88. let url = '{{url('apiLocal/configuration/store')}}';
  89. if(!this.validateConfiguration(params))return;
  90. window.tempTip.setIndex(1099);
  91. window.tempTip.setDuration(3000);
  92. window.axios.post(url,params).then(res=>{
  93. if(res.data.success){
  94. this.configurations.unshift(res.data.data);
  95. this.$forceUpdate();
  96. $("#add-configuration").modal('hide');
  97. window.tempTip.showSuccess('添加成功');
  98. return ;
  99. }
  100. if(res.data.errors){
  101. this.configurationErrors = res.data.errors;
  102. return ;
  103. }
  104. window.tempTip.show(res.data.message ?? '修改失败');
  105. }).catch(err=>{
  106. window.tempTip.show('修改失败'+err);
  107. });
  108. },
  109. validateConfiguration(configuration){
  110. let bool = true;
  111. if(!configuration.hasOwnProperty('name') || configuration.name.trim() === ''){
  112. this.$set(this.configurationErrors,'name',['名称为必填项'])
  113. bool = false;
  114. }
  115. if(!configuration.hasOwnProperty('value') || configuration.value.trim() === ''){
  116. this.$set(this.configurationErrors,'value',['值为必填项'])
  117. bool = false;
  118. }
  119. if(!configuration.hasOwnProperty('description') || configuration.description.trim() === ''){
  120. this.$set(this.configurationErrors,'description',['描述为必填项'])
  121. bool = false;
  122. }
  123. if(!bool)this.$forceUpdate();
  124. return bool;
  125. }
  126. }
  127. });
  128. </script>
  129. @endsection