add-msg.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <view class="msg-box">
  3. <view class="leave-message-box" >
  4. <view class="">
  5. <textarea v-model="msgData.msg" placeholder="留个言吧" :maxlength="999" auto-height />
  6. </view>
  7. <view class="img-box">
  8. <view class="credentials-img" @click="showImg(msgData.msg_img,pIndex)"
  9. v-for="(msgImg,pIndex) in msgData.msg_img">
  10. <image class="credentials-imgs" :src="msgImg.type===1?msgImg.url:getVideoImg(msgImg.url)" @error="" mode="aspectFill"></image>
  11. <image v-if="msgImg.type===2" class="video-img" src="@/static/task/video-img.png" mode=""></image>
  12. <image @click.stop="shutImg(pIndex)" class="gb-img" src="@/static/login/gb.png" mode=""></image>
  13. </view>
  14. <view class="credentials-img">
  15. <image class="img-box-img" @click="showUploadingImg(true)" src="/pages-task/static/add-client/scmb.png" mode=""></image>
  16. </view>
  17. </view>
  18. <view class="file-box">
  19. <view class="file-list">
  20. <view class="file-item" v-for="(file,fileIndex) in msgData.file_list">
  21. <view class="file-img">
  22. <image src="/static/task/file-icon.png"></image>
  23. <view class="img-icon" v-if="file.file_type===1">PDF</view>
  24. <view class="img-icon icon-four" v-else-if="file.file_type===2">Word</view>
  25. <view class="img-icon icon-two" v-else>XLS</view>
  26. </view>
  27. <view class="file-text">
  28. {{file.name}}
  29. </view>
  30. <view class="file-set" @click.stop="setFile(fileIndex)">
  31. <image src="/static/task/file-icon.png"></image>
  32. <view class="but-list" :class="{'but-list-show':fileNum===fileIndex}">
  33. <view class="but-item" @click.stop="editFile">重命名</view>
  34. <view class="but-item" @click.stop="delFile(fileIndex)">删除</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="add-file" @click="uploadingFile(5)">
  40. <view class="add-img">
  41. <image src="@/static/task/add-file.png"></image>
  42. </view>
  43. <view class="add-text">
  44. 上传附件文档
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <uni-popup ref="editPopup" type="bottom">
  50. <view class="popup-edit">
  51. <view class="edit-nav">
  52. 修改文件名
  53. </view>
  54. <en-input label="文件名" placeholder="请输入文件名" v-model="fileName"></en-input>
  55. <button class="edit-but" @click="setFileName">保存</button>
  56. </view>
  57. </uni-popup>
  58. <uni-popup ref="popup" type="bottom">
  59. <view class="popup-block">
  60. <view class="popup-row" @click="uploadingFile(1)">拍照</view>
  61. <view class="popup-row" @click="uploadingFile(2)">选择照片</view>
  62. <view class="popup-row" @click="uploadingFile(3)">录像</view>
  63. <view class="popup-row" @click="uploadingFile(4)">选择视频</view>
  64. <view class="popup-row" @click="showUploadingImg(false)">取消</view>
  65. </view>
  66. </uni-popup>
  67. </view>
  68. </template>
  69. <script>
  70. import txUploadFile from "@/common/js/txOssSts";
  71. import tools from "@/common/js/tools";
  72. import EnInput from "@/components/en-from/en-input/en-input";
  73. export default {
  74. name: "add-msg",
  75. components: {EnInput},
  76. props: {
  77. value:{
  78. default:{
  79. business_id: '',
  80. reply_id: 0,
  81. 'msg': '',
  82. 'msg_img': [],
  83. 'file_list': [],
  84. }
  85. }
  86. },
  87. data() {
  88. return {
  89. fileNum:-1,
  90. msgData:{
  91. 'msg': '',
  92. 'msg_img': [],
  93. 'file_list': [],
  94. },
  95. fileName:'',
  96. }
  97. },
  98. watch: {
  99. 'msgData':{
  100. handler() {
  101. this.$emit('input',this.msgData)
  102. },
  103. deep: true
  104. }
  105. },
  106. mounted() {
  107. this.msgData=this.value
  108. },
  109. methods: {
  110. setFile(fileIndex){
  111. this.fileNum=fileIndex
  112. },
  113. setFileName(){
  114. if( this.fileName===''){
  115. tools.error('请输入文件名称')
  116. return
  117. }
  118. this.msgData.file_list[this.fileNum].name=this.fileName
  119. this.$refs.editPopup.close();
  120. this.fileNum=-1
  121. },
  122. editFile(){
  123. this.fileName=this.msgData.file_list[this.fileNum].name;
  124. this.$refs.editPopup.open("bottom");
  125. },
  126. delFile(fileIndex){
  127. this.msgData.file_list.splice(fileIndex, 1)
  128. this.fileNum=-1
  129. },
  130. getVideoImg(url){
  131. return tools.getOssVideo(url)
  132. },
  133. shutImg(indexT) {
  134. this.msgData.msg_img.splice(indexT, 1)
  135. },
  136. showImg(item, index) {
  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({'name':tempFilePath.name,'file_type':tools.getFileType(data.Location),'url':data.Location})
  172. console.log('---------------------------------------------');
  173. this.msgData.file_list.push({'name':tempFilePath.name,'file_type':tools.getFileType(data.Location),'url':data.Location})
  174. }
  175. })
  176. })
  177. this.showUploadingImg(false);
  178. } else {
  179. tools.error("请选择上传文件")
  180. tools.hideLoading()
  181. }
  182. },
  183. fail:(e)=>{
  184. tools.hideLoading()
  185. }
  186. });
  187. },
  188. uploadingVideo(sourceType){
  189. tools.showLoading()
  190. uni.chooseVideo({
  191. sizeType: "compressed",
  192. sourceType: [sourceType === 3 ? 'camera' : 'album'],
  193. success: (res) =>{
  194. txUploadFile(res.tempFilePath).then((data) => {
  195. if (!data) {
  196. tools.error('视频上传失败')
  197. } else {
  198. setTimeout(()=>{
  199. this.msgData.msg_img.push({'type':2,'url':data.Location})
  200. },1500)
  201. }
  202. this.showUploadingImg(false);
  203. }).catch((e)=>{
  204. tools.hideLoading()
  205. })
  206. },
  207. fail:(e)=>{
  208. tools.hideLoading()
  209. }
  210. });
  211. },
  212. uploadingImg(sourceType) {
  213. tools.showLoading()
  214. uni.chooseMedia({
  215. mediaType: 'image',
  216. count: sourceType === 1 ? 1 : 9, //默认9
  217. sizeType: "compressed",
  218. sourceType: [sourceType === 1 ? 'camera' : 'album'],
  219. success: (res) => {
  220. console.log(res)
  221. if (res.tempFiles.length > 0) {
  222. res.tempFiles.forEach((tempFile) => {
  223. txUploadFile(tempFile.tempFilePath).then((data) => {
  224. if (!data) {
  225. tools.error('图片上传失败')
  226. } else {
  227. this.msgData.msg_img.push({'type':1,'url':data.Location})
  228. }
  229. })
  230. })
  231. this.showUploadingImg(false);
  232. } else {
  233. tools.error("请选择上传的图片")
  234. tools.hideLoading()
  235. }
  236. },
  237. fail:(e)=>{
  238. tools.hideLoading()
  239. }
  240. });
  241. },
  242. }
  243. }
  244. </script>
  245. <style scoped lang="scss">
  246. .msg-box{
  247. .popup-block {
  248. border-radius: 20rpx 20rpx 0rpx 0rpx;
  249. overflow: hidden;
  250. background-color: #f5f5f5;
  251. .popup-row {
  252. height: 100rpx;
  253. background-color: #fff;
  254. text-align: center;
  255. line-height: 100rpx;
  256. border-bottom: 2rpx solid #f5f5f5;
  257. &:nth-child(4) {
  258. margin-bottom: 20rpx;
  259. }
  260. &:last-child {
  261. height: 112rpx;
  262. border: none;
  263. line-height: 112rpx;
  264. }
  265. &:active {
  266. background-color: rgb(244, 244, 244);
  267. }
  268. }
  269. }
  270. .popup-edit{
  271. border-radius: 20rpx 20rpx 0rpx 0rpx;
  272. overflow: hidden;
  273. background-color: #fff;
  274. padding: 20rpx;
  275. min-height: 50vh;
  276. position: relative;
  277. .edit-nav {
  278. font-size: 18px;
  279. font-weight: bold;
  280. text-align: center;
  281. padding: 30rpx 0 15rpx;
  282. background: #fff;
  283. }
  284. .edit-but{
  285. margin-top: 20rpx;
  286. height: 88rpx;
  287. line-height: 88rpx;
  288. text-align: center;
  289. font-size: 32rpx;
  290. background: #3169FA;
  291. color: #fff;
  292. position: absolute;
  293. bottom: 20rpx;
  294. width: calc(100vw - 20rpx);
  295. }
  296. }
  297. .leave-message-box {
  298. width: 100%;
  299. height: auto;
  300. padding: 36rpx 30rpx 52rpx;
  301. box-sizing: border-box;
  302. background: #fff;
  303. .img-box {
  304. width: 100%;
  305. height: auto;
  306. display: flex;
  307. flex-wrap: wrap;
  308. padding: 40rpx 0 0 0;
  309. .credentials-img {
  310. width: calc((100vw - 92rpx)/3);
  311. height: calc((100vw - 92rpx)/3);
  312. margin-right:16rpx;
  313. position: relative;
  314. .credentials-imgs {
  315. width: calc((100vw - 92rpx)/3);
  316. height: calc((100vw - 92rpx)/3);
  317. display: block;
  318. }
  319. .video-img{
  320. position: absolute;
  321. top:calc(50% - 28rpx);
  322. left:calc(50% - 28rpx);
  323. width: 56rpx;
  324. height: 56rpx;
  325. }
  326. .gb-img {
  327. width: 32rpx;
  328. height: 32rpx;
  329. position: absolute;
  330. right: 0;
  331. top: 0;
  332. z-index: 2;
  333. }
  334. .img-box-img {
  335. width: calc((100vw - 92rpx)/3);
  336. height: calc((100vw - 92rpx)/3);
  337. }
  338. }
  339. .credentials-img:nth-of-type(3n+0){
  340. margin-right:0;
  341. }
  342. .credentials-img:nth-of-type(n+4){
  343. margin-top:16rpx;
  344. }
  345. }
  346. .file-box{
  347. .file-list{
  348. .file-item{
  349. height:72rpx;
  350. padding: 39rpx 2rpx;
  351. display: flex;
  352. justify-content: left;
  353. .file-img{
  354. height: 72rpx;
  355. width: 72rpx;
  356. position: relative;
  357. .img-icon{
  358. position: absolute;
  359. left: 0;
  360. top: 37rpx;
  361. width: 32rpx;
  362. height: 20rpx;
  363. background: #F24949;
  364. font-weight: 600;
  365. color: #FFFFFF;
  366. font-size: 12rpx;
  367. line-height: 20rpx;
  368. text-align: center;
  369. }
  370. .icon-two{
  371. background: #00BF72;
  372. }
  373. .icon-three{
  374. background: #F9742C;
  375. }
  376. .icon-four{
  377. background: #0083FB;
  378. }
  379. image{
  380. height: 72rpx;
  381. width: 72rpx;
  382. }
  383. }
  384. .file-text{
  385. margin-left: 24rpx;
  386. width: calc(100vw - 214rpx);
  387. height: 72rpx;
  388. line-height: 72rpx;
  389. color: #333333;
  390. display: -webkit-box;
  391. -webkit-line-clamp: 1;
  392. -webkit-box-orient: vertical;
  393. overflow: hidden;
  394. }
  395. .file-set{
  396. margin-top:21rpx ;
  397. width: 30rpx;
  398. position: relative;
  399. image{
  400. width: 30rpx;
  401. height: 30rpx;
  402. }
  403. .but-list{
  404. display: none;
  405. position: absolute;
  406. width: 168rpx;
  407. height: 204rpx;
  408. left: -200rpx;
  409. top: 15rpx;
  410. background: rgba(51,51,51,0.39);
  411. border-radius: 8rpx;
  412. padding-left: 32rpx;
  413. .but-item{
  414. height: 102rpx;
  415. line-height: 102rpx;
  416. font-size: 32rpx;
  417. color: #FFFFFF;
  418. }
  419. }
  420. .but-list-show{
  421. display: block;
  422. }
  423. }
  424. }
  425. }
  426. .add-file{
  427. height:72rpx;
  428. padding: 39rpx 2rpx;
  429. display: flex;
  430. justify-content: left;
  431. .add-img{
  432. height: 72rpx;
  433. width: 72rpx;
  434. image{
  435. height: 72rpx;
  436. width: 72rpx;
  437. }
  438. }
  439. .add-text{
  440. height: 72rpx;
  441. line-height: 72rpx;
  442. color: #333333;
  443. margin-left: 16rpx;
  444. }
  445. }
  446. }
  447. }
  448. }
  449. </style>