send_chat.vue 8.4 KB

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