耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.1 KiB

  1. <template>
  2. <view class="search-info flex-1 flex flex-column">
  3. <view class="search-info-box position-fixed top-0 left-0 w-100 zIndex-1">
  4. <u-search disabled placeholder="请输入要搜索的商品" height="70" :show-action="false" @click="handleSearch" />
  5. </view>
  6. <view class="search-info-scroll flex-1">
  7. <view class="p-20" v-if="goodsList.length">
  8. <view class="m-b-20" v-for="item in goodsList" :key="item.id">
  9. <goods-item :goods="item" thereTo='home' />
  10. </view>
  11. </view>
  12. <view class="w-100 h-100" v-else-if="!loading && !goodsList.length">
  13. <u-empty icon-size="100" mode="search" text="没有搜索到此商品"></u-empty>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data: () => ({
  21. title: '',
  22. pageNo: 1,
  23. pageSize: 10,
  24. goodsList: [],
  25. loading: true,
  26. total: null,
  27. isMore: 1
  28. }),
  29. onLoad(optios) {
  30. uni.showLoading()
  31. this.title = optios.keyword
  32. this.getGoodsList()
  33. },
  34. onReachBottom() {
  35. if(this.isMore === 1) {
  36. this.isMore = 2
  37. this.pageNo+=1;
  38. this.getGoodsList();
  39. }
  40. },
  41. onPullDownRefresh() {
  42. this.pageNo= 1;
  43. uni.showLoading()
  44. this.isMore = 1
  45. this.goodsList = []
  46. this.getGoodsList();
  47. },
  48. methods: {
  49. getGoodsList () {
  50. this.$api('getGoodsList', {title: this.title, pageNo: this.pageNo, pageSize: this.pageSize })
  51. .then(res => {
  52. uni.hideLoading()
  53. this.loading = false
  54. let { code, result } = res
  55. if (res.code === 200) {
  56. this.isMore = 1
  57. if(this.pageNo * this.pageSize >= this.total) this.isMore = 0
  58. result.records.forEach(item => {
  59. const picArray= item.pic.split(',')
  60. item.pic= picArray[0]
  61. })
  62. this.goodsList = [ ...result.records, ...this.goodsList ]
  63. }
  64. })
  65. .catch(err => {
  66. uni.hideLoading()
  67. this.loading = false
  68. })
  69. },
  70. handleSearch () {
  71. this.$tools.redirectTo({
  72. url: '/pagesC/search/search'
  73. })
  74. },
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .search-info {
  80. background: #f6f6f6;
  81. &-box {
  82. padding: 20rpx;
  83. background-color: #fff;
  84. }
  85. &-scroll {
  86. padding-top: 110rpx;
  87. }
  88. }
  89. </style>