add-file.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="text-color-12">
  3. <view class="p-30">
  4. <textarea class="sys-from-background-color r-20 textarea p-20" name="" id="" cols="30" rows="10"
  5. v-model="msgData.msg" :maxlength="999" :placeholder="placeholder"></textarea>
  6. <view class="size-26 m-tb20 sys-weight-600">上传附件</view>
  7. <view class="">
  8. <view class="sys-from-background-color row-justify-sb center p-20 m-b16 r-20"
  9. v-for="(file,fileIndex) in msgData.file_list" :key="fileIndex">
  10. <view class="row-c">
  11. <image class="wh-60 m-r20" src="/page_subpack/static/img/task-details/icon-pdf.png"
  12. v-if="file.file_type===1" mode="aspectFill"></image>
  13. <image class="wh-60 m-r20" src="/page_subpack/static/img/task-details/icon-word.png"
  14. v-else-if="file.file_type===2" mode="aspectFill"> </image>
  15. <image class="wh-60 m-r20" src="/page_subpack/static/img/task-details/icon-excel.png" v-else
  16. mode="aspectFill"> </image>
  17. <text class="size-24 text-color-666"> {{file.name}}</text>
  18. </view>
  19. <image class="delete-iocn wh-25" src="/page_subpack/static/img/task-details/hint-subtract.png"
  20. @click.stop="delFile(fileIndex)" mode=""></image>
  21. </view>
  22. <view class="sys-from-background-color row-c p-20 r-20" @click.stop="uploadingWord()">
  23. <image class="wh-80 m-r20" src="/page_subpack/static/img/task-details/add-file.png" mode="aspectFill">
  24. </image>
  25. <view class="column">
  26. <text class="select-file size-24">选择文件</text>
  27. <text class="size-24 text-color-666">支持上传文件:pdf</text>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <EnButton @onSubmit="clickBut"></EnButton>
  33. </view>
  34. </template>
  35. <script>
  36. import tools from "@/service/tools";
  37. import txUploadFile from "@/service/txOssSts";
  38. import {addTransferPdf} from "@/api/transfer";
  39. export default {
  40. props: {
  41. is_button: {
  42. type: Boolean,
  43. default: false
  44. },
  45. placeholder: {
  46. default: '留个言吧~~'
  47. }
  48. },
  49. data() {
  50. return {
  51. msgData: {
  52. business_id: '',
  53. msg: '',
  54. reply_id: 0,
  55. msg_img: [],
  56. file_list: [],
  57. },
  58. videoUrl:'',
  59. isAjax: false,
  60. }
  61. },
  62. methods: {
  63. clickBut() {
  64. if (this.isAjax) {
  65. return;
  66. }
  67. addTransferPdf(this.msgData).then((res) => {
  68. if (res.code === 1) {
  69. tools.success(res.msg)
  70. this.$emit('newMsg')
  71. this.msgData.msg=''
  72. this.msgData.file_list=[]
  73. } else {
  74. tools.error(res.msg)
  75. this.isAjax = false;
  76. }
  77. })
  78. },
  79. delFile(fileIndex) {
  80. this.msgData.file_list.splice(fileIndex, 1)
  81. this.fileNum = -1
  82. },
  83. uploadingWord() {
  84. tools.showLoading()
  85. wx.chooseMessageFile({
  86. count: 5, //默认100
  87. type: 'file', //默认100
  88. extension: ['pdf'],
  89. success: (res) => {
  90. console.log('---------------------------------------------');
  91. console.log(res);
  92. if (res.tempFiles.length > 0) {
  93. res.tempFiles.forEach((tempFilePath) => {
  94. console.log(tempFilePath)
  95. txUploadFile(tempFilePath.path).then((data) => {
  96. if (!data) {
  97. tools.error('上传失败')
  98. } else {
  99. console.log({
  100. 'name': tempFilePath.name,
  101. 'file_type': tools.getFileType(data
  102. .Location),
  103. 'url': data.Location
  104. })
  105. this.msgData.file_list.push({
  106. 'name': tempFilePath.name,
  107. 'file_type': tools.getFileType(data .Location),
  108. 'url': data.Location
  109. })
  110. }
  111. })
  112. })
  113. tools.hideLoading()
  114. } else {
  115. tools.error("请选择上传文件")
  116. tools.hideLoading()
  117. }
  118. },
  119. fail: (e) => {
  120. tools.hideLoading()
  121. }
  122. });
  123. },
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .nav {
  129. font-size: 18px;
  130. font-weight: bold;
  131. text-align: center;
  132. padding: 30rpx 0 15rpx;
  133. background: #fff;
  134. }
  135. .textarea {
  136. width: calc(100% - 40rpx);
  137. max-height: 100rpx;
  138. }
  139. .popup-block {
  140. border-radius: 20rpx 20rpx 0rpx 0rpx;
  141. overflow: hidden;
  142. background-color: #f5f5f5;
  143. .popup-row {
  144. height: 100rpx;
  145. background-color: #fff;
  146. text-align: center;
  147. line-height: 100rpx;
  148. border-bottom: 2rpx solid #f5f5f5;
  149. &:nth-child(4) {
  150. margin-bottom: 20rpx;
  151. }
  152. &:last-child {
  153. height: 112rpx;
  154. border: none;
  155. line-height: 112rpx;
  156. }
  157. &:active {
  158. background-color: rgb(244, 244, 244);
  159. }
  160. }
  161. }
  162. .image-content {
  163. display: flex;
  164. flex-wrap: wrap;
  165. .image-box {
  166. position: relative;
  167. .image-item {
  168. width: 130rpx;
  169. height: 130rpx;
  170. border-radius: 10rpx;
  171. }
  172. .video-icon {
  173. position: absolute;
  174. top: 50%;
  175. left: 50%;
  176. transform: translate(-50%, -50%);
  177. }
  178. .delete-iocn {
  179. position: absolute;
  180. right: -10rpx;
  181. top: -10rpx;
  182. }
  183. }
  184. .add-image {
  185. width: 128rpx;
  186. height: 128rpx;
  187. border-radius: 10rpx;
  188. background: #F7F9FE;
  189. border: 1rpx dashed #999999;
  190. }
  191. }
  192. .select-file {
  193. width: 132rpx;
  194. height: 44rpx;
  195. background: #FFFFFF;
  196. border-radius: 6rpx;
  197. border: 1rpx solid #DDDDDD;
  198. line-height: 44rpx;
  199. text-align: center;
  200. display: inline-block;
  201. margin-bottom: 10rpx;
  202. }
  203. </style>