news.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view>
  3. <u-navbar :back-text="title" back-icon-size="28" back-icon-color="#ffffff"
  4. :background="{backgroundColor: '#2795FD',}" :back-text-style="{color: '#ffffff'}"></u-navbar>
  5. <view class="main">
  6. <view class="news-item" v-for="(item,i) in list" :key="i"
  7. @click="gotoUrl('pages/packages/news/articleDetail?id='+item.id)">
  8. <view class="content">
  9. <view class="title">
  10. {{item.title}}
  11. </view>
  12. <view class="tags">
  13. <view class="classify">
  14. {{item.categoryN}}
  15. </view>
  16. <view class="date">
  17. {{item.createTime.substring(0,10)}}
  18. </view>
  19. </view>
  20. </view>
  21. <view class="picture">
  22. <img :src="item.thumbnailImage" alt="">
  23. </view>
  24. </view>
  25. </view>
  26. <u-divider v-if="list.length==recordsTotal"
  27. :isnone="list.length==0" nonetext="没有找到相关内容"
  28. bg-color="#fff" margin-top="20" border-color="#CFD2D5">已经到底了</u-divider>
  29. </view>
  30. </template>
  31. <script>
  32. import * as API from '@/apis/pagejs/packages.js'
  33. export default {
  34. data() {
  35. return {
  36. title:"",
  37. type:"",
  38. list:[],
  39. recordsTotal: 0,
  40. listFrom:{
  41. pageIndex: 1,
  42. pageSize: 20,
  43. }
  44. }
  45. },
  46. onLoad(op) {
  47. this.title=op.title
  48. this.type=op.t
  49. this.getList();
  50. },
  51. onReachBottom() {
  52. if (this.list.length < this.recordsTotal) {
  53. this.myLoadmore();
  54. }
  55. },
  56. methods: {
  57. myLoadmore(){
  58. this.listFrom.pageIndex += 1;
  59. this.getList();
  60. },
  61. getList(){
  62. uni.showLoading({
  63. title: "加载中",
  64. mask: true,
  65. })
  66. API.newsList({
  67. category:this.type,
  68. pageSize:this.listFrom.pageSize,
  69. pageIndex:this.listFrom.pageIndex,
  70. }).then((res) => {
  71. uni.hideLoading();
  72. if (this.listFrom.pageIndex == 1) {
  73. this.list = res.data.data;
  74. } else {
  75. this.list = [
  76. ...this.list,
  77. ...res.data.data
  78. ];
  79. }
  80. this.recordsTotal=res.data.recordsTotal;
  81. }).catch(error => {
  82. uni.showToast({icon: 'none',
  83. title: error,
  84. icon: "none"
  85. })
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. page{
  93. padding-bottom: 120px;
  94. }
  95. .main{
  96. padding: 24rpx 32rpx;
  97. .news-item{
  98. display: flex;
  99. height: auto;
  100. margin-bottom: 40rpx;
  101. .content{
  102. width: 526rpx;
  103. margin-right: 24rpx;
  104. display: flex;
  105. flex-direction: column;
  106. justify-content: space-between;
  107. .title{
  108. color: rgba(51, 51, 51, 1);
  109. font-size: 16px;
  110. text-align: justify;
  111. line-height: 48rpx;
  112. }
  113. .tags{
  114. display: flex;
  115. justify-content: space-between;
  116. .classify{
  117. color: rgba(39, 149, 253, 1);
  118. }
  119. .date{
  120. color: rgba(153, 153, 153, 1);
  121. font-size: 24rpx;
  122. }
  123. }
  124. }
  125. .picture{
  126. width: 224rpx;
  127. height: 172rpx;
  128. border-radius: 4px;
  129. img{
  130. width: 224rpx;
  131. height: 172rpx;
  132. }
  133. }
  134. }
  135. }
  136. </style>