index.blade.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. @extends('layouts.app')
  2. @section('title','项目耗材')
  3. @section('content')
  4. <nav id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. </nav>
  7. <div class="container-fluid d-none" id="owner_material">
  8. <div class="card">
  9. @can('项目耗材-编辑')
  10. @include('maintenance.ownerMaterial._create')
  11. @include('maintenance.ownerMaterial._edit')
  12. @endcan
  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.ownerMaterial._table')
  20. </div>
  21. </div>
  22. @can('项目耗材-文件上传')
  23. @include('maintenance.ownerMaterial._uploadFile')
  24. @endcan
  25. </div>
  26. @endsection
  27. @section('lastScript')
  28. <script>
  29. let vue = new Vue({
  30. el:"#owner_material",
  31. data:{
  32. ownerMaterials:{!! $ownerMaterials->toJson() !!}['data'],
  33. owners:{!! $owners->toJson() !!},
  34. materials:{!! $materials->toJson() !!},
  35. addOwnerMaterial:{},
  36. editOwnerMaterial:{},
  37. index:'',
  38. filterOwners:'',
  39. filterMaterials:'',
  40. materialErrors:{},
  41. uploadError: null,
  42. selectTr:0
  43. },
  44. mounted(){
  45. $('#owner_material').removeClass('d-none');
  46. this.filterOwners = JSON.parse(JSON.stringify(this.owners));
  47. this.filterMaterials = JSON.parse(JSON.stringify(this.materials));
  48. },
  49. created(){
  50. let _this = this;
  51. this.ownerMaterials.forEach(function(item){
  52. _this.fileType(item);
  53. })
  54. },
  55. methods:{
  56. fileType(ownerMaterial){
  57. let file_types = [ 'gif','jpeg','jpg','png','svg'];
  58. if(!ownerMaterial.file){
  59. ownerMaterial.isImg = false;
  60. return;
  61. }
  62. if(ownerMaterial.file.url){
  63. let target = ownerMaterial.file.url;
  64. let index= target.lastIndexOf(".");
  65. let ext = target.substr(index+1);
  66. if(file_types.includes(ext)){
  67. ownerMaterial.isImg = true;
  68. }
  69. }
  70. },
  71. destroy(id,index){
  72. if (!confirm('是否删除当前项目耗材')) return;
  73. axios.delete('{{url('apiLocal/ownerMaterial')}}/'+id).then(res=>{
  74. if(res.data.success){
  75. tempTip.setIndex(100);
  76. tempTip.setDuration(3000);
  77. tempTip.showSuccess('删除成功');
  78. this.$delete(this.ownerMaterials,index);
  79. return ;
  80. }
  81. tempTip.setDuration(3000);
  82. tempTip.show(res.data.message);
  83. }).catch(err=>{
  84. tempTip.setDuration(3000);
  85. tempTip.show('删除当前项目耗材失败:'+err);
  86. });
  87. },
  88. edit(ownerMaterial,i){
  89. this.materialErrors = {};
  90. this.editOwnerMaterial = JSON.parse(JSON.stringify(ownerMaterial));
  91. this.filterMaterials = JSON.parse(JSON.stringify(this.materials));
  92. this.filterOwners = JSON.parse(JSON.stringify(this.owners));
  93. $('#editOwnerName').val('');
  94. this.index = i;
  95. $('#edit-ownerMaterial').modal('show');
  96. },
  97. update(){
  98. let url = '{{url('apiLocal/ownerMaterial/update')}}';
  99. let params = this.editOwnerMaterial;
  100. if(!this.validateOwnerMaterial(params))return;
  101. window.tempTip.setIndex(1099);
  102. window.tempTip.setDuration(3000);
  103. window.axios.post(url,params).then(res=>{
  104. if(res.data.success){
  105. this.fileType(res.data);
  106. this.$set(this.ownerMaterials,this.index,res.data.data);
  107. this.index = null;
  108. $("#edit-ownerMaterial").modal('hide');
  109. window.tempTip.showSuccess('修改成功');
  110. return ;
  111. }else if (res.data.errors){
  112. this.materialErrors = res.data.errors;
  113. return ;
  114. }
  115. window.tempTip.show('修改成功');
  116. }).catch(err=>{
  117. window.tempTip.show(err);
  118. });
  119. },
  120. store(){
  121. this.addOwnerMaterial = {};
  122. this.materialErrors = {};
  123. $('#filterOwnerName').val('');
  124. this.filterMaterials = JSON.parse(JSON.stringify(this.materials));
  125. this.filterOwners = JSON.parse(JSON.stringify(this.owners));
  126. $('#add-ownerMaterial').modal('show');
  127. },
  128. create(params){
  129. let url = '{{url('apiLocal/ownerMaterial/store')}}';
  130. if(!this.validateOwnerMaterial(params))return;
  131. window.tempTip.setIndex(1099);
  132. window.tempTip.setDuration(3000);
  133. window.axios.post(url,params).then(res=>{
  134. if(res.data.success){
  135. this.fileType(res.data.data);
  136. this.ownerMaterials.unshift(res.data.data);
  137. this.addOwnerMaterial = {};
  138. $("#add-ownerMaterial").modal('hide');
  139. window.tempTip.showSuccess('创建成功');
  140. return ;
  141. }else if (res.data.errors){
  142. this.materialErrors = res.data.errors;
  143. return ;
  144. }
  145. window.tempTip.show('创建失败');
  146. }).catch(err=>{
  147. window.tempTip.show(err);
  148. });
  149. },
  150. uploadModal(ownerMaterial,i){
  151. this.editOwnerMaterial = JSON.parse(JSON.stringify(ownerMaterial));
  152. this.filterMaterials = JSON.parse(JSON.stringify(this.materials));
  153. this.filterOwners = JSON.parse(JSON.stringify(this.owners));
  154. this.index = i;
  155. $('#uploadFile').modal('show');
  156. },
  157. getDownFileUrl(ownerMaterial){
  158. return '{{ url("maintenance/ownerMaterial/downFile?file=")}}'+ownerMaterial.file.url+'&name='+ownerMaterial.file.file_name;
  159. },
  160. uploadFile(){
  161. tempTip.setDuration(3000);
  162. tempTip.setIndex(1099);
  163. let url = '{{url('apiLocal/ownerMaterial/uploadFile')}}';
  164. let data = new FormData();
  165. let file = this.$refs.file.files[0];
  166. if(file===null){
  167. if (!confirm('请选择上传文件')) return;
  168. }
  169. if (file.size >=10485760){
  170. tempTip.show("图片大小不能超过10MB!");
  171. return;
  172. }
  173. data.append('file',file);
  174. data.append('id',this.editOwnerMaterial.id);
  175. window.axios.post(url,data,{
  176. 'Content-Type':'multipart/form-data'
  177. }).then(res=>{
  178. if(res.data.success){
  179. this.fileType(res.data.data);
  180. this.$set(this.ownerMaterials,this.index,res.data.data);
  181. this.editOwnerMaterial = {};
  182. this.index = '';
  183. tempTip.showSuccess('文件上传成功');
  184. $("#uploadFile").modal('hide');
  185. return ;
  186. }
  187. tempTip.show(res.data.message ?? '文件上传失败');
  188. }).catch(err=>{
  189. tempTip.show('文件上传失败'+err);
  190. })
  191. },
  192. filterMaterial(e,type){
  193. let value = $(e.target).val();
  194. let materials = JSON.parse(JSON.stringify(this.materials));
  195. if(value==='' || value===null)this.filterMaterials = materials;
  196. else {
  197. this.filterMaterials = materials.filter(function(item){
  198. return item.name.indexOf(value) !== -1;
  199. });
  200. if(this.filterMaterials.length>0){
  201. if(type===1)this.addOwnerMaterial.material_id = this.filterMaterials[0]['id'];
  202. if(type===2)this.editOwnerMaterial.material_id = this.filterMaterials[0]['id'];
  203. }
  204. }
  205. },
  206. filterOwner(e,type){
  207. let value = $(e.target).val();
  208. let owners = JSON.parse(JSON.stringify(this.owners));
  209. if(value==='' || value===null)this.filterOwners = owners;
  210. else {
  211. this.filterOwners = owners.filter(function(item){
  212. return item.name.indexOf(value) !== -1;
  213. });
  214. if(this.filterOwners.length>0){
  215. if(type===1)this.addOwnerMaterial.owner_id = this.filterOwners[0]['id'];
  216. if(type===2)this.editOwnerMaterial.owner_id = this.filterOwners[0]['id'];
  217. }
  218. }
  219. },
  220. validateOwnerMaterial(material){
  221. let is_validate = true;
  222. if(!material.hasOwnProperty('owner_id') || material['owner_id']=== 0){
  223. this.$set(this.materialErrors,'owner_id',['货主为必选项']);
  224. is_validate = false;
  225. }
  226. if(!material.hasOwnProperty('material_id') || material['owner_id'] === 0 ){
  227. this.$set(this.materialErrors,'material_id',['耗材为必选项']);
  228. is_validate = false;
  229. }
  230. if((!material.hasOwnProperty('material_code')) || material['material_code'].trim()===''){
  231. this.$set(this.materialErrors,'material_code',['耗材编码为必填项']);
  232. is_validate = false;
  233. }
  234. if(!material.hasOwnProperty('size') || ((material['size']).trim().length === 0)){
  235. this.$set(this.materialErrors,'size',['耗材编码为必填项']);
  236. is_validate = false;
  237. }
  238. if(!is_validate)this.$forceUpdate();
  239. return is_validate;
  240. }
  241. }
  242. });
  243. </script>
  244. @endsection