oneIndex.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 article_thumb =items.article_thumb;
  75. let ac_id = items.ac_id;
  76. let name = '';
  77. this.typelist.forEach((item, index) => {
  78. if(item.ac_id == ac_id) {
  79. name = item.ac_name;
  80. }
  81. })
  82. // :src=" pictureUrl + '/' + item.article_thumb"
  83. uni.navigateTo({
  84. url: `/pages/myone/onedetail?id=${article_id}&name=${name}&article_thumb=${article_thumb}`
  85. });
  86. },
  87. getype() {
  88. this.request({
  89. url: '/v1/entry/news_cate',
  90. method:'POST',
  91. success: (res) => {
  92. let array = [{ac_name:'全部'}];
  93. this.typelist = array.concat(res.data.data);
  94. }
  95. })
  96. },
  97. getlist() {
  98. this.request({
  99. url: '/v1/entry/news',
  100. method:'POST',
  101. data: {
  102. page: this.page,
  103. page_size: this.page_size,
  104. ac_id: this.ac_id,
  105. keyword: this.keyword
  106. },
  107. success: (res) => {
  108. let { data } = res.data;
  109. if(data.total_page == data.current_page) {
  110. this.ispull = false;
  111. }
  112. this.acrelist = this.acrelist.concat(data.new_list);
  113. }
  114. })
  115. },
  116. confirm() {
  117. uni.navigateTo({
  118. url: './ariclle'
  119. })
  120. },
  121. onChange(event) {
  122. this.active = event.detail.name;
  123. if( event.detail.name == 0) {
  124. this.ac_id = '';
  125. }else {
  126. let items = this.typelist[this.active];
  127. this.ac_id = items.ac_id;
  128. }
  129. this.active = event.detail.name;
  130. this.ispull = true;
  131. this.page = 1;
  132. this.acrelist = [];
  133. this.getlist();
  134. },
  135. // 滚动到顶部
  136. upper(e) {
  137. console.log(e)
  138. console.log("顶部")
  139. },
  140. // 滚到底部
  141. lower(e) {
  142. this.page = this.page + 1;
  143. if(this.ispull) {
  144. this.getlist();
  145. }
  146. },
  147. // 滚动时触发
  148. scroll(e) {
  149. if(e.detail.scrollTop > 400) {
  150. this.isTop = true;
  151. }else{ //当距离小于500时显示回到顶部按钮
  152. this.isTop = false;
  153. }
  154. this.old.scrollTop = e.detail.scrollTop
  155. },
  156. }
  157. }
  158. </script>
  159. <style>
  160. .hotelList {
  161. display: flex;
  162. flex-direction: row;
  163. padding: 24upx 32upx;
  164. }
  165. .hotleLeft {
  166. width: 214upx;
  167. height: 152upx;
  168. }
  169. .hotelright {
  170. padding-left: 16upx;
  171. display: flex;
  172. flex-direction: column;
  173. width: 100%;
  174. justify-content: space-between;
  175. }
  176. .searchType .input-view {
  177. width: 85%;
  178. display: flex;
  179. background-color: #e7e7e7;
  180. height: 30px;
  181. border-radius: 15px;
  182. padding: 0 4%;
  183. flex-wrap: nowrap;
  184. margin: 7px 0;
  185. line-height: 30px;
  186. margin: 24upx auto;
  187. }
  188. .searchType .input-view .uni-icon {
  189. line-height: 30px !important;
  190. }
  191. .searchType .input-view .input {
  192. height: 30px;
  193. line-height: 30px;
  194. width: 94%;
  195. padding: 0 3%;
  196. }
  197. </style>