list.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <page-loading :loading="loading">
  3. <view class="product-page">
  4. <view
  5. class="product-list dir-left-wrap"
  6. >
  7. <view
  8. v-for="(item,index) in lists"
  9. :key="index"
  10. class="product-item dir-top-wrap"
  11. @click="$u.route({url: `/pages/product/detail?id=${item.id}`})"
  12. >
  13. <view class="cover-img">
  14. <image :src="item.cover_img" mode="aspectFill" />
  15. </view>
  16. <view class="detail main-center cross-center">
  17. {{ item.name }}
  18. </view>
  19. </view>
  20. </view>
  21. <u-loadmore
  22. :status="loadmore.status"
  23. :loading-text="loadmore.loadingText"
  24. :loadmore-text="loadmore.loadmoreText"
  25. :nomore-text="loadmore.nomoreText"
  26. />
  27. </view>
  28. </page-loading>
  29. </template>
  30. <script>
  31. import PageLoading from '../../components/PageLoading'
  32. export default {
  33. name: 'Product',
  34. components: { PageLoading },
  35. data() {
  36. return {
  37. loading: false,
  38. keywords: '',
  39. cate_id: 0,
  40. ids: '',
  41. limit: 6,
  42. page: 1,
  43. isMore: true,
  44. lists: [],
  45. loadmore: {
  46. status: 'loadmore',
  47. loadingText: '努力加载中...',
  48. loadmoreText: '轻轻上拉',
  49. nomoreText: '没有更多了~'
  50. }
  51. }
  52. },
  53. computed: {},
  54. methods: {
  55. handleSearch() {
  56. this.getLists()
  57. },
  58. getLists() {
  59. this.loadmore.status = 'loading'
  60. this.$api.product.search({
  61. limit: this.limit,
  62. keywords: this.keywords,
  63. cate_id: this.cate_id,
  64. ids: this.ids,
  65. page: this.page
  66. }).then(res => {
  67. this.loading = false
  68. if (res.data.length) {
  69. this.loadmore.status = 'loadmore'
  70. this.lists = this.lists.concat(res.data)
  71. } else {
  72. this.loadmore.status = 'nomore'
  73. this.isMore = false
  74. }
  75. })
  76. }
  77. },
  78. onLoad(options) {
  79. this.keywords = options.keywords
  80. this.cate_id = options?.cate_id
  81. this.ids = options?.ids
  82. this.loading = true
  83. this.getLists()
  84. },
  85. onReachBottom(e) {
  86. console.log('-->data', e)
  87. if (!this.isMore) return
  88. this.page += 1
  89. this.getLists()
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. .product-page {
  95. padding: 0 30rpx 80rpx;
  96. .product-list{
  97. margin-top: 40rpx;
  98. .product-item{
  99. width: 335rpx;
  100. margin-bottom: 50rpx;
  101. &:nth-child(2n){
  102. margin-left: 20rpx;
  103. }
  104. .cover-img{
  105. width: 335rpx;
  106. height: 370rpx;
  107. image{
  108. width: 100%;
  109. height: 100%;
  110. }
  111. }
  112. .detail{
  113. padding: 20rpx 0;
  114. font-size: 24rpx;
  115. color: #333333;
  116. }
  117. }
  118. }
  119. }
  120. </style>