search-result.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="search_result">
  3. <!-- 带搜索框的navbar -->
  4. <NavbarSearch ref="NavbarSearch" v-model="searchKeyWord" @sortType="sortTypeChange" @confirm="confirmSearch"></NavbarSearch>
  5. <!-- 商品列表 -->
  6. <view class="goodsList">
  7. <Goods class="list_item" v-for="(item, index) in goodsList" :key="index" :data="item"></Goods>
  8. </view>
  9. <!-- 无数据 -->
  10. <NoData
  11. height="50vh"
  12. v-if="finish&&goodsList.length == 0"
  13. ></NoData>
  14. <u-loadmore v-else :status="finish?'nomore':loading?'loading':'loadmore'" :load-text="loadText" margin-top="60" />
  15. </view>
  16. </template>
  17. <script>
  18. import NavbarSearch from '@/components/navbar/navbar-search.vue';
  19. import CardGoods from '@/pages/mall/components/card.vue';
  20. import Goods from '@/pages/mall/components/goods.vue';
  21. export default {
  22. components: { NavbarSearch, CardGoods,Goods},
  23. data() {
  24. return {
  25. searchKeyWord: '',//关键字
  26. cateInfo:{
  27. id:null,
  28. name:null,
  29. },
  30. sortType: {},//排序
  31. // 商品列表
  32. goodsList: [],
  33. status: 'loadmore',
  34. loadText: {
  35. loadmore: '轻轻上拉',
  36. loading: ' ',
  37. nomore: '没有更多了'
  38. },
  39. page:1,
  40. finish:false,
  41. loading:false,
  42. };
  43. },
  44. onLoad(opt) {
  45. if(opt.key){
  46. // 是搜索进来的
  47. this.searchKeyWord = opt.key;
  48. }
  49. if(opt.cateInfo){
  50. // 分类过来的
  51. this.cateInfo = JSON.parse(decodeURIComponent(opt.cateInfo));
  52. }
  53. uni.setNavigationBarTitle({
  54. title: this.cateInfo.id?'分类/'+this.cateInfo.name:'搜索列表'
  55. })
  56. this.getGoodsList();
  57. },
  58. onReachBottom(){
  59. this.getGoodsList();
  60. },
  61. methods: {
  62. sortTypeChange(e) {
  63. this.sortType=e;
  64. this.page = 1;
  65. this.finish = false;
  66. this.goodsList=[];
  67. this.getGoodsList();
  68. },
  69. confirmSearch(e){
  70. this.searchKeyWord = e;
  71. this.page = 1;
  72. this.finish = false;
  73. this.goodsList=[];
  74. this.getGoodsList();
  75. },
  76. // 查询商品
  77. getGoodsList() {
  78. if(this.finish)return false;
  79. if(this.loading) return false;
  80. this.loading = true;
  81. this.$u.api.getGoodsListAjax({
  82. title: this.searchKeyWord,
  83. page: this.page,
  84. cate_id:this.cateInfo.id,
  85. ...this.sortType
  86. }).then(({code,data})=>{
  87. this.loading = false;
  88. if(code==1){
  89. if(data.last_page<=data.current_page){
  90. this.finish = true;
  91. }
  92. if(data.current_page==1){
  93. this.goodsList = data.data;
  94. }else{
  95. this.goodsList=this.goodsList.concat(data.data);
  96. }
  97. }else{
  98. this.finish = true;
  99. }
  100. this.page = data.current_page+1;
  101. }).catch(()=>{
  102. this.loading = false;
  103. this.finish = true;
  104. })
  105. },
  106. }
  107. };
  108. </script>
  109. <style lang="scss" scoped>
  110. .search_result{
  111. background-color: #fff;
  112. min-height: 100vh;
  113. }
  114. // .goodsList {
  115. // padding: 30rpx 0;
  116. // }
  117. .list_item:last-child{
  118. background-color: red;
  119. }
  120. .goodsList .goodsItem:last-child{
  121. border-bottom: 0;
  122. }
  123. </style>