send_chat.vue 8.7 KB

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