index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="discover_recommend">
  3. <scroll-view v-if="noteRecommendList.length>0" scroll-y="true" :show-scrollbar="false" class="scroll-view" :style="'height:'+swiperHeight+'px'"
  4. id="recommendList" @scrolltolower="onTouchmoveRecommend" @scroll="followScroll">
  5. <discover-details v-if="noteRecommendList.length>0" @getIsMore="getIsMore" @getComment="getComment"
  6. type="list" :noteRecommendList="noteRecommendList"></discover-details>
  7. <view class='loadingicon acea-row row-center-wrapper'>
  8. <text class='loading iconfont icon-jiazai' :hidden='loading==false && noteDetails'></text>{{loadTitle}}
  9. </view>
  10. </scroll-view>
  11. <view class="empty-boxs" v-if="isShow">
  12. <emptyPage title="内容不存在,可能被删除了噢~" mTop="31%" :imgSrc="urlDomain+'crmebimage/presets/noguanzhu.png'"></emptyPage>
  13. <view class="btn" url="/pages/discover_index/index" @click="back">返回首页</view>
  14. </view>
  15. <!-- 评论 -->
  16. <uni-popup type="bottom" ref="comment">
  17. <view
  18. :style="'width: '+ windowWidth +'px; background-color: #fff; border-top-left-radius: 10px; border-top-right-radius: 10px;'">
  19. <discoverComment v-if="showComment" @getReplyNum="getReplyNum" :noteId="noteDetails.id"
  20. :noteDetails="noteDetails" @close="close">
  21. </discoverComment>
  22. </view>
  23. </uni-popup>
  24. </view>
  25. </template>
  26. <script>
  27. import emptyPage from '@/components/emptyPage.vue'
  28. import discoverDetails from '@/components/discoverDetails/index.vue'
  29. import discoverComment from '@/components/discoverComment/index.vue'
  30. import {
  31. noteRecommendApi,
  32. noteDetailApi
  33. } from '@/api/discover.js';
  34. export default {
  35. components: {
  36. discoverDetails,
  37. discoverComment,
  38. emptyPage
  39. },
  40. data() {
  41. return {
  42. urlDomain: this.$Cache.get("imgHost"),
  43. windowWidth: 0, //获取屏幕宽度🌟💗
  44. swiperHeight: 0,
  45. noteRecommendList: [], // 发现内容推荐列表
  46. loaded: false,
  47. loading: false,
  48. loadTitle: '加载更多',
  49. where: {
  50. page: 1,
  51. limit: 10,
  52. noteId: '' //内容id
  53. },
  54. noteDetails: {}, //内容详情
  55. isShow: false, //内容是否被删掉
  56. showComment: false, //评论弹窗
  57. windowHeight: 0,
  58. isWidth: 0
  59. }
  60. },
  61. onLoad: function(options) {
  62. this.windowWidth = uni.getSystemInfoSync().screenWidth; //获取屏幕宽度
  63. this.where.noteId = options.noteId ? options.noteId : '';
  64. this.getNoteRecommend(); // 推荐
  65. this.getNoteDetail(options.noteId);
  66. },
  67. created() {
  68. var that = this;
  69. // 获取设备宽度
  70. uni.getSystemInfo({
  71. success(e) {
  72. that.isWidth = e.windowWidth / 6;
  73. that.windowHeight = e.windowHeight;
  74. that.swiperHeight = that.windowHeight
  75. that.$set(that, 'swiperHeight', that.windowHeight);
  76. }
  77. });
  78. },
  79. onReachBottom() {
  80. this.getNoteRecommend(); // 推荐
  81. },
  82. // 滚动监听
  83. onPageScroll(e) {
  84. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  85. uni.$emit('scroll');
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. // #ifdef MP
  91. onShareAppMessage: function(res) {
  92. let data = res.target.dataset;
  93. return {
  94. title: data.title || '',
  95. imageUrl: data.cover || '',
  96. path: 'pages/discover/discover_details/index?noteId=' + data.id + '&sd=' + data.uid,
  97. }
  98. },
  99. // #endif
  100. methods: {
  101. /**
  102. * 列表滑动中用到的方法
  103. */
  104. followScroll() {
  105. uni.$emit('scroll');
  106. },
  107. onTouchmoveRecommend(e) {
  108. this.getNoteRecommend();
  109. },
  110. close() {
  111. uni.showTabBar();
  112. this.showComment = false;
  113. this.$refs.comment.close();
  114. },
  115. getReplyNum(n) {
  116. this.noteDetails.replyNum = n;
  117. },
  118. // 点击评论
  119. getComment(item) {
  120. this.showComment = false;
  121. this.noteDetails = item;
  122. uni.hideTabBar();
  123. this.$refs.comment.open('bottom');
  124. this.showComment = true;
  125. },
  126. //返回首页
  127. back() {
  128. uni.switchTab({
  129. url: '/pages/discover_index/index'
  130. })
  131. this.$util.backPageRefresh();
  132. },
  133. getIsMore(i) {
  134. this.noteRecommendList[i].isMore = true;
  135. },
  136. //此页面,最上面展示当前内容的详情,底下为推荐的内容列表
  137. // 内容详情
  138. getNoteDetail(noteId) {
  139. this.loading = true;
  140. noteDetailApi(noteId).then(res => {
  141. this.noteRecommendList.unshift(res.data)
  142. this.noteDetails = res.data
  143. this.loading = false;
  144. }).catch(err => {
  145. this.isShow = true;
  146. uni.showToast({
  147. title: err,
  148. icon: 'none'
  149. })
  150. this.loading = false;
  151. });
  152. },
  153. // 内容发现推荐列表
  154. getNoteRecommend: function() {
  155. let that = this;
  156. if (that.loadend) return;
  157. if (that.loading) return;
  158. that.loading = true;
  159. that.loadTitle = '';
  160. that.where.title = encodeURIComponent(this.searchValue);
  161. noteRecommendApi(that.where).then(res => {
  162. that.$set(that.where, 'page', that.where.page + 1);
  163. this.noteRecommendList = this.noteRecommendList.concat(res.data.list || []);
  164. that.loadend = that.where.page > res.data.totalPage;
  165. that.loading = false;
  166. that.loadTitle = that.loadend ? '已全部加载' : '加载更多';
  167. this.noteRecommendList.map(item => {
  168. item.isMore = false;
  169. })
  170. }).catch(err => {
  171. that.loading = false;
  172. uni.showToast({
  173. title: err,
  174. icon: 'none'
  175. })
  176. });
  177. },
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .btn {
  183. width: 440rpx;
  184. text-align: center;
  185. padding: 15rpx 0;
  186. @include main_color(theme);
  187. @include coupons_border_color(theme);
  188. border-radius: 40rpx;
  189. margin: 44rpx auto 0;
  190. font-size: 32rpx;
  191. }
  192. .discover_recommend {
  193. background-color: #fff;
  194. /deep/.no-border {
  195. bottom: 40rpx;
  196. }
  197. }
  198. </style>