index.vue 4.5 KB

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