upload1.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!--出账申请上传组件-->
  2. <template id="upload1">
  3. <div>
  4. <input type="file" class="com-input" @change="update($event,filelist,transfer.id)" accept="image/jpeg,image/jpg,image/gif,image/bmp,image/png,.pdf,.doc,.docx,.xls,.xlsx" />
  5. <div style="margin-left: 100px">
  6. <div v-if="filelist==0">
  7. <div v-for="(item,index1) in fileList0">
  8. <span v-text="item.name"></span>
  9. <span @click="deleteAttach(item.id,0,index1)" class="delete" v-if="transfer.status==201 || transfer.status==205">
  10. <i class="fa fa-trash"></i>删除
  11. </span>
  12. </div>
  13. </div>
  14. <div v-if="filelist==1">
  15. <div v-for="(item,index1) in fileList1">
  16. <span v-text="item.name"></span>
  17. <span @click="deleteAttach(item.id,1,index1)" class="delete" v-if="transfer.status==201 || transfer.status==205">
  18. <i class="fa fa-trash"></i>删除
  19. </span>
  20. </div>
  21. </div>
  22. <div v-if="filelist==2">
  23. <div v-for="(item,index1) in fileList2">
  24. <span v-text="item.name"></span>
  25. <span @click="deleteAttach(item.id,2,index1)" class="delete" v-if="transfer.status==201 || transfer.status==205">
  26. <i class="fa fa-trash"></i>删除
  27. </span>
  28. </div>
  29. </div>
  30. <div v-if="filelist==3">
  31. <div v-for="(item,index1) in fileList3">
  32. <span v-text="item.name"></span>
  33. <span @click="deleteAttach(item.id,3,index1)" class="delete" v-if="transfer.status==201 || transfer.status==205">
  34. <i class="fa fa-trash"></i>删除
  35. </span>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. data:function() {
  44. return {
  45. //附件1
  46. fileList0: [],
  47. //附件2
  48. fileList1: [],
  49. fileList2: [],
  50. fileList3: [],
  51. attach: {id: '', type: '', aaid: '', name: '', path: '', size: ''},
  52. }
  53. },
  54. props: ['filelist', 'transfer'],
  55. mounted:function(){
  56. for(var i=0;i<this.transfer.attaches.length;i++){
  57. if(this.transfer.attaches[i].type=='交易买方贸易合同'){
  58. this.fileList0.push(this.transfer.attaches[i])
  59. }else if(this.transfer.attaches[i].type=='增值税发票'){
  60. this.fileList1.push(this.transfer.attaches[i])
  61. }else if(this.transfer.attaches[i].type=='货运单据'){
  62. this.fileList2.push(this.transfer.attaches[i])
  63. }else if(this.transfer.attaches[i].type=='其他'){
  64. this.fileList3.push(this.transfer.attaches[i])
  65. }
  66. }
  67. },
  68. methods:{
  69. update:function(e, index,aaid) {
  70. let file = e.target.files[0]
  71. this.attach.name = e.target.files[0].name;
  72. this.attach.aaid = aaid;
  73. if (index == 0) {
  74. this.attach.type = '交易买方贸易合同';
  75. } else if (index == 1) {
  76. this.attach.type = '增值税发票';
  77. } else if (index == 2) {
  78. this.attach.type = '货运单据';
  79. } else if (index == 3) {
  80. this.attach.type = '其他';
  81. }
  82. let param = new FormData()
  83. param.append('file', file, file.name)
  84. param.append('type', this.attach.type)
  85. param.append('aaid', this.attach.aaid)
  86. param.append('chunk', '0')
  87. let _this = this
  88. let config = {
  89. headers: {'Content-Type': 'multipart/form-data'}
  90. }
  91. return this.$axios.post('/accountapply/attachsave', param, config)
  92. .then(response => {
  93. if(response.data.type == '交易买方贸易合同'){
  94. _this.fileList0.push(response.data)
  95. }else if (response.data.type == '增值税发票') {
  96. _this.fileList1.push(response.data)
  97. } else if (response.data.type == '货运单据') {
  98. _this.fileList2.push(response.data)
  99. } else if (response.data.type == '其他') {
  100. _this.fileList3.push(response.data)
  101. }
  102. })
  103. },
  104. deleteAttach: function (id, index, index1) {
  105. let _this = this;
  106. var params = new URLSearchParams();
  107. params.append('id', id)
  108. this.$axios.post('/accountapply/attachdelete', params)
  109. .then(function () {
  110. switch (index) {
  111. case 0:
  112. _this.fileList0.splice(index1, 1)
  113. break;
  114. case 1:
  115. _this.fileList1.splice(index1, 1)
  116. break;
  117. case 2:
  118. _this.fileList2.splice(index1, 1)
  119. break;
  120. case 3:
  121. _this.fileList3.splice(index1, 1)
  122. break;
  123. }
  124. }).catch(function () {
  125. alert('删除失败')
  126. })
  127. }
  128. },
  129. }
  130. </script>