news_list.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="news-list">
  3. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
  4. :up="upOption">
  5. <view class="contain">
  6. <view class="banner">
  7. <ad-swipers v-if="type == 0" :pid="14" height="340rpx">
  8. </ad-swipers>
  9. <ad-swipers v-if="type == 1" :pid="15" height="340rpx">
  10. </ad-swipers>
  11. </view>
  12. <tabs :current="active" @change="changeActive" :bar-width="60">
  13. <tab name="全部"></tab>
  14. <tab v-for="(item, index) in categoryList" :key="index" :name="item.name"></tab>
  15. </tabs>
  16. <view class="main">
  17. <view class="article-list">
  18. <view class="article-item bg-white" v-for="(item, index) in newsList" :key="index" >
  19. <router-link :to="{path: '/pages/news_details/news_details', query: {id: item.id, type}}">
  20. <view class="flex col-top">
  21. <view class="info flex-1">
  22. <view class="title lg line-2 m-b-20">{{ item.title }}</view>
  23. <view class="lighter line-2">
  24. <view>{{ item.intro }}</view>
  25. </view>
  26. </view>
  27. <u-image width="240rpx" height="180rpx" class="img m-l-20" :src="item.image" />
  28. </view>
  29. <view class="flex row-between m-t-20">
  30. <view class="xs muted">发布时间: {{item.create_time}}</view>
  31. <view class="flex">
  32. <image class="icon-sm" src="/static/images/icon_see.png"></image>
  33. <view class="m-l-10 xs muted">{{ item.visit }}人浏览</view>
  34. </view>
  35. </view>
  36. </router-link>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </mescroll-body>
  42. </view>
  43. </template>
  44. <script>
  45. import {
  46. getCategoryList,
  47. getArticleList
  48. } from '@/api/store';
  49. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
  50. export default {
  51. mixins: [MescrollMixin],
  52. data() {
  53. return {
  54. active: 0,
  55. upOption: {
  56. auto: false,
  57. empty: {
  58. icon: '/static/images/news_null.png',
  59. tip: "暂无数据",
  60. }
  61. },
  62. categoryList: [],
  63. newsList: [],
  64. type: -1,
  65. };
  66. },
  67. onLoad(options) {
  68. this.type = this.$Route.query.type || 0;
  69. if (this.type) {
  70. uni.setNavigationBarTitle({
  71. title: '帮助中心'
  72. });
  73. } else {
  74. uni.setNavigationBarTitle({
  75. title: '商城资讯'
  76. });
  77. }
  78. },
  79. methods: {
  80. changeActive(e) {
  81. this.active = e;
  82. this.newsList = [] // 先置空列表,显示加载进度
  83. this.mescroll.resetUpScroll() // 再刷新列表数据
  84. },
  85. async downCallback() {
  86. await this.getCategoryListFun();
  87. this.mescroll.resetUpScroll();
  88. },
  89. upCallback(page) {
  90. const { type, active, categoryList } = this
  91. getArticleList({
  92. type: this.type,
  93. cid: this.active ? categoryList[active - 1].id : '',
  94. page_size:page.size,
  95. page_no:page.num
  96. }).then(({
  97. data
  98. }) => {
  99. if (page.num == 1) this.newsList = [];
  100. let curPageData = data.list;
  101. let curPageLen = curPageData.length;
  102. let hasNext = !!data.more;
  103. this.newsList = this.newsList.concat(curPageData);
  104. this.mescroll.endSuccess(curPageLen, hasNext);
  105. }).catch(() => {
  106. this.mescroll.endErr()
  107. })
  108. },
  109. async getCategoryListFun() {
  110. const {
  111. code,
  112. data
  113. } = await getCategoryList({
  114. type: this.type
  115. })
  116. if (code == 1) {
  117. this.categoryList = data
  118. }
  119. },
  120. }
  121. };
  122. </script>
  123. <style lang="scss">
  124. .news-list {
  125. .main {
  126. .article-list {
  127. padding-top: 20rpx;
  128. .article-item {
  129. padding: 20rpx;
  130. align-items: flex-start;
  131. &:not(:last-of-type){
  132. border-bottom: $-solid-border;
  133. }
  134. }
  135. }
  136. }
  137. }
  138. </style>