collection.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view>
  3. <!-- <view class="tab ddflex">
  4. <view :class="'li ' + (type == 1 ? 'active' : '')" @click="swiType(1)">动态</view>
  5. <view :class="'li ' + (type == 2 ? 'active' : '')" @click="swiType(2)">提问</view>
  6. </view> -->
  7. <!-- <view class="placeholder-view"></view> -->
  8. <view class="list" v-if="pageList && pageList.length > 0">
  9. <view class="li" v-for="(item, index) in pageList" :key="index">
  10. <view class="user ddflex" @click="toUserHomePage(item.userDTO.id)">
  11. <image :src="item.userDTO.avatar" mode="aspectFill" class="userimg"></image>
  12. <view class="fflex">
  13. <view class="namea ddflex">
  14. <view class="name fflex ddflex">
  15. {{ item.userDTO.nickName }}
  16. <image v-if="item.userDTO.levelGrade > 0" src="../../static/images/vip_tag.png" class="vip-tag"></image>
  17. </view>
  18. <view class="time">{{ item.time }}</view>
  19. </view>
  20. <view class="area" v-if="item.userDTO.cityName">{{ item.userDTO.provinceName }} {{ item.userDTO.cityName }}</view>
  21. </view>
  22. </view>
  23. <!-- 分享的动态 -->
  24. <block v-if="item.source">
  25. <view class="link ddflex" @click="jumpUrlDetail(item)">
  26. <block v-if="item.url&&item.url.length > 0"><image mode="aspectFill" v-if="idx == 0" v-for="(it, idx) in item.url" :src="it" :key="idx"></image></block>
  27. <view class="fflex tover"><rich-text :nodes="item.content"></rich-text></view>
  28. </view>
  29. </block>
  30. <!-- 非分享的动态 -->
  31. <block v-else>
  32. <view v-if="item.type == 2" class="des tovers" @click="jumpUrlDetail(item)">
  33. <view class="wen">提问</view>
  34. {{ removeHtml(item.content) }}
  35. </view>
  36. <view class="des" v-else @click="jumpUrlDetail(item)"><rich-text :nodes="item.content"></rich-text></view>
  37. <!-- //如果有投票,就不显示图片 -->
  38. <block v-if="!item.qyPoll">
  39. <view class="video" v-if="item.isHaveVideo">
  40. <video :src="item.url" :show-center-play-btn="false" :controls="item.isControls" :autoplay="item.isControls" :id="'myVideo'+index" @pause="videoPause(index)" @ended="videoEnded(index)"></video>
  41. <view class="video-play ddflex" @click="videoPlay(index)" v-if="item.isShowPlayBtn"><image src="../../static/images/play.png"></image></view>
  42. </view>
  43. <view class="imgbox ddflex" @click="jumpUrlDetail(item)" v-else><!-- @click="previewImgss(item.url, idx)" -->
  44. <block v-if="item.url&&item.url.length>0">
  45. <image mode="aspectFill" v-for="(it, idx) in item.url" :src="it" :key="idx"></image>
  46. </block>
  47. </view>
  48. </block>
  49. <!-- 话题 -->
  50. <view class="ddflex" v-if="item.qyDialogu">
  51. <view class="topic ddflex" @click="jumpUrl('/topics/detail/detail?topicId=' + item.qyDialogu.id)">
  52. <image src="../../static/images/topic.png"></image>
  53. {{ item.qyDialogu.title }}
  54. </view>
  55. </view>
  56. <!-- 投票 -->
  57. <view :class="'vote-box' + (item.qyPoll&&item.qyPoll.isEnd ? ' ends' : '')" v-if="item.qyPoll">
  58. <view class="vote-tit">{{ item.qyPoll.title }}</view>
  59. <block v-if="item.qyPoll.isVote == 1">
  60. <view class="vote-list end" @click="jumpUrlDetail(item)">
  61. <view :class="'lis ddflex ' + (itpy.isVote == 1 ? 'active' : '')" v-for="(itpy, idex) in JSON.parse(item.qyPoll.optionJson)" :key="idex">
  62. <view class="percent" :style="'width:' + parseFloat(itpy.proportion) + '%;'"></view>
  63. <view class="fflex">{{ itpy.name }}</view>
  64. <view>{{ parseFloat(itpy.proportion) + '%' }}</view>
  65. </view>
  66. </view>
  67. </block>
  68. <block v-else>
  69. <view class="vote-list">
  70. <view class="lis" v-for="(itpy, idex) in JSON.parse(item.qyPoll.optionJson)" :key="idex" @click="submitPoll(item, index, idex)">
  71. {{ itpy.name }}
  72. </view>
  73. </view>
  74. </block>
  75. <view class="vote-can" v-if="item.qyPoll.isEnd"><text>{{item.qyPoll.voteCount}}人参与</text>投票已结束</view>
  76. </view>
  77. <view class="product" v-if="item.products && item.products.length > 0">
  78. <view scroll-x="true" :class="'pro-view' + (item.products.length == 1 ? ' pro-view1' : '')">
  79. <view class="li" v-for="(it, idx) in item.products" :key="idx" @click="toProductDetail(it)">
  80. <view class="ddflex">
  81. <image :src="it.pic" mode="aspectFill" class="pro-pic"></image>
  82. <view class="fflex">
  83. <view class="title tovers">{{ it.title }}</view>
  84. <view class="opts ddflex">
  85. <view class="money">¥{{ it.salePrice }}</view>
  86. <view class="pro-btn" @click="toProductDetail(it)">购买</view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </block>
  94. <view class="opt ddflex" v-if="!item.source">
  95. <view class="fflex" @click="jumpUrlDetail(item)">{{ item.count.browseCount }}次浏览</view>
  96. <view class="ddflex" @click="submitFabulous(2, item.id, index)">
  97. <image :src="'../../static/images/' + (item.isPraise == 1 ? 'like_h' : 'like') + '.png'"></image>
  98. {{ item.count.fabulousCount < 99 ? item.count.fabulousCount : '99+' }}
  99. </view>
  100. <view class="ddflex" @click="jumpUrlDetail(item)">
  101. <image src="../../static/images/comment.png"></image>
  102. {{ item.count.commentCount < 99 ? item.count.commentCount : '99+' }}
  103. </view>
  104. <button open-type="share" class="opt-share ddflex">
  105. <image src="../../static/images/share.png"></image>
  106. 分享
  107. </button>
  108. </view>
  109. </view>
  110. </view>
  111. <view class="nodata" v-else>
  112. <image :src="picUrlss + 'empty_jl.png'"></image>
  113. <text>{{ type == 1 ? '暂无动态' : type == 2 ? '暂无提问' : '' }}</text>
  114. </view>
  115. </view>
  116. </template>
  117. <script>
  118. const app = getApp();
  119. const req = require('../../utils/request.js');
  120. const api = require('../../utils/api.js');
  121. const util = require('../../utils/util.js');
  122. export default {
  123. data() {
  124. return {
  125. picUrlss: req.public.picUrls,
  126. systems: {},
  127. userInfo: '',
  128. isLoad: true,
  129. form: {
  130. page: 1,
  131. limit: 10
  132. },
  133. type: 1, //1 聊一聊,2提问
  134. pageList: [],
  135. isShowView: false,
  136. videoCurrent: null,
  137. videoContext: ''
  138. };
  139. },
  140. onLoad() {
  141. this.getOfficeList();
  142. },
  143. onReachBottom() {
  144. this.form.page++;
  145. this.getOfficeList();
  146. },
  147. methods: {
  148. jumpUrl(url) {
  149. uni.navigateTo({
  150. url: url
  151. });
  152. },
  153. jumpCollection() {
  154. if (this.userId == this.userInfo.id) {
  155. this.jumpUrl('/topics/collection/collection');
  156. }
  157. },
  158. removeHtml(content) {
  159. return util.removeHtml(content);
  160. },
  161. //预览图片
  162. previewImgss(picUrls, index) {
  163. //预览合同图片
  164. var src = picUrls[index];
  165. let imgs = picUrls;
  166. uni.previewImage({
  167. current: src, // 当前显示图片的http链接
  168. urls: imgs
  169. });
  170. },
  171. jumpUrlDetail(item) {
  172. if (item.source) {
  173. this.jumpUrl('/office/detail/detail?contentId=' + item.source);
  174. } else {
  175. this.jumpUrl('/office/detail/detail?contentId=' + item.id);
  176. }
  177. },
  178. toProductDetail(it) {
  179. if (!req.isLogins(true)) {
  180. return;
  181. }
  182. if(it.actId){
  183. app.globalData.openPage('group/detail/detail?id=' + it.id + '&groupId=' + it.actId);
  184. }else{
  185. app.globalData.openPage('product/detail/detail?id=' + it.id);
  186. }
  187. },
  188. toUserHomePage(userId) {
  189. this.jumpUrl('/topics/home/home?userId=' + userId);
  190. },
  191. //切换类型
  192. swiType(type) {
  193. this.isLoad = true;
  194. this.form.page = 1;
  195. this.type = type;
  196. this.getOfficeList();
  197. },
  198. sum(arr) {
  199. var s = 0;
  200. for (var i=arr.length-1; i>=0; i--) {
  201. if(arr[i].count){
  202. s += Number(arr[i].count);
  203. }
  204. }
  205. return s;
  206. },
  207. getOfficeList() {
  208. let that = this;
  209. var pramData = this.form;
  210. pramData.type = this.type;
  211. pramData.fabulousType = 5;
  212. if (!this.isLoad) return false;
  213. this.isLoad = false;
  214. req.getRequest('/api/v3/moments/collectionList', pramData, data => {
  215. if(data&&data.length > 0){
  216. data.map(it=>{
  217. if(it.qyPoll && it.qyPoll.isEnd){
  218. it.qyPoll.voteCount = that.sum(JSON.parse(it.qyPoll.optionJson))
  219. }
  220. if(it.url){
  221. let h = it.url.substring(it.url.lastIndexOf('.') + 1)
  222. if(h.indexOf('mp4')<0&&h.indexOf('MP4')<0){
  223. it.url = it.url.split(',');
  224. }else{
  225. it.isHaveVideo = true
  226. it.isControls = false
  227. it.isShowPlayBtn = true
  228. }
  229. }
  230. it.content = '<div style="overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 5;-webkit-box-orient: vertical;word-break: break-all;">' + it.content + '</div>'
  231. return it;
  232. })
  233. }
  234. if (data && data.length >= this.form.limit) {
  235. this.isLoad = true;
  236. }
  237. if (this.form.page > 1) {
  238. data = this.pageList.concat(data);
  239. }
  240. this.pageList = data;
  241. this.isShowView = true;
  242. });
  243. },
  244. //提交点赞、取消点赞;收藏、取消收藏
  245. submitFabulous(type, id, index) {
  246. if (!req.isLogins(true)) {
  247. return;
  248. }
  249. var dataP = {};
  250. dataP.type = type; //1,观看 ,2点赞,3评论,4分享,5收藏
  251. dataP.momentsId = id;
  252. req.postRequestLoding('/api/v3/fabulous/save', dataP, data => {
  253. if (type == 2) {
  254. //动态点赞
  255. if (this.pageList[index].isPraise == 1) {
  256. //已赞
  257. this.pageList[index].isPraise = 0;
  258. this.pageList[index].count.fabulousCount--;
  259. } else {
  260. this.pageList[index].isPraise = 1;
  261. this.pageList[index].count.fabulousCount++;
  262. }
  263. }
  264. });
  265. },
  266. //提交投票
  267. submitPoll(item, pIndex, pollIndex) {
  268. var dataP = {};
  269. // dataP.id = item.id;
  270. dataP.pollId = item.qyPoll.id;
  271. var pollObjList = JSON.parse(item.qyPoll.optionJson);
  272. dataP.pollOptionCode = pollObjList[pollIndex].code;
  273. req.postRequest('/api/v3/poll/saveDetails', dataP, data => {
  274. req.msg('投票成功');
  275. //图片完之后要将该投票的对象返回,便于做渲染%
  276. this.pageList[pIndex].qyPoll = data;
  277. });
  278. },
  279. videoPlay(index){
  280. var that = this;
  281. var curIdx = index;
  282. this.pageList[index].isControls = true
  283. this.pageList[index].isShowPlayBtn = false
  284. // 有播放时先将prev暂停,再播放当前点击的current
  285. if (that.videoCurrent != null) {
  286. var videoContextPrev = uni.createVideoContext('myVideo' + that.videoCurrent)
  287. if (that.videoCurrent != curIdx) {
  288. this.pageList[that.videoCurrent].isControls = false
  289. this.pageList[that.videoCurrent].isShowPlayBtn = true
  290. videoContextPrev.stop()
  291. }
  292. that.videoCurrent = curIdx
  293. var videoContextCurrent = uni.createVideoContext('myVideo' + curIdx)
  294. videoContextCurrent.play()
  295. } else {
  296. // 没有播放时播放视频
  297. that.videoCurrent = curIdx
  298. var videoContext = uni.createVideoContext('myVideo' + curIdx) // 对应的视频id
  299. videoContext.play()
  300. }
  301. },
  302. videoPause(index){
  303. this.pageList[index].isControls = false
  304. this.pageList[index].isShowPlayBtn = true
  305. },
  306. videoEnded(index){
  307. this.pageList[index].isControls = false
  308. this.pageList[index].isShowPlayBtn = true
  309. }
  310. }
  311. };
  312. </script>
  313. <style>
  314. @import './collection.css';
  315. </style>