send_chat.vue 9.4 KB

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