send_chat.vue 8.6 KB

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