add-file.vue 5.1 KB

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