index.vue 3.6 KB

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