send_chat.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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" v-model="msgData.msg" :maxlength="999"
  5. placeholder="留个言吧"></textarea>
  6. <view class="size-26 m-t20 sys-weight-600">上传图片</view>
  7. <view class="image-content">
  8. <view class="image-box" :key="index" @click="showImg(msgData.msg_img,pIndex)"
  9. v-for="(msgImg,pIndex) in msgData.msg_img">
  10. <image class="image-item wh-110 m-t20 r-10 m-r20" :src="msgImg.type===1?msgImg.url:getVideoImg(msgImg.url)" mode="aspectFill">
  11. </image>
  12. <image class="delete-iocn wh-25" src="/static/img/information/hint-subtract.png" mode="" @click.stop="shutImg(pIndex)"></image>
  13. </view>
  14. <view class="add-image column-c justify-center m-t20" @click.stop="showUploadingImg(true)">
  15. <image class="wh-45" src="/static/img/task-details/Mask oup.png" mode=""></image>
  16. <text class="size-24 text-color-666">视频/图片</text>
  17. </view>
  18. </view>
  19. <view class="size-26 m-tb20 sys-weight-600">上传附件</view>
  20. <view class="">
  21. <view class="sys-from-background-color row-justify-sb center p-20 m-b16 r-20" v-for="(file,fileIndex) in msgData.file_list"
  22. :key="fileIndex">
  23. <view class="row-c">
  24. <image class="wh-60 m-r20" src="/static/img/task-details/icon-word.png" mode="aspectFill">
  25. </image>
  26. <text class="size-24 text-color-666"> {{file.name}}</text>
  27. </view>
  28. <image class="delete-iocn wh-25" src="/static/img/information/hint-subtract.png" @click.stop="delFile(delFile)" mode=""></image>
  29. </view>
  30. <view class="sys-from-background-color row-c p-20 r-20" @click.stop="uploadingFile(5)">
  31. <image class="wh-80 m-r20" src="/static/img/task-details/add-file.png" mode="aspectFill">
  32. </image>
  33. <view class="column">
  34. <text class="select-file size-24">选择文件</text>
  35. <text class="size-24 text-color-666">支持上传文件:pdf、word、excel、ppt</text>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <EnButton v-if="is_button"></EnButton>
  41. <uni-popup ref="popup" type="bottom">
  42. <view class="popup-block">
  43. <view class="popup-row" @click="uploadingFile(1)">拍照</view>
  44. <view class="popup-row" @click="uploadingFile(2)">选择照片</view>
  45. <view class="popup-row" @click="uploadingFile(3)">录像</view>
  46. <view class="popup-row" @click="uploadingFile(4)">选择视频</view>
  47. <view class="popup-row" @click="showUploadingImg(false)">取消</view>
  48. </view>
  49. </uni-popup>
  50. </view>
  51. </template>
  52. <script>
  53. import tools from "@/service/tools";
  54. import txUploadFile from "@/service/txOssSts";
  55. export default {
  56. props: {
  57. is_button: {
  58. type: Boolean,
  59. default: false
  60. }
  61. },
  62. data() {
  63. return {
  64. msgData: {
  65. business_id: '',
  66. msg: '',
  67. reply_id: 0,
  68. msg_img: [],
  69. file_list: [],
  70. },
  71. }
  72. },
  73. methods: {
  74. delFile(fileIndex){
  75. this.msgData.file_list.splice(fileIndex, 1)
  76. this.fileNum=-1
  77. },
  78. getVideoImg(url){
  79. return tools.getOssVideo(url)
  80. },
  81. shutImg(indexT) {
  82. this.msgData.msg_img.splice(indexT, 1)
  83. },
  84. showUploadingImg(showImg) {
  85. if (showImg) {
  86. this.$refs.popup.open("bottom");
  87. } else {
  88. this.$refs.popup.close();
  89. }
  90. tools.hideLoading()
  91. },
  92. uploadingFile(fileType){
  93. if(fileType<3){
  94. this.uploadingImg(fileType)
  95. }else if(fileType<5){
  96. this.uploadingVideo(fileType)
  97. }else {
  98. this.uploadingWord()
  99. }
  100. },
  101. uploadingWord(){
  102. tools.showLoading()
  103. wx.chooseMessageFile({
  104. count: 5, //默认100
  105. type: 'file', //默认100
  106. extension:['pdf','doc','docx','xlsx','xls'],
  107. success: (res)=> {
  108. console.log('---------------------------------------------');
  109. console.log(res);
  110. if (res.tempFiles.length > 0) {
  111. res.tempFiles.forEach((tempFilePath) => {
  112. console.log(tempFilePath)
  113. txUploadFile(tempFilePath.path).then((data) => {
  114. if (!data) {
  115. tools.error('图片上传失败')
  116. } else {
  117. console.log({'name':tempFilePath.name,'file_type':tools.getFileType(data.Location),'url':data.Location})
  118. console.log('---------------------------------------------');
  119. this.msgData.file_list.push({'name':tempFilePath.name,'file_type':tools.getFileType(data.Location),'url':data.Location})
  120. }
  121. })
  122. })
  123. this.showUploadingImg(false);
  124. } else {
  125. tools.error("请选择上传文件")
  126. tools.hideLoading()
  127. }
  128. },
  129. fail:(e)=>{
  130. tools.hideLoading()
  131. }
  132. });
  133. },
  134. uploadingVideo(sourceType){
  135. tools.showLoading()
  136. uni.chooseVideo({
  137. sizeType: "compressed",
  138. sourceType: [sourceType === 3 ? 'camera' : 'album'],
  139. success: (res) =>{
  140. txUploadFile(res.tempFilePath).then((data) => {
  141. if (!data) {
  142. tools.error('视频上传失败')
  143. } else {
  144. setTimeout(()=>{
  145. this.msgData.msg_img.push({'type':2,'url':data.Location})
  146. },1500)
  147. }
  148. this.showUploadingImg(false);
  149. }).catch((e)=>{
  150. tools.hideLoading()
  151. })
  152. },
  153. fail:(e)=>{
  154. tools.hideLoading()
  155. }
  156. });
  157. },
  158. uploadingImg(sourceType) {
  159. tools.showLoading()
  160. uni.chooseMedia({
  161. mediaType: 'image',
  162. count: sourceType === 1 ? 1 : 9, //默认9
  163. sizeType: "compressed",
  164. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  165. success: (res) => {
  166. console.log(res)
  167. if (res.tempFiles.length > 0) {
  168. res.tempFiles.forEach((tempFile) => {
  169. txUploadFile(tempFile.tempFilePath).then((data) => {
  170. if (!data) {
  171. tools.error('图片上传失败')
  172. } else {
  173. this.msgData.msg_img.push({'type':1,'url':data.Location})
  174. }
  175. })
  176. })
  177. this.showUploadingImg(false);
  178. } else {
  179. tools.error("请选择上传的图片")
  180. tools.hideLoading()
  181. }
  182. },
  183. fail:(e)=>{
  184. tools.hideLoading()
  185. }
  186. });
  187. },
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .textarea {
  193. width: calc(100% - 40rpx);
  194. max-height: 100rpx;
  195. }
  196. .popup-block {
  197. border-radius: 20rpx 20rpx 0rpx 0rpx;
  198. overflow: hidden;
  199. background-color: #f5f5f5;
  200. .popup-row {
  201. height: 100rpx;
  202. background-color: #fff;
  203. text-align: center;
  204. line-height: 100rpx;
  205. border-bottom: 2rpx solid #f5f5f5;
  206. &:nth-child(4) {
  207. margin-bottom: 20rpx;
  208. }
  209. &:last-child {
  210. height: 112rpx;
  211. border: none;
  212. line-height: 112rpx;
  213. }
  214. &:active {
  215. background-color: rgb(244, 244, 244);
  216. }
  217. }
  218. }
  219. .image-content {
  220. display: flex;
  221. flex-wrap: wrap;
  222. .image-box {
  223. position: relative;
  224. .image-item {
  225. width: 130rpx;
  226. height: 130rpx;
  227. border-radius: 10rpx;
  228. }
  229. .delete-iocn {
  230. position: absolute;
  231. right: 12rpx;
  232. top: 12rpx;
  233. }
  234. }
  235. .add-image {
  236. width: 128rpx;
  237. height: 128rpx;
  238. border-radius: 10rpx;
  239. background: #F7F9FE;
  240. border: 1rpx dashed #999999;
  241. }
  242. }
  243. .select-file {
  244. width: 132rpx;
  245. height: 44rpx;
  246. background: #FFFFFF;
  247. border-radius: 6rpx;
  248. border: 1rpx solid #DDDDDD;
  249. line-height: 44rpx;
  250. text-align: center;
  251. display: inline-block;
  252. margin-bottom: 10rpx;
  253. }
  254. </style>