send_chat.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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" @click.stop=""></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. watch: {
  74. 'msgData':{
  75. handler() {
  76. this.$emit('input',this.msgData)
  77. },
  78. deep: true
  79. }
  80. },
  81. methods: {
  82. delFile(fileIndex){
  83. this.msgData.file_list.splice(fileIndex, 1)
  84. this.fileNum=-1
  85. },
  86. getVideoImg(url){
  87. return tools.getOssVideo(url)
  88. },
  89. shutImg(indexT) {
  90. this.msgData.msg_img.splice(indexT, 1)
  91. },
  92. showUploadingImg(showImg) {
  93. if (showImg) {
  94. this.$refs.popup.open("bottom");
  95. } else {
  96. this.$refs.popup.close();
  97. }
  98. tools.hideLoading()
  99. },
  100. uploadingFile(fileType){
  101. if(fileType<3){
  102. this.uploadingImg(fileType)
  103. }else if(fileType<5){
  104. this.uploadingVideo(fileType)
  105. }else {
  106. this.uploadingWord()
  107. }
  108. },
  109. uploadingWord(){
  110. tools.showLoading()
  111. wx.chooseMessageFile({
  112. count: 5, //默认100
  113. type: 'file', //默认100
  114. extension:['pdf','doc','docx','xlsx','xls'],
  115. success: (res)=> {
  116. console.log('---------------------------------------------');
  117. console.log(res);
  118. if (res.tempFiles.length > 0) {
  119. res.tempFiles.forEach((tempFilePath) => {
  120. console.log(tempFilePath)
  121. txUploadFile(tempFilePath.path).then((data) => {
  122. if (!data) {
  123. tools.error('图片上传失败')
  124. } else {
  125. console.log({'name':tempFilePath.name,'file_type':tools.getFileType(data.Location),'url':data.Location})
  126. console.log('---------------------------------------------');
  127. this.msgData.file_list.push({'name':tempFilePath.name,'file_type':tools.getFileType(data.Location),'url':data.Location})
  128. }
  129. })
  130. })
  131. this.showUploadingImg(false);
  132. } else {
  133. tools.error("请选择上传文件")
  134. tools.hideLoading()
  135. }
  136. },
  137. fail:(e)=>{
  138. tools.hideLoading()
  139. }
  140. });
  141. },
  142. uploadingVideo(sourceType){
  143. tools.showLoading()
  144. uni.chooseVideo({
  145. sizeType: "compressed",
  146. sourceType: [sourceType === 3 ? 'camera' : 'album'],
  147. success: (res) =>{
  148. txUploadFile(res.tempFilePath).then((data) => {
  149. if (!data) {
  150. tools.error('视频上传失败')
  151. } else {
  152. setTimeout(()=>{
  153. this.msgData.msg_img.push({'type':2,'url':data.Location})
  154. },1500)
  155. }
  156. this.showUploadingImg(false);
  157. }).catch((e)=>{
  158. tools.hideLoading()
  159. })
  160. },
  161. fail:(e)=>{
  162. tools.hideLoading()
  163. }
  164. });
  165. },
  166. uploadingImg(sourceType) {
  167. tools.showLoading()
  168. uni.chooseMedia({
  169. mediaType: 'image',
  170. count: sourceType === 1 ? 1 : 9, //默认9
  171. sizeType: "compressed",
  172. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  173. success: (res) => {
  174. console.log(res)
  175. if (res.tempFiles.length > 0) {
  176. res.tempFiles.forEach((tempFile) => {
  177. txUploadFile(tempFile.tempFilePath).then((data) => {
  178. if (!data) {
  179. tools.error('图片上传失败')
  180. } else {
  181. this.msgData.msg_img.push({'type':1,'url':data.Location})
  182. }
  183. })
  184. })
  185. this.showUploadingImg(false);
  186. } else {
  187. tools.error("请选择上传的图片")
  188. tools.hideLoading()
  189. }
  190. },
  191. fail:(e)=>{
  192. tools.hideLoading()
  193. }
  194. });
  195. },
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .textarea {
  201. width: calc(100% - 40rpx);
  202. max-height: 100rpx;
  203. }
  204. .popup-block {
  205. border-radius: 20rpx 20rpx 0rpx 0rpx;
  206. overflow: hidden;
  207. background-color: #f5f5f5;
  208. .popup-row {
  209. height: 100rpx;
  210. background-color: #fff;
  211. text-align: center;
  212. line-height: 100rpx;
  213. border-bottom: 2rpx solid #f5f5f5;
  214. &:nth-child(4) {
  215. margin-bottom: 20rpx;
  216. }
  217. &:last-child {
  218. height: 112rpx;
  219. border: none;
  220. line-height: 112rpx;
  221. }
  222. &:active {
  223. background-color: rgb(244, 244, 244);
  224. }
  225. }
  226. }
  227. .image-content {
  228. display: flex;
  229. flex-wrap: wrap;
  230. .image-box {
  231. position: relative;
  232. .image-item {
  233. width: 130rpx;
  234. height: 130rpx;
  235. border-radius: 10rpx;
  236. }
  237. .delete-iocn {
  238. position: absolute;
  239. right: 12rpx;
  240. top: 12rpx;
  241. }
  242. }
  243. .add-image {
  244. width: 128rpx;
  245. height: 128rpx;
  246. border-radius: 10rpx;
  247. background: #F7F9FE;
  248. border: 1rpx dashed #999999;
  249. }
  250. }
  251. .select-file {
  252. width: 132rpx;
  253. height: 44rpx;
  254. background: #FFFFFF;
  255. border-radius: 6rpx;
  256. border: 1rpx solid #DDDDDD;
  257. line-height: 44rpx;
  258. text-align: center;
  259. display: inline-block;
  260. margin-bottom: 10rpx;
  261. }
  262. </style>