oneIndex.vue 4.9 KB

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