index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view>
  3. <view class="search">
  4. <u-search placeholder="搜索标题" v-model="param.title" bgColor="white" :showAction="false" @search="(current = 0), (param.type = ''), refresh()" @clear="(current = 0), (param.type = ''), (param.title = ''), refresh()"></u-search>
  5. </view>
  6. <view class="tab">
  7. <u-tabs :list="tab" :current="current" keyName="dictLabel" @click="click"></u-tabs>
  8. </view>
  9. <view class="list">
  10. <view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/knowledge/detail?id=' + item.id)">
  11. <view class="title omit">
  12. <text class="icon" v-if="item.top === 1">&#xe61f;</text>
  13. <text>{{ item.title }}</text>
  14. </view>
  15. <view class="desc">
  16. <text>{{ item.type }}</text>
  17. <text>发布于 {{ item.createTime }}</text>
  18. </view>
  19. </view>
  20. <view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
  21. <u-empty v-if="!loadMore && list.length == 0"></u-empty>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. tab: [],
  30. current: 0,
  31. list: [],
  32. param: { pageNum: 1, pageSize: 10 },
  33. loadMore: true
  34. };
  35. },
  36. onLoad(e) {
  37. this.getType();
  38. this.getData();
  39. },
  40. methods: {
  41. click(e) {
  42. this.current = e.index;
  43. this.param.type = e.dictValue;
  44. this.refresh();
  45. },
  46. getData() {
  47. this.http.request({
  48. url: '/app/knowledge/list',
  49. data: this.param,
  50. loading: 'false',
  51. success: (res) => {
  52. this.loadMore = res.data.pages > this.param.pageNum ? true : false;
  53. res.data.rows.forEach((item) => {
  54. item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
  55. this.list.push(item);
  56. });
  57. }
  58. });
  59. },
  60. getType() {
  61. this.http.request({
  62. url: '/app/common/type/knowledge_type',
  63. loading: 'false',
  64. success: (res) => {
  65. this.tab = res.data.data;
  66. this.tab.unshift({ dictLabel: '全部类型', dictValue: '' });
  67. }
  68. });
  69. },
  70. go(url) {
  71. uni.navigateTo({ url: url });
  72. },
  73. //刷新数据
  74. refresh() {
  75. this.loadMore = true;
  76. this.param.pageNum = 1;
  77. this.list = [];
  78. this.getData();
  79. }
  80. },
  81. //下拉刷新
  82. onPullDownRefresh() {
  83. setTimeout(() => {
  84. this.refresh();
  85. uni.stopPullDownRefresh();
  86. }, 1000);
  87. },
  88. //上拉加载
  89. onReachBottom() {
  90. if (this.loadMore) {
  91. this.param.pageNum++;
  92. this.getData();
  93. }
  94. }
  95. };
  96. </script>
  97. <style lang="scss">
  98. .list {
  99. padding: 10px 12px;
  100. background-color: white;
  101. margin: 10px;
  102. border-radius: 10px;
  103. .item {
  104. border-radius: 5px;
  105. padding: 13px 12px 13px 12px;
  106. margin-bottom: 10px;
  107. overflow: hidden;
  108. border-bottom: 1px solid $line;
  109. &:last-child{
  110. border: 0px;
  111. }
  112. .title {
  113. font-size: 15px;
  114. font-weight: bold;
  115. .icon {
  116. color: orangered;
  117. padding-right: 3px;
  118. }
  119. }
  120. .desc {
  121. font-size: 14px;
  122. padding-top: 10px;
  123. color: $font-c;
  124. text {
  125. padding-right: 30px;
  126. }
  127. }
  128. }
  129. }
  130. </style>