send_chat.vue 8.3 KB

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