search.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="搜索"></fa-navbar>
  5. <view class="u-p-20 u-bg-white"><u-search placeholder="请输入关键词搜索" v-model="keyword" @custom="search" :focus="true"></u-search></view>
  6. <!-- 分类 -->
  7. <view class="u-bg-white u-border-bottom">
  8. <fa-orderby :tabList="tabList" showField="title" :activeColor="theme.bgColor" @change="orderChange"></fa-orderby>
  9. </view>
  10. <fa-article-item :archivesList="pageList"></fa-article-item>
  11. <!-- 空数据 -->
  12. <view class="u-p-60" v-if="!pageList.length">
  13. <u-empty text="没有更多了"></u-empty>
  14. </view>
  15. <!-- 加载更多 -->
  16. <view class="u-p-30" v-if="pageList.length"><u-loadmore bg-color="#f4f6f8" :status="status" /></view>
  17. <!-- 回到顶部 -->
  18. <u-back-top :scroll-top="scrollTop" :icon-style="{ color: theme.bgColor }" :custom-style="{ backgroundColor: lightColor }"></u-back-top>
  19. <!-- 底部导航 -->
  20. <fa-tabbar></fa-tabbar>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. onLoad(e) {
  26. let query = this.$Route.query || e || {};
  27. this.keyword = query.keyword || '';
  28. this.goSearch();
  29. },
  30. data() {
  31. return {
  32. tabList: [],
  33. tabwidth: 60,
  34. current: 0,
  35. keyword: '',
  36. pageList:[],
  37. has_more: false,
  38. scrollTop: 0,
  39. status: 'nomore',
  40. page: 1,
  41. orderby:'default',
  42. orderway:'asc',
  43. is_order:false
  44. };
  45. },
  46. methods: {
  47. search(){
  48. this.page = 1;
  49. this.is_order = true;
  50. this.goSearch();
  51. },
  52. goSearch() {
  53. this.$api.search({page:this.page,orderby:this.orderby,orderway:this.orderway,q:this.keyword}).then(res => {
  54. this.status = 'nomore';
  55. if (res.code) {
  56. //有数据过渡切换
  57. if(this.is_order){
  58. this.pageList = [];
  59. this.is_order = false;
  60. }
  61. this.tabList = res.data.orderList;
  62. this.pageList = [...this.pageList,...res.data.pageList.data];
  63. this.has_more = res.data.pageList.last_page>res.data.pageList.current_page;
  64. }
  65. });
  66. },
  67. orderChange(e){
  68. this.page = 1;
  69. this.is_order = true;
  70. this.orderby = e.orderby;
  71. this.orderway = e.orderway;
  72. this.goSearch();
  73. }
  74. },
  75. onPageScroll(e) {
  76. this.scrollTop = e.scrollTop;
  77. },
  78. onReachBottom() {
  79. if (this.has_more) {
  80. this.status = 'loading';
  81. this.page = ++this.page;
  82. this.goSearch();
  83. }
  84. }
  85. };
  86. </script>
  87. <style lang="scss">
  88. page {
  89. background-color: #f4f6f8;
  90. }
  91. </style>