list.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="article-list-wrap">
  3. <view class="top-tabbar">
  4. <scroll-view scroll-x="true" scroll-with-animation="true">
  5. <view class="type-list d-s-c">
  6. <view :class="type_active == 0 ? 'tab-item active' : 'tab-item '" @click="tabTypeFunc(0)">
  7. 全部
  8. </view>
  9. <view :class="type_active == item.category_id ? 'tab-item active' : 'tab-item '" v-for="(item, index) in categorys" :key="index" @click="tabTypeFunc(item.category_id)">
  10. {{ item.name }}
  11. </view>
  12. </view>
  13. </scroll-view>
  14. </view>
  15. <template>
  16. <scroll-view scroll-y="true" class="scroll-Y" :style="'height:' + scrollviewHigh + 'px;'" lower-threshold="50" @scrolltolower="scrolltolowerFunc">
  17. <view class="article-list">
  18. <view class="item" v-for="(item, index) in listData" :key="index" @click="gotoDetail(item.article_id)">
  19. <view class="info">
  20. <view class="title">{{ item.article_title }}</view>
  21. <view class="summary">{{ item.dec }}</view>
  22. <view class="datatime d-s-c">
  23. <text>{{ item.create_time }}</text>
  24. <text class="icon iconfont icon-chakan ml30"></text>
  25. <text class="ml10">{{ item.actual_views }}</text>
  26. </view>
  27. </view>
  28. <view class="pic" v-if="item.image != null"><image :src="item.image.file_path" mode="aspectFill"></image></view>
  29. </view>
  30. </view>
  31. <!-- 没有记录 -->
  32. <view class="d-c-c p30" v-if="listData.length == 0 && !loading">
  33. <text class="iconfont icon-wushuju"></text>
  34. <text class="cont">亲,暂无相关记录哦</text>
  35. </view>
  36. <uni-load-more v-else :loadingType="loadingType"></uni-load-more>
  37. </scroll-view>
  38. </template>
  39. </view>
  40. </template>
  41. <script>
  42. import uniLoadMore from '@/components/uni-load-more.vue';
  43. export default {
  44. components: {
  45. uniLoadMore
  46. },
  47. data() {
  48. return {
  49. /*是否加载完成*/
  50. loading: true,
  51. /*手机高度*/
  52. phoneHeight: 0,
  53. /*可滚动视图区域高度*/
  54. scrollviewHigh: 0,
  55. /*数据列表*/
  56. listData: [],
  57. /*是否有更多*/
  58. no_more: null,
  59. /*一页多少条*/
  60. list_rows: 10,
  61. /*当前第几页*/
  62. page: 1,
  63. /*分类数据*/
  64. categorys: [],
  65. /*当前选中的类别*/
  66. type_active: 0
  67. };
  68. },
  69. computed: {
  70. /*加载中状态*/
  71. loadingType() {
  72. if (this.loading) {
  73. return 1;
  74. } else {
  75. if (this.listData.length != 0 && this.no_more) {
  76. return 2;
  77. } else {
  78. return 0;
  79. }
  80. }
  81. }
  82. },
  83. mounted() {
  84. this.init();
  85. /*获取分类*/
  86. this.getCategory();
  87. /*获取新闻列表*/
  88. this.getData();
  89. },
  90. methods: {
  91. /*初始化*/
  92. init() {
  93. let _this = this;
  94. uni.getSystemInfo({
  95. success(res) {
  96. _this.phoneHeight = res.windowHeight;
  97. // 计算组件的高度
  98. let view = uni.createSelectorQuery().select('.top-tabbar');
  99. view.boundingClientRect(data => {
  100. let h = _this.phoneHeight - data.height;
  101. _this.scrollviewHigh = h;
  102. }).exec();
  103. }
  104. });
  105. },
  106. /*获取文章分类*/
  107. getCategory() {
  108. let self = this;
  109. self._get('plus.article.article/category', {}, function(res) {
  110. self.categorys = res.data.category;
  111. });
  112. },
  113. /*tab切换*/
  114. tabTypeFunc(e) {
  115. if(e!=this.type_active){
  116. this.type_active=e;
  117. this.page=1;
  118. this.listData=[];
  119. this.getData();
  120. }
  121. },
  122. /*获取数据*/
  123. getData() {
  124. let self = this;
  125. let page = self.page;
  126. let list_rows = self.list_rows;
  127. self.loading = true;
  128. uni.showLoading({
  129. title: '加载中'
  130. });
  131. self._get(
  132. 'plus.article.article/index',
  133. {
  134. page: page || 1,
  135. list_rows: list_rows,
  136. category_id:self.type_active
  137. },
  138. function(res) {
  139. self.listData = self.listData.concat(res.data.list.data);
  140. self.last_page = res.data.list.last_page;
  141. if (res.data.list.last_page <= 1) {
  142. self.no_more = true;
  143. }
  144. self.loading = false;
  145. uni.hideLoading();
  146. }
  147. );
  148. },
  149. /*可滚动视图区域到底触发*/
  150. scrolltolowerFunc() {
  151. let self = this;
  152. self.bottomRefresh = true;
  153. self.page++;
  154. self.loading = true;
  155. if (self.page > self.last_page) {
  156. self.loading = false;
  157. self.no_more = true;
  158. return;
  159. }
  160. self.getData();
  161. },
  162. /*跳转文章详情*/
  163. gotoDetail(e) {
  164. this.gotoPage('/pages/article/detail/detail?article_id=' + e);
  165. }
  166. }
  167. };
  168. </script>
  169. <style>
  170. .article-list-wrap .type-list .tab-item {
  171. padding: 0 30rpx;
  172. font-size: 34rpx;
  173. height: 86rpx;
  174. line-height: 86rpx;
  175. white-space: nowrap;
  176. border-bottom: 4rpx solid #FFFFFF;
  177. }
  178. .article-list-wrap .type-list .tab-item.active{
  179. border-bottom: 4rpx solid #E2231A;
  180. margin-bottom: 0;
  181. }
  182. .article-list {
  183. background: #ffffff;
  184. }
  185. .article-list .item {
  186. padding: 30rpx;
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. border-bottom: 1px solid #e3e3e3;
  191. }
  192. .article-list .item .info {
  193. flex: 1;
  194. overflow: hidden;
  195. }
  196. .article-list .item .title {
  197. font-size: 36rpx;
  198. }
  199. .article-list .item .summary {
  200. margin-top: 20rpx;
  201. font-size: 28rpx;
  202. color: #999999;
  203. }
  204. .article-list .item .title,
  205. .article-list .item .summary {
  206. display: -webkit-box;
  207. overflow: hidden;
  208. -webkit-line-clamp: 2;
  209. -webkit-box-orient: vertical;
  210. }
  211. .article-list .item .pic {
  212. padding-left: 30rpx;
  213. }
  214. .article-list .item .pic,
  215. .article-list .item .pic image {
  216. width: 160rpx;
  217. height: 160rpx;
  218. }
  219. .article-list .item .datatime {
  220. margin-top: 20rpx;
  221. font-size: 24rpx;
  222. color: #999999;
  223. }
  224. </style>