index.blade.php 4.3 KB

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