oneIndex.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 confirm-type="search" class="input" type="text" placeholder="搜索文章" @confirm="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="true">
  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="item.article_thumb"/>
  21. </view>
  22. <view class="hotelright">
  23. <view style="font-size: 28upx;color: #303133;">{{item.article_title}}</view>
  24. <view>
  25. {{item.article_time}}
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. </view>
  32. </template>
  33. <script>
  34. import uniIcon from '@/component/uni-icon/uni-icon.vue'
  35. export default {
  36. components: {
  37. uniIcon
  38. },
  39. data() {
  40. return {
  41. page: 1,
  42. page_size: 10,
  43. ac_id:'',
  44. keyword:'',
  45. active: 0,
  46. scrollTop: 0,
  47. old: {
  48. scrollTop: 0
  49. },
  50. typelist:[],
  51. acrelist:[],
  52. ispull: true
  53. }
  54. },
  55. onLoad() {
  56. this.getype(); // 获取文章分类
  57. this.getlist(); // 获取文章列表
  58. },
  59. methods: {
  60. goIndex(items) {
  61. let article_id = items.article_id;
  62. let ac_id = items.ac_id;
  63. let name = '';
  64. this.typelist.forEach((item, index) => {
  65. if(item.ac_id == ac_id) {
  66. name = item.ac_name;
  67. }
  68. })
  69. uni.navigateTo({
  70. url: `/pages/myone/onedetail?id=${article_id}&name=${name}`
  71. });
  72. },
  73. getype() {
  74. this.request({
  75. url: '/v1/entry/news_cate',
  76. method:'POST',
  77. success: (res) => {
  78. let array = [{ac_name:'全部'}];
  79. this.typelist = array.concat(res.data.data);
  80. }
  81. })
  82. },
  83. getlist() {
  84. this.request({
  85. url: '/v1/entry/news',
  86. method:'POST',
  87. data: {
  88. page: this.page,
  89. page_size: this.page_size,
  90. ac_id: this.ac_id,
  91. keyword: this.keyword
  92. },
  93. success: (res) => {
  94. let { data } = res.data;
  95. if(data.total_page == data.current_page) {
  96. console.log("ooooo")
  97. this.ispull = false;
  98. }
  99. this.acrelist = this.acrelist.concat(data.new_list);
  100. console.log(this.acrelist);
  101. console.log(data.total_page);
  102. }
  103. })
  104. },
  105. confirm() {
  106. },
  107. onChange(event) {
  108. this.active = event.detail.name;
  109. if( event.detail.name == 0) {
  110. this.ac_id = '';
  111. }else {
  112. let items = this.typelist[this.active];
  113. this.ac_id = items.ac_id;
  114. }
  115. this.active = event.detail.name;
  116. this.ispull = true;
  117. this.page = 1;
  118. this.acrelist = [];
  119. this.getlist();
  120. },
  121. // 滚动到顶部
  122. upper(e) {
  123. console.log(e)
  124. console.log("顶部")
  125. },
  126. // 滚到底部
  127. lower(e) {
  128. this.page = this.page + 1;
  129. if(this.ispull) {
  130. this.getlist();
  131. }
  132. },
  133. // 滚动时触发
  134. scroll(e) {
  135. this.old.scrollTop = e.detail.scrollTop
  136. },
  137. }
  138. }
  139. </script>
  140. <style>
  141. .hotelList {
  142. display: flex;
  143. flex-direction: row;
  144. padding: 24upx 32upx;
  145. }
  146. .hotleLeft {
  147. width: 214upx;
  148. height: 152upx;
  149. background-color: #007AFF;
  150. }
  151. .hotelright {
  152. padding-left: 16upx;
  153. display: flex;
  154. flex-direction: column;
  155. width: 100%;
  156. }
  157. .searchType .input-view {
  158. width: 85%;
  159. display: flex;
  160. background-color: #e7e7e7;
  161. height: 30px;
  162. border-radius: 15px;
  163. padding: 0 4%;
  164. flex-wrap: nowrap;
  165. margin: 7px 0;
  166. line-height: 30px;
  167. margin: 24upx auto;
  168. }
  169. .searchType .input-view .uni-icon {
  170. line-height: 30px !important;
  171. }
  172. .searchType .input-view .input {
  173. height: 30px;
  174. line-height: 30px;
  175. width: 94%;
  176. padding: 0 3%;
  177. }
  178. </style>