send_chat.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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"
  5. v-model="msgData.msg" :maxlength="999" :placeholder="placeholder"></textarea>
  6. <view class="size-26 m-t20 sys-weight-600">上传图片</view>
  7. <view class="image-content">
  8. <view class="image-box m-t20 r-10 m-r20" :key="pIndex" @click.stop="showImg(msgData.msg_img,pIndex)"
  9. v-for="(msgImg,pIndex) in msgData.msg_img">
  10. <image class="image-item wh-110" :src="msgImg.type===1?msgImg.url:getVideoImg(msgImg.url)"
  11. mode="aspectFill">
  12. </image>
  13. <image class="wh-45 video-icon" src="/static/img/task/play.png" mode="aspectFill"
  14. @click.stop="showVideoImg(msgImg.url)" v-if="msgImg.type === 2">
  15. </image>
  16. <image class="delete-iocn wh-25" src="/page_task/static/img/information/hint-subtract.png" mode=""
  17. @click.stop="shutImg(pIndex)"></image>
  18. </view>
  19. <view class="add-image column-c justify-center m-t20" @click.stop="showUploadingImg(true)">
  20. <image class="wh-45" src="/page_task/static/img/task-details/Maskoup.png" mode=""></image>
  21. <text class="size-24 text-color-666">视频/图片</text>
  22. </view>
  23. </view>
  24. <view class="size-26 m-tb20 sys-weight-600">上传附件</view>
  25. <view class="">
  26. <view class="sys-from-background-color row-justify-sb center p-20 m-b16 r-20"
  27. v-for="(file,fileIndex) in msgData.file_list" :key="fileIndex">
  28. <view class="row-c">
  29. <image class="wh-60 m-r20" src="/page_task/static/img/task-details/icon-pdf.png"
  30. v-if="file.file_type===1" mode="aspectFill"></image>
  31. <image class="wh-60 m-r20" src="/page_task/static/img/task-details/icon-word.png"
  32. v-else-if="file.file_type===2" mode="aspectFill"> </image>
  33. <image class="wh-60 m-r20" src="/page_task/static/img/task-details/icon-excel.png" v-else
  34. mode="aspectFill"> </image>
  35. <text class="size-24 text-color-666"> {{file.name}}</text>
  36. </view>
  37. <image class="delete-iocn wh-25" src="/page_task/static/img/information/hint-subtract.png"
  38. @click.stop="delFile(delFile)" mode=""></image>
  39. </view>
  40. <view class="sys-from-background-color row-c p-20 r-20" @click.stop="uploadingFile(5)">
  41. <image class="wh-80 m-r20" src="/page_task/static/img/task-details/add-file.png" mode="aspectFill">
  42. </image>
  43. <view class="column">
  44. <text class="select-file size-24">选择文件</text>
  45. <text class="size-24 text-color-666">支持上传文件:pdf、word、excel、ppt</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <EnButton v-if="is_button" @onSubmit="clickBut"></EnButton>
  51. <uni-popup ref="popup" type="bottom">
  52. <view class="popup-block">
  53. <view class="popup-row" @click="uploadingFile(1)">拍照</view>
  54. <view class="popup-row" @click="uploadingFile(2)">选择照片</view>
  55. <view class="popup-row" @click="uploadingFile(3)">录像</view>
  56. <view class="popup-row" @click="uploadingFile(4)">选择视频</view>
  57. <view class="popup-row" @click="showUploadingImg(false)">取消</view>
  58. </view>
  59. </uni-popup>
  60. <uni-popup ref="videoPopup" @change="closeVideoImg">
  61. <view class="video-box" v-if="videoUrl">
  62. <video class="myVideo" :src="videoUrl" :autoplay="true"></video>
  63. </view>
  64. </uni-popup>
  65. </view>
  66. </template>
  67. <script>
  68. import tools from "@/service/tools";
  69. import txUploadFile from "@/service/txOssSts";
  70. export default {
  71. props: {
  72. is_button: {
  73. type: Boolean,
  74. default: false
  75. },
  76. placeholder: {
  77. default: '留个言吧~~'
  78. }
  79. },
  80. data() {
  81. return {
  82. msgData: {
  83. business_id: '',
  84. msg: '',
  85. reply_id: 0,
  86. msg_img: [],
  87. file_list: [],
  88. },
  89. videoUrl:''
  90. }
  91. },
  92. watch: {
  93. 'msgData': {
  94. handler() {
  95. this.$emit('input', this.msgData)
  96. },
  97. deep: true
  98. }
  99. },
  100. methods: {
  101. closeVideoImg(e) {
  102. if (!e.show) {
  103. console.log('关闭视频了')
  104. this.videoUrl = ''
  105. }
  106. },
  107. showVideoImg(url){
  108. this.videoUrl = url
  109. this.$refs.videoPopup.open('center')
  110. },
  111. showImg(item, index) {
  112. let imgList=[]
  113. for (const imgListKey in this.msgData.msg_img) {
  114. if(this.msgData.msg_img[imgListKey].type===1){
  115. imgList.push(this.msgData.msg_img[imgListKey].url)
  116. }
  117. }
  118. uni.previewImage({
  119. urls: imgList,
  120. current: item.url,
  121. success: () => {}
  122. })
  123. },
  124. clickBut() {
  125. console.log('------butClick--------------')
  126. this.$emit('butClick')
  127. },
  128. delFile(fileIndex) {
  129. this.msgData.file_list.splice(fileIndex, 1)
  130. this.fileNum = -1
  131. },
  132. getVideoImg(url) {
  133. return tools.getOssVideo(url)
  134. },
  135. shutImg(indexT) {
  136. this.msgData.msg_img.splice(indexT, 1)
  137. },
  138. showUploadingImg(showImg) {
  139. if (showImg) {
  140. this.$refs.popup.open("bottom");
  141. } else {
  142. this.$refs.popup.close();
  143. }
  144. tools.hideLoading()
  145. },
  146. uploadingFile(fileType) {
  147. if (fileType < 3) {
  148. this.uploadingImg(fileType)
  149. } else if (fileType < 5) {
  150. this.uploadingVideo(fileType)
  151. } else {
  152. this.uploadingWord()
  153. }
  154. },
  155. uploadingWord() {
  156. tools.showLoading()
  157. wx.chooseMessageFile({
  158. count: 5, //默认100
  159. type: 'file', //默认100
  160. extension: ['pdf', 'doc', 'docx', 'xlsx', 'xls'],
  161. success: (res) => {
  162. console.log('---------------------------------------------');
  163. console.log(res);
  164. if (res.tempFiles.length > 0) {
  165. res.tempFiles.forEach((tempFilePath) => {
  166. console.log(tempFilePath)
  167. txUploadFile(tempFilePath.path).then((data) => {
  168. if (!data) {
  169. tools.error('图片上传失败')
  170. } else {
  171. console.log({
  172. 'name': tempFilePath.name,
  173. 'file_type': tools.getFileType(data
  174. .Location),
  175. 'url': data.Location
  176. })
  177. console.log(
  178. '---------------------------------------------'
  179. );
  180. this.msgData.file_list.push({
  181. 'name': tempFilePath.name,
  182. 'file_type': tools.getFileType(data
  183. .Location),
  184. 'url': data.Location
  185. })
  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. uploadingVideo(sourceType) {
  201. tools.showLoading()
  202. uni.chooseVideo({
  203. sizeType: "compressed",
  204. sourceType: [sourceType === 3 ? 'camera' : 'album'],
  205. success: (res) => {
  206. txUploadFile(res.tempFilePath).then((data) => {
  207. if (!data) {
  208. tools.error('视频上传失败')
  209. } else {
  210. setTimeout(() => {
  211. this.msgData.msg_img.push({
  212. 'type': 2,
  213. 'url': data.Location
  214. })
  215. }, 1500)
  216. }
  217. this.showUploadingImg(false);
  218. }).catch((e) => {
  219. tools.hideLoading()
  220. })
  221. },
  222. fail: (e) => {
  223. tools.hideLoading()
  224. }
  225. });
  226. },
  227. uploadingImg(sourceType) {
  228. tools.showLoading()
  229. uni.chooseMedia({
  230. mediaType: 'image',
  231. count: sourceType === 1 ? 1 : 9, //默认9
  232. sizeType: "compressed",
  233. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  234. success: (res) => {
  235. console.log(res)
  236. if (res.tempFiles.length > 0) {
  237. res.tempFiles.forEach((tempFile) => {
  238. txUploadFile(tempFile.tempFilePath).then((data) => {
  239. if (!data) {
  240. tools.error('图片上传失败')
  241. } else {
  242. this.msgData.msg_img.push({
  243. 'type': 1,
  244. 'url': data.Location
  245. })
  246. }
  247. })
  248. })
  249. this.showUploadingImg(false);
  250. } else {
  251. tools.error("请选择上传的图片")
  252. tools.hideLoading()
  253. }
  254. },
  255. fail: (e) => {
  256. tools.hideLoading()
  257. }
  258. });
  259. },
  260. }
  261. }
  262. </script>
  263. <style lang="scss" scoped>
  264. .textarea {
  265. width: calc(100% - 40rpx);
  266. max-height: 100rpx;
  267. }
  268. .popup-block {
  269. border-radius: 20rpx 20rpx 0rpx 0rpx;
  270. overflow: hidden;
  271. background-color: #f5f5f5;
  272. .popup-row {
  273. height: 100rpx;
  274. background-color: #fff;
  275. text-align: center;
  276. line-height: 100rpx;
  277. border-bottom: 2rpx solid #f5f5f5;
  278. &:nth-child(4) {
  279. margin-bottom: 20rpx;
  280. }
  281. &:last-child {
  282. height: 112rpx;
  283. border: none;
  284. line-height: 112rpx;
  285. }
  286. &:active {
  287. background-color: rgb(244, 244, 244);
  288. }
  289. }
  290. }
  291. .image-content {
  292. display: flex;
  293. flex-wrap: wrap;
  294. .image-box {
  295. position: relative;
  296. .image-item {
  297. width: 130rpx;
  298. height: 130rpx;
  299. border-radius: 10rpx;
  300. }
  301. .video-icon {
  302. position: absolute;
  303. top: 50%;
  304. left: 50%;
  305. transform: translate(-50%, -50%);
  306. }
  307. .delete-iocn {
  308. position: absolute;
  309. right: -10rpx;
  310. top: -10rpx;
  311. }
  312. }
  313. .add-image {
  314. width: 128rpx;
  315. height: 128rpx;
  316. border-radius: 10rpx;
  317. background: #F7F9FE;
  318. border: 1rpx dashed #999999;
  319. }
  320. }
  321. .select-file {
  322. width: 132rpx;
  323. height: 44rpx;
  324. background: #FFFFFF;
  325. border-radius: 6rpx;
  326. border: 1rpx solid #DDDDDD;
  327. line-height: 44rpx;
  328. text-align: center;
  329. display: inline-block;
  330. margin-bottom: 10rpx;
  331. }
  332. </style>