index.vue 3.0 KB

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