index.blade.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. @extends("layouts.app")
  2. @section("title","图片")
  3. @section("content")
  4. <div class="container-fluid d-noe" id="list">
  5. <div class="card">
  6. @include('maintenance.expressPrinting.image._create')
  7. <div class="card-body">
  8. <div class="row pull-left m-1">
  9. <button class="btn btn-outline-info mb-1 mr-3" @click="showCreatedModel"><span
  10. class="fa fa-plus"></span>&nbsp;新&nbsp;&nbsp;增
  11. </button>
  12. </div>
  13. @include('maintenance.expressPrinting.image._table')
  14. </div>
  15. </div>
  16. </div>
  17. @endsection
  18. @section('lastScript')
  19. <script>
  20. let list = new Vue({
  21. el:'#list',
  22. data:{
  23. images:{!! $printPartImages->toJson() !!}['data'],
  24. notFindImgUrl:'{!! url('/icon/img404-thumbnail.jpg') !!}',
  25. imgPrefix:"{{asset("/storage")}}",
  26. selectTr:null,
  27. isCreated:null,
  28. editItem:{},
  29. index:null,
  30. },
  31. mounted(){
  32. $("#list").removeClass("d-none");
  33. },
  34. methods:{
  35. showCreatedModel(){
  36. this.isCreated = true;
  37. $("#imageModal").modal("show");
  38. },
  39. edit(item){
  40. this.isCreated = false;
  41. this.editItem = JSON.parse(JSON.stringify(item))
  42. $("#imageModal").modal("show");
  43. },
  44. save(){
  45. let url = '{{url("apiLocal/maintenance/expressPrinting/part/image/saveFile")}}';
  46. let data = new FormData();
  47. data.set("name",this.editItem.name);
  48. let file= this.$refs.image.files[0];
  49. data.set("file",file);
  50. if (!this.isCreated) {
  51. url = '{{url("apiLocal/maintenance/expressPrinting/part/image/update")}}'
  52. data.set("id",this.index);
  53. };
  54. window.tempTip.setIndex(2000);
  55. window.axios.post(url,data,{
  56. 'Content-Type': 'multipart/form-data'
  57. }).then(res=>{
  58. if(res.data.success){
  59. window.tempTip.showSuccess("文件保存成功");
  60. if (this.isCreated){
  61. this.images.unshift(res.data.data);
  62. } else {
  63. this.$set(this.images,this.index,res.data.data);
  64. document.getElementById('img'+this.editItem.id).setAttribute('src',this.imgPrefix+res.data.data.file.url+'.'+res.data.data.file.type);
  65. }
  66. this.$forceUpdate();
  67. $('#imageModal').modal('hide');
  68. return
  69. }
  70. window.tempTip.show(res.data.message);
  71. }).catch(err=>{
  72. window.tempTip.show(err)
  73. });
  74. },
  75. destroy(id,index){
  76. let url = '{{url("apiLocal/maintenance/expressPrinting/part/image/destroy")}}'+"?id"+id;
  77. window.axios.delete(url).then(res=>{
  78. if(res.data.success){
  79. window.tempTip.showSuccess("文件删除成功");
  80. this.$delete(this.images,index)
  81. this.$forceUpdate()
  82. return
  83. }
  84. window.tempTip.show(res.data.message);
  85. }).catch(err=>{
  86. window.tempTip.show(err)
  87. });
  88. },
  89. setImageStyle(image){
  90. console.log('img'+image.id);
  91. let img = document.getElementById('img'+image.id);
  92. // let height = img.getAttribute('height');
  93. // img.setAttribute('height',int(height) * (120 / int(height)));
  94. }
  95. }
  96. })
  97. </script>
  98. @endsection