recommendBox.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div>
  3. <div class="recommend-box" v-if="show_recommendList.length > 0">
  4. <h2 class="recommend-title">推荐内容</h2>
  5. <ul class="recommend-list-box finger-point">
  6. <li class="recommend-list-item" v-for="(item, index) in show_recommendList" :key="index" @click="getMicroDetails(item.id)">
  7. <p class="top">
  8. <span class="rank">{{index+1}}</span>
  9. <span class="article-title overflow-hide">{{item.title}}</span>
  10. <span class="watch-num">
  11. <i class="iconfont icon-fontclass-yulan"></i>
  12. {{item.browse_num}}
  13. </span>
  14. </p>
  15. <p class="article-content overflow-hide"><span v-html="item.contents"></span></p>
  16. </li>
  17. </ul>
  18. <p class="change-item finger-point" v-if="recommend_total>5" @click.stop="changeRecommend">
  19. <i class="iconfont icon-fontclass-gengxin"></i><span>换一批</span>
  20. </p>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. props: {},
  27. data() {
  28. return {
  29. recommend_page: 1,
  30. recommend_total: 0,
  31. recommendList: [],
  32. show_recommend_index: 0,
  33. show_recommendList: [],
  34. };
  35. },
  36. mounted() {
  37. this.getRecommendTrick();
  38. },
  39. methods: {
  40. getMicroDetails(stickid) {
  41. if(this.fun.getSiteRoot() == "http://localhost:82") {
  42. this.toUrl('microcommentdetails-tid',{tid: stickid})
  43. }else {
  44. window.open(this.fun.getSiteRoot() + `/plugins/shop_server/microcommentdetails/${stickid}?i=` +this.fun.getKeyByI(), "_blank");
  45. }
  46. },
  47. toUrl(url, params) {
  48. this.$router.push(this.fun.getUrl(url, params));
  49. },
  50. changeRecommend() {
  51. // console.log(this.show_recommend_index,this.recommendList.length,this.recommend_total)
  52. if(this.show_recommend_index + 5 > this.recommend_total) {
  53. this.show_recommend_index = 0;
  54. }
  55. if(this.show_recommend_index + 5 >= this.recommendList.length && this.recommendList.length < this.recommend_total) {
  56. this.recommend_page += 1;
  57. this.getRecommendTrick()
  58. }
  59. this.show_recommend_index = this.show_recommend_index + 5;
  60. this.show_recommendList = this.recommendList.slice(this.show_recommend_index,this.show_recommend_index + 5);
  61. },
  62. getRecommendTrick() {
  63. this.fun.$get("plugin.micro-communities.api.pc.index.recommendTrick", {page: this.recommend_page}, "load").then(response => {
  64. if (response.result == 1) {
  65. this.recommend_total = response.data.total;
  66. if(this.recommend_total > 0) {
  67. this.$emit('changeRecommend', true);
  68. }
  69. this.recommendList = this.recommendList.concat(response.data.data || []);
  70. this.show_recommendList = this.recommendList.slice(this.show_recommend_index,this.show_recommend_index+5);
  71. } else {
  72. this.$message.error(response.msg);
  73. }
  74. });
  75. },
  76. }
  77. };
  78. </script>
  79. <style lang="scss" rel="stylesheet/scss" scoped>
  80. .recommend-box {
  81. margin-top: 8px;
  82. background-color: #ffffff;
  83. .recommend-title {
  84. padding: 15px 20px;
  85. border-bottom: 1px solid #efefef;
  86. }
  87. .recommend-list-item {
  88. position: relative;
  89. margin: 0 19px;
  90. padding: 16px 0;
  91. .top {
  92. display: flex;
  93. align-items: center;
  94. margin-bottom: 10px;
  95. }
  96. .rank {
  97. font-size: 16px;
  98. font-weight: 600;
  99. letter-spacing: 8px;
  100. color: #ec544a;
  101. }
  102. .article-title {
  103. flex: 1;
  104. width: 0;
  105. color: #2a2a2a;
  106. font-weight: bold;
  107. }
  108. .watch-num {
  109. margin-left: 8px;
  110. color: #6b6b6b;
  111. }
  112. .article-content {
  113. width: 240px;
  114. height: 20px;
  115. color: #6b6b6b;
  116. }
  117. }
  118. .recommend-list-item:hover {
  119. .article-title {
  120. color: var(--color);
  121. }
  122. }
  123. .recommend-list-item::after {
  124. position: absolute;
  125. content: '';
  126. left: 0;
  127. bottom: 0;
  128. width: 100%;
  129. height: 1px;
  130. background-color: #e4e4e4;
  131. }
  132. .recommend-list-item:nth-child(4), .recommend-list-item:nth-child(5) {
  133. .rank{
  134. color: #ff8200;
  135. }
  136. }
  137. .change-item {
  138. padding: 10px 0;
  139. text-align: center;
  140. letter-spacing: 1px;
  141. color: #555555;
  142. .icon-fontclass-gengxin {
  143. margin-right: 5px;
  144. vertical-align: middle;
  145. }
  146. }
  147. }
  148. </style>