oneIndex.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view>
  3. <view class="searchType" style="background: #fff;">
  4. <view class="input-view">
  5. <uni-icon type="search" size="22" color="#666666" />
  6. <input disabled="true" confirm-type="search" class="input" type="text" placeholder="搜索文章" @click="confirm" />
  7. </view>
  8. </view>
  9. <view>
  10. <van-tabs :active="active" @change="onChange">
  11. <van-tab v-for="(item,index) in typelist" :key="index" :name="index" :title="item.ac_name"></van-tab>
  12. </van-tabs>
  13. </view>
  14. <scroll-view class="floor-list"
  15. :scroll-top="scrollTop" style="height: 90vh;" scroll-y="true" @scroll="scroll" @scrolltoupper="upper" @scrolltolower="lower"
  16. :refresher-enabled="false">
  17. <view v-for="(item,indedx) in acrelist" :key="indedx" @click="goIndex(item)">
  18. <view class="hotelList">
  19. <view class="hotleLeft">
  20. <image style="width: 214upx;height: 152upx;" :src=" pictureUrl + '/' + item.article_thumb"/>
  21. </view>
  22. <view class="hotelright">
  23. <view style="font-size: 28upx;color: #303133;">{{item.article_title}}</view>
  24. <view style="color: #999;">
  25. {{item.article_time}}
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <Gobacktop @getop="getop" v-if="isTop" />
  32. </view>
  33. </template>
  34. <script>
  35. import uniIcon from '@/component/uni-icon/uni-icon.vue'
  36. import Gobacktop from '@/component/Gobacktop.vue'
  37. export default {
  38. components: {
  39. uniIcon,
  40. Gobacktop
  41. },
  42. data() {
  43. return {
  44. pictureUrl: this.pictureUrl,
  45. page: 1,
  46. page_size: 10,
  47. ac_id:'',
  48. keyword:'',
  49. active: 0,
  50. scrollTop: 0,
  51. old: {
  52. scrollTop: 0
  53. },
  54. isTop: false,
  55. typelist:[],
  56. acrelist:[],
  57. ispull: true
  58. }
  59. },
  60. onLoad() {
  61. this.getype(); // 获取文章分类
  62. this.getlist(); // 获取文章列表
  63. },
  64. methods: {
  65. getop() {
  66. this.scrollTop = this.old.scrollTop
  67. this.$nextTick(function(){
  68. this.scrollTop=0;
  69. });
  70. this.isTop = false;
  71. },
  72. goIndex(items) {
  73. let article_id = items.article_id;
  74. let ac_id = items.ac_id;
  75. let name = '';
  76. this.typelist.forEach((item, index) => {
  77. if(item.ac_id == ac_id) {
  78. name = item.ac_name;
  79. }
  80. })
  81. uni.navigateTo({
  82. url: `/pages/myone/onedetail?id=${article_id}&name=${name}`
  83. });
  84. },
  85. getype() {
  86. this.request({
  87. url: '/v1/entry/news_cate',
  88. method:'POST',
  89. success: (res) => {
  90. let array = [{ac_name:'全部'}];
  91. this.typelist = array.concat(res.data.data);
  92. }
  93. })
  94. },
  95. getlist() {
  96. this.request({
  97. url: '/v1/entry/news',
  98. method:'POST',
  99. data: {
  100. page: this.page,
  101. page_size: this.page_size,
  102. ac_id: this.ac_id,
  103. keyword: this.keyword
  104. },
  105. success: (res) => {
  106. let { data } = res.data;
  107. if(data.total_page == data.current_page) {
  108. this.ispull = false;
  109. }
  110. this.acrelist = this.acrelist.concat(data.new_list);
  111. }
  112. })
  113. },
  114. confirm() {
  115. uni.navigateTo({
  116. url: './ariclle'
  117. })
  118. },
  119. onChange(event) {
  120. this.active = event.detail.name;
  121. if( event.detail.name == 0) {
  122. this.ac_id = '';
  123. }else {
  124. let items = this.typelist[this.active];
  125. this.ac_id = items.ac_id;
  126. }
  127. this.active = event.detail.name;
  128. this.ispull = true;
  129. this.page = 1;
  130. this.acrelist = [];
  131. this.getlist();
  132. },
  133. // 滚动到顶部
  134. upper(e) {
  135. console.log(e)
  136. console.log("顶部")
  137. },
  138. // 滚到底部
  139. lower(e) {
  140. this.page = this.page + 1;
  141. if(this.ispull) {
  142. this.getlist();
  143. }
  144. },
  145. // 滚动时触发
  146. scroll(e) {
  147. if(e.detail.scrollTop > 400) {
  148. this.isTop = true;
  149. }else{ //当距离小于500时显示回到顶部按钮
  150. this.isTop = false;
  151. }
  152. this.old.scrollTop = e.detail.scrollTop
  153. },
  154. }
  155. }
  156. </script>
  157. <style>
  158. .hotelList {
  159. display: flex;
  160. flex-direction: row;
  161. padding: 24upx 32upx;
  162. }
  163. .hotleLeft {
  164. width: 214upx;
  165. height: 152upx;
  166. }
  167. .hotelright {
  168. padding-left: 16upx;
  169. display: flex;
  170. flex-direction: column;
  171. width: 100%;
  172. justify-content: space-between;
  173. }
  174. .searchType .input-view {
  175. width: 85%;
  176. display: flex;
  177. background-color: #e7e7e7;
  178. height: 30px;
  179. border-radius: 15px;
  180. padding: 0 4%;
  181. flex-wrap: nowrap;
  182. margin: 7px 0;
  183. line-height: 30px;
  184. margin: 24upx auto;
  185. }
  186. .searchType .input-view .uni-icon {
  187. line-height: 30px !important;
  188. }
  189. .searchType .input-view .input {
  190. height: 30px;
  191. line-height: 30px;
  192. width: 94%;
  193. padding: 0 3%;
  194. }
  195. </style>