index.blade.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. @extends('layouts.app')
  2. @section('title','耗材类型')
  3. @section('content')
  4. <span id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. </span>
  7. <div class="container-fluid d-none" id="material_div">
  8. @can('耗材类型-编辑')
  9. @include('maintenance.material._edit')
  10. @include('maintenance.material._create')
  11. @endcan
  12. <div class="card">
  13. <div class="card_body">
  14. <div class="row pull-left m-1">
  15. @can('耗材类型-编辑')
  16. <button class="btn btn-outline-info mb-1 mr-3" @click="store"><span class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增</button>
  17. @endcan
  18. </div>
  19. @include('maintenance.material._table')
  20. </div>
  21. </div>
  22. </div>
  23. @endsection
  24. @section('lastScript')
  25. <script>
  26. let vue = new Vue({
  27. el:'#material_div',
  28. data:{
  29. materials:{!! $materials->toJson() !!}['data'],
  30. editMaterial:{},
  31. addMaterial:{},
  32. selectTr:0,
  33. selectIndex:0,
  34. materialError:{},
  35. },
  36. created(){
  37. },
  38. mounted() {
  39. $('#material_div').removeClass('d-none');
  40. },
  41. methods:{
  42. destroy(id,index){
  43. window.tempTip.setIndex(1099);
  44. window.tempTip.confirm("是否删除当前耗材?",()=>{
  45. window.axios.delete('{{url("apiLocal/material/destroy")}}/'+id).then(res=>{
  46. if(res.data.success){
  47. tempTip.setDuration(3000);
  48. tempTip.showSuccess('删除成功');
  49. this.$delete(this.materials,index);
  50. return;
  51. }
  52. tempTip.setDuration(3000);
  53. tempTip.show(res.data.message);
  54. }).catch(err=>{
  55. tempTip.setDuration(3000);
  56. tempTip.show(err);
  57. });
  58. });
  59. },
  60. edit(material,i){
  61. this.editMaterial =JSON.parse(JSON.stringify(material));
  62. this.selectIndex = i;
  63. $('#editModal').modal('show');
  64. },
  65. store(){
  66. this.addMaterial = {};
  67. $('#addModal').modal('show');
  68. },
  69. // 耗材更新
  70. update(material,index){
  71. window.tempTip.setDuration(3000);
  72. window.tempTip.setIndex(1099);
  73. window.axios.post('{{url('apiLocal/material/update')}}',material).then(res=>{
  74. if(res.data.success){
  75. $('#editModal').modal('hide');
  76. window.tempTip.showSuccess('修改成功');
  77. console.log(res.data.data);
  78. this.$set(this.materials,index,res.data.data);
  79. this.selectIndex = 0;
  80. return;
  81. }else if(res.data.errors){
  82. this.materialError = res.data.errors;
  83. return;
  84. }
  85. window.tempTip.show(res.data.message);
  86. }).catch(err=>{
  87. window.tempTip.show(err);
  88. });
  89. },
  90. // 耗材创建
  91. create(addMaterial){
  92. window.tempTip.setDuration(3000);
  93. window.tempTip.setIndex(1099);
  94. axios.post('{{url('apiLocal/material/store')}}',addMaterial)
  95. .then(res=>{
  96. if(res.data.success){
  97. $('#addModal').modal('hide');
  98. window.tempTip.showSuccess('添加成功');
  99. this.addMaterial={};
  100. this.materials.unshift(res.data.data);
  101. return;
  102. }else if(res.data.errors){
  103. this.materialError = res.data.errors;
  104. return;
  105. }
  106. tempTip.show(res.data.message);
  107. }).catch(err=>{
  108. tempTip.show(err);
  109. });
  110. }
  111. }
  112. });
  113. </script>
  114. @endsection