collect.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="app">
  3. <uni-nav-bar statusBar backgroundColor="#fff" fixed title="我要转发" left-icon="left" @clickLeft="utils.navigateBack()"/>
  4. <view class="app">
  5. <view class="list" v-for="(item,index) in data">
  6. <view class="img" v-if="item.type == 'img'" @tap="tapOpen(index)">
  7. <image :src="item.data" mode="widthFix"></image>
  8. </view>
  9. <view class="text" v-if="item.type == 'text'" @tap="tapOpen(index)">
  10. {{item.data}}
  11. </view>
  12. <view class="text" v-if="item.type == 'voice'" @tap="tapOpen(index)">
  13. [语音文件{{parseInt(item.data.time/1000)}}秒]
  14. </view>
  15. <view class="info fx-r">
  16. <view class="nickname">{{item.nickname}}</view>
  17. <view class="time">{{item.time}}</view>
  18. </view>
  19. <view class="pop-del" @tap="tapDel(index)"><image src="/static/img/search_del.png"></image></view>
  20. </view>
  21. <view class="loading fx-r fx-ac fx-bc" v-if="page.isFrite && !page.isFoot">
  22. <image src="/static/chat/xloading.png"></image>
  23. <text>正在载入更多...</text>
  24. </view>
  25. <view class="loading complete" :hidden="!page.isFoot">已加载全部</view>
  26. </view>
  27. <view class="app-win fx-h fx-bc fx-ac" v-if="isPop">
  28. <view class="bg"></view>
  29. <view class="body">
  30. <view class="title">发送给:</view>
  31. <view class="nicknam-info fx-r fx-bc">
  32. <image :src="avatar" mode="aspectFill"></image>
  33. <view class="nickname">{{nickname}}</view>
  34. </view>
  35. <view class="img fx-h fx-bc fx-ac" style="height: 300px;" v-if="inData.type == 'text'">
  36. {{inData.data}}
  37. </view>
  38. <view class="img fx-h fx-bc fx-ac" style="height: 300px;" v-if="inData.type == 'img'">
  39. <image :src="inData.data" mode="widthFix" @tap="tapOpenImg(inData.data)"></image>
  40. </view>
  41. <view style="height: 300px;" v-if="inData.type == 'voice'">
  42. <view class="voice" @tap="playa(inData.id,inData.data.filePath)">
  43. <view class="i"></view>
  44. <text style="color: #2c2c2c;,margin-right: 3rpx;margin-right: 60px;">{{parseInt(inData.data.time/1000)}} "</text>
  45. <image v-if="playMsgId != inData.id" src="/static/chat/yyy.png" style="width: 15px;height: 15px; margin-left:4px;" mode="widthFix"></image>
  46. <image v-if="playMsgId == inData.id" src="/static/chat/yyy.gif" style="width: 15px;height: 15px; margin-left:4px;" mode="widthFix"></image>
  47. </view>
  48. </view>
  49. <view class="btns fx-r">
  50. <view class="btn" @tap="isPop = false">取消</view>
  51. <view class="btn btn2" @tap="tapSend">确认</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <style lang="scss">
  58. .app-win{ position: fixed;width: 100%;height: 100%;top: 0;left: 0;z-index: 9;}
  59. .app-win .bg{background: rgba(0, 0, 0, 0.5); width: 100%;height: 100%;top: 0;left: 0;position: absolute;}
  60. .app-win .body{background: #fff;border-radius: 8px;position: relative;z-index: 8;padding-bottom: 0;width: 80%;}
  61. .app-win .body .title{padding: 10px;}
  62. .nicknam-info{padding: 10px;}
  63. .nicknam-info image{width: 40px;height: 40px;border-radius: 40px;}
  64. .nicknam-info .nickname{margin-left: 8px;}
  65. .btns{height: 50px;}
  66. .btns .btn{ width: 50%;text-align: center;line-height: 50px;color: #787878;}
  67. .btns .btn2{background: $ic-appcolor;color: #fff;border-radius: 0 0 6px 0;}
  68. .img image{width: 150px;margin: 10px 0;}
  69. .voice{margin: 10px;position: relative;min-height: 20px;font-size: 16px;background-color: #cceaff;max-width: calc(100% - 140rpx);padding: 20rpx;border-radius: 8rpx;word-break:break-all;display:inline-block;}
  70. .voice .i{width: 0;height: 0;right: -10px;position: absolute;border-top: 10px solid transparent; border-left: 10px solid #cceaff; border-bottom: 10px solid transparent;}
  71. </style>
  72. <script>
  73. import {mapState,mapMutations } from 'vuex';
  74. export default {
  75. computed: mapState(['user']),
  76. data() {
  77. return {
  78. data: [],
  79. nickname:"",
  80. groupId : 0,
  81. avatar : "",
  82. isPop:false,
  83. inData : {},
  84. img:"",
  85. playlyurl:"",
  86. playMsgId:"",
  87. page:{
  88. isFirst:false,
  89. isLoad:false,
  90. isFoot:false,
  91. page:1
  92. }
  93. }
  94. },
  95. onLoad(option) {
  96. //获取订单
  97. this.nickname = option.nickname || "";
  98. this.groupId = option.groupId || 0;
  99. this.avatar = option.avatar || "";
  100. this.getData();
  101. },
  102. onReachBottom() {
  103. if(this.page.isFoot || this.page.isLoad) {
  104. return;
  105. }
  106. this.page.page ++;
  107. this.getData();
  108. },
  109. methods: {
  110. getData:function(isPull = false){
  111. if(this.page.isLoad) return;
  112. this.page.isLoad = true;
  113. if(isPull) {
  114. this.page.page = 1;
  115. this.page.isLoad = false;
  116. this.page.isFoot = false;
  117. }
  118. uni.showLoading({ title: '获取数据中..' });
  119. var post = {};
  120. post.page = this.page.page;
  121. this
  122. .request
  123. .post("chatCollect",post)
  124. .then(res => {
  125. uni.hideLoading();
  126. this.page.isFirst = true;
  127. this.page.isLoad = false;
  128. res.data.listData = this.inJson(res.data.listData);
  129. if(isPull) {
  130. this.data = res.data.listData;
  131. } else {
  132. this.data = this.data.concat(res.data.listData);
  133. }
  134. //是否到底
  135. if(res.data.listData.length != res.data.pageSize) {
  136. this.page.isFoot = true;
  137. }
  138. })
  139. .catch(res=>{
  140. console.log(res);
  141. uni.hideLoading();
  142. uni.showModal({title: '系统提示',content: '加载失败,返回在尝试',showCancel: false});
  143. });
  144. },
  145. tapOpen:function(index){
  146. this.isPop = true;
  147. this.inData = this.data[index];
  148. },
  149. /**
  150. * 发送数据
  151. */
  152. tapSend:function(){
  153. uni.showLoading({ title: '提交中..' });
  154. this
  155. .request
  156. .post("chatCollectSend",{
  157. msg_id : this.inData['msg_id'],
  158. groupId : this.groupId
  159. })
  160. .then(res=>{
  161. uni.hideLoading();
  162. if(res.code == 200) {
  163. this.utils.Tip("发送成功");
  164. setTimeout(()=>{
  165. uni.navigateBack();
  166. },200);
  167. } else {
  168. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  169. }
  170. })
  171. .catch(err=>{
  172. uni.hideLoading();
  173. uni.showModal({title: '系统提示',content: '加载失败,返回在尝试',showCancel: false});
  174. });
  175. },
  176. tapDel:function(index) {
  177. this.utils.showModal("你确定要删除吗?", ()=>{
  178. uni.showLoading({ title:"提交数据中..." });
  179. this
  180. .request
  181. .post("chatCollectDel",{id:this.data[index].id})
  182. .then(res=>{
  183. uni.hideLoading();
  184. if(res.code == 200) {
  185. this.utils.Tip("删除成功");
  186. this.$delete(this.data,index);
  187. } else {
  188. this.utils.Tip(res.msg);
  189. }
  190. })
  191. .catch(err=>{
  192. uni.hideLoading();
  193. this.utils.Tip("加载失败,请重新尝试");
  194. });
  195. });
  196. },
  197. inJson:function(data){
  198. for(var i in data){
  199. if(this.utils.isJSON(data[i].data)) {
  200. data[i].data = JSON.parse(data[i].data);
  201. }
  202. }
  203. return data;
  204. },
  205. tapOpenImg:function(img){
  206. uni.previewImage({current:0,urls:[img]});
  207. },
  208. playa:function(msgId,filePath){
  209. var innerAudioContext = uni.createInnerAudioContext();
  210. innerAudioContext.autoplay = true;
  211. if(this.playlyurl == filePath){
  212. this.playlyurl = ''
  213. innerAudioContext.stop()
  214. }else{
  215. this.playlyurl = filePath;
  216. this.playMsgId = msgId;
  217. innerAudioContext.src = filePath;
  218. innerAudioContext.play()
  219. innerAudioContext.onEnded(()=>{
  220. this.playlyurl = ''
  221. this.playMsgId = "";
  222. })
  223. }
  224. }
  225. }
  226. }
  227. </script>
  228. <style>
  229. .app .list{padding: 20px;position: relative;background-color: #fff;margin-top: 10px;}
  230. .app .list .info{font-size: 14px;color: #787878;}
  231. .app .list .info .time{margin-left: 10px;}
  232. .app .list .img image{max-width: 180px;border-radius: 6px;}
  233. .pop-del{position: absolute;right: 10px;top: 10px;}
  234. .pop-del image{width: 18px;height: 18px;}
  235. </style>