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