send_chat.vue 8.2 KB

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