add-file.vue 6.1 KB

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