index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="container">
  3. <view class="top">
  4. <view class="search">
  5. <uni-easyinput class="uni-input" prefixIcon="search" v-model="searchVal" placeholder="请输入您要查询的名称"></uni-easyinput>
  6. <button class="searchBtn" type="default" size="mini" @click="searchBtn">搜索</button>
  7. </view>
  8. </view>
  9. <uni-list border class="list">
  10. <uni-list-item
  11. v-for="(item, index) in dataList"
  12. :key="index"
  13. :ellipsis="2"
  14. :title="item.title"
  15. :note="item.createTime"
  16. showArrow
  17. clickable
  18. :thumb="item.blogPic"
  19. thumb-size="lg"
  20. @click="listItemBtn(item)"
  21. />
  22. <!-- <uni-list-item showArrow :thumb="item.blogPic" thumb-size="lg" :ellipsis="2" :title="item.title" link clickable @click="listItemBtn(item)" ></uni-list-item> -->
  23. </uni-list>
  24. <uni-load-more :status="more" />
  25. </view>
  26. </template>
  27. <script>
  28. import request from '../../api/cms.js';
  29. import { BASE_URL } from '../../env.js';
  30. export default {
  31. data() {
  32. return {
  33. searchVal: '',
  34. page: 0,
  35. size: 12,
  36. // more = 加载前, loading = 加载中, noMore = 没有更多
  37. more: 'more',
  38. dataList: []
  39. }
  40. },
  41. onShow: function() {
  42. // this.init();
  43. },
  44. async mounted() {
  45. this.getPolicyList({ typeName: 'fczs' });
  46. },
  47. methods: {
  48. // 列表点击函数
  49. listItemBtn(e) {
  50. uni.navigateTo({ url: `/pages/details/cmsinfo?id=${e.id}` })
  51. },
  52. // 搜索函数
  53. async getPolicyList(e) {
  54. this.page += 1;
  55. this.more = 'loading';
  56. if(this.searchVal !== '') e.title = this.searchVal;
  57. const res = await request.getArticleList({ pageNum: this.page, pageSize: this.size, ...e });
  58. this.dataList.push(...res.rows.map(e => {
  59. return { ...e, blogPic: BASE_URL.fileUrl + e.blogPic }
  60. }))
  61. // 根据总数 算页数 如果当前页 = 总页数就是没有数据 否则就是上拉加载
  62. this.more = this.page >= Math.ceil(res.total / this.size) ? 'noMore' : 'more';
  63. },
  64. // 搜索函数
  65. searchBtn() {
  66. if(!this.searchVal || this.searchVal == '') return;
  67. this.reset();
  68. this.getPolicyList({ title: this.searchVal, typeName: 'fczs' });
  69. },
  70. reset() {
  71. this.page = 0;
  72. this.dataList = [];
  73. }
  74. },
  75. // 页面生命周期中onReachBottom(页面滚动到底部的事件)
  76. onReachBottom() {
  77. if(this.more != 'noMore') {
  78. this.more = 'more';
  79. this.getPolicyList();
  80. }
  81. }
  82. }
  83. </script>
  84. <style>
  85. .container {
  86. width: 100%;
  87. background-color: #fff;
  88. }
  89. .top {
  90. width: 100%;
  91. z-index: 999;
  92. background-color: #fff;
  93. overflow: hidden;
  94. }
  95. .tabsBox {
  96. width: 100%;
  97. border-bottom: 1px solid #d3d3d3;
  98. display: flex;
  99. }
  100. .tab {
  101. width: 25%;
  102. }
  103. .text {
  104. display: block;
  105. width: 80%;
  106. margin: 0 auto;
  107. text-align: center;
  108. }
  109. .current {
  110. color: #ff9302;
  111. border-bottom: 1px solid #ff9302;
  112. }
  113. .search {
  114. width: 90%;
  115. height: 2em;
  116. border: 1px solid #f3f3f3;
  117. background-color: #fff !important;
  118. border-radius: 12px;
  119. display: flex;
  120. margin: 20px auto;
  121. }
  122. .uni-easyinput {
  123. width: 70%;
  124. margin-left: 5%;
  125. height: 100%;
  126. font-size: 14px;
  127. }
  128. .uni-easyinput .uni-easyinput__content {
  129. border: none !important;
  130. height: 100%;
  131. line-height: 2em;
  132. }
  133. .searchBtn {
  134. width: 20%;
  135. background-color: #ff9302 !important;
  136. border: none;
  137. color: #fff !important;
  138. height: 2em;
  139. margin-top: 0.2em;
  140. margin-left: 4%;
  141. border-radius: 12px;
  142. }
  143. .list {
  144. display: block;
  145. }
  146. </style>