index-bak.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="discover-details">
  3. <!-- #ifdef MP || APP-PLUS-->
  4. <!-- <nav-bar iconColor='#fff' navTitle='内容详情' :isBackgroundColor="false" ref="navBarRef" :isHeight="false">
  5. </nav-bar> -->
  6. <!-- #endif -->
  7. <discover-details v-if="noteDetail && !loading" :noteRecommendList="noteDetail" type="detail"
  8. @getComment="getComment" @onChangeReplyStatus="onChangeReplyStatus" :imageH="imageH"
  9. :isShowCommentView="isShowCommentView"></discover-details>
  10. <view class='loadingicon acea-row row-center-wrapper' :hidden='loading==false'>
  11. <text class='loading iconfont icon-jiazai'></text>
  12. </view>
  13. <view class="commen_details borderPad" id="myElement">
  14. <view v-if="noteDetail.platReplySwitch" class="commen_count" id="commen_count">
  15. 评论<span class="ml10">{{noteDetail.replyNum == 0 ? '' : noteDetail.replyNum}}</span></view>
  16. <view>
  17. <discoverComment v-if="noteDetail" :noteId="noteId" :noteDetails="noteDetail" :isClickBtn="isClickBtn"
  18. fromTo="pageView" :isShowCommentView="isShowCommentView" @closeModelComment="closeModelComment">
  19. </discoverComment>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import discoverDetails from '@/components/discoverDetails/index.vue'
  26. import discoverComment from '@/components/discoverComment/index.vue'
  27. import navBar from '@/components/navBar';
  28. import {
  29. noteDetailApi
  30. } from '@/api/discover.js';
  31. import {
  32. silenceBindingSpread,
  33. getUserSpread
  34. } from '@/utils/index.js';
  35. import {
  36. mapGetters
  37. } from "vuex";
  38. import onShare from "../../../mixins/onShare";
  39. export default {
  40. components: {
  41. discoverDetails,
  42. discoverComment,
  43. navBar
  44. },
  45. mixins: [onShare],
  46. computed: mapGetters(['isLogin', 'uid', 'globalData']),
  47. data() {
  48. return {
  49. noteDetail: {}, //内容详情
  50. content: '',
  51. bottomVal: 0,
  52. placeholder: "快来说点儿什么吧...",
  53. loading: false,
  54. isShowComment: false, //真实评论弹窗显示隐藏
  55. noteId: 0,
  56. showComment: false, //评论弹窗
  57. imageH: 0, //图片高度
  58. appear: false,
  59. elementId: 'myElement',
  60. observer: null,
  61. isShowCommentView: false, //评论列表是否出现
  62. isClickBtn: false, //是否点击了评论按钮,
  63. title: '内容详情'
  64. }
  65. },
  66. onLoad: function(options) {
  67. let pages = getCurrentPages()
  68. this.noteId = Number(options.noteId);
  69. this.getNoteDetail(options.noteId);
  70. //分销码
  71. getUserSpread(options);
  72. },
  73. onReady() {
  74. setTimeout(() => {
  75. // 创建监听器
  76. this.observer = uni.createIntersectionObserver(this);
  77. // 监听评论列表是否出现
  78. this.observer.relativeToViewport('#myElement').observe('#commen_count', (res) => {
  79. // res.intersectionRatio 为相交区域和元素的比例
  80. if (res.intersectionRatio > 0) {
  81. this.isShowCommentView = true
  82. // 元素进入可视区域
  83. } else {
  84. this.isShowCommentView = false
  85. this.isClickBtn = false
  86. // 元素离开可视区域
  87. }
  88. });
  89. }, 500)
  90. },
  91. onUnload() {
  92. // 页面销毁时,停止监听
  93. if (this.observer) {
  94. this.observer.disconnect();
  95. }
  96. },
  97. onShow() {
  98. //分销绑定
  99. silenceBindingSpread(this.isLogin, this.globalData.spread);
  100. },
  101. methods: {
  102. // 计算图片高度
  103. computedHeight() {
  104. let that = this;
  105. if (this.noteDetail.image) {
  106. let windowWidth = uni.getSystemInfoSync().windowWidth;
  107. uni.getImageInfo({
  108. src: that.$util.setDomain(this.noteDetail.image.split(',')[0]),
  109. success: (image) => {
  110. let imageH = parseInt(image.height * windowWidth / image.width);
  111. if (imageH > 500) {
  112. this.isAuto = false;
  113. this.imageH = 500;
  114. } else {
  115. this.imageH = imageH;
  116. }
  117. }
  118. })
  119. }
  120. },
  121. getReplyNum(n) {
  122. this.noteRecommendListNew[this.noteIndex].replyNum = n;
  123. },
  124. //触发评论输入框出现
  125. getComment(item) {
  126. this.showComment = true;
  127. this.isClickBtn = true
  128. this.noteDetails = item;
  129. },
  130. closeModelComment() {
  131. this.isClickBtn = false
  132. },
  133. //关闭评论回调
  134. onChangeReplyStatus(replyStatus) {
  135. if (replyStatus === 1) {
  136. this.$set(this.noteDetail, 'replyStatus', 2)
  137. this.$util.Tips({
  138. title: '禁止成功'
  139. });
  140. } else {
  141. this.$set(this.noteDetail, 'replyStatus', 1)
  142. this.$util.Tips({
  143. title: '开启成功'
  144. });
  145. }
  146. },
  147. // 内容详情
  148. getNoteDetail(noteId) {
  149. noteDetailApi(noteId).then(res => {
  150. this.loading = true;
  151. this.noteDetail = res.data;
  152. this.noteRecommendList = res.data;
  153. this.computedHeight()
  154. this.loading = false;
  155. }).catch(err => {
  156. this.loading = false;
  157. uni.showToast({
  158. title: err,
  159. icon: 'none'
  160. })
  161. });
  162. },
  163. }
  164. }
  165. </script>
  166. <style scoped lang="scss">
  167. /deep/.container {
  168. padding-bottom: 0 !important;
  169. }
  170. .commen_details {
  171. /deep/.container {
  172. height: auto !important;
  173. }
  174. /deep/.main_content {
  175. padding: 30rpx 0 !important;
  176. }
  177. }
  178. .commen_count {
  179. font-size: 26rpx;
  180. color: #282828;
  181. margin: 40rpx 0 0 0;
  182. // min-height: 1px;
  183. }
  184. .discover-details {
  185. padding-bottom: calc(80rpx+ constant(safe-area-inset-bottom)) !important; ///兼容 IOS<11.2/
  186. padding-bottom: calc(80rpx + env(safe-area-inset-bottom));
  187. background-color: #fff;
  188. }
  189. .details {
  190. padding-bottom: calc(40rpx+ constant(safe-area-inset-bottom)) !important; ///兼容 IOS<11.2/
  191. padding-bottom: calc(40rpx + env(safe-area-inset-bottom));
  192. }
  193. .lang {
  194. width: 560rpx !important;
  195. }
  196. .send {
  197. font-size: 26rpx;
  198. color: #ffffff;
  199. width: 120rpx;
  200. height: 62rpx;
  201. line-height: 62rpx;
  202. text-align: center;
  203. @include linear-gradient(theme);
  204. border-radius: 30rpx;
  205. text-align: center;
  206. }
  207. .details {
  208. background-color: #fff;
  209. }
  210. </style>