send_chat.vue 8.1 KB

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