list.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. limit: 6,
  40. page: 1,
  41. isMore: true,
  42. lists: [],
  43. loadmore: {
  44. status: 'loadmore',
  45. loadingText: '努力加载中...',
  46. loadmoreText: '轻轻上拉',
  47. nomoreText: '没有更多了~'
  48. }
  49. }
  50. },
  51. computed: {},
  52. methods: {
  53. handleSearch() {
  54. this.getLists()
  55. },
  56. getLists() {
  57. this.loadmore.status = 'loading'
  58. this.$api.product.search({
  59. limit: this.limit,
  60. keywords: this.keywords,
  61. page: this.page
  62. }).then(res => {
  63. this.loading = false
  64. if (res.data.length) {
  65. this.loadmore.status = 'loadmore'
  66. this.lists = this.lists.concat(res.data)
  67. } else {
  68. this.loadmore.status = 'nomore'
  69. this.isMore = false
  70. }
  71. })
  72. }
  73. },
  74. onLoad(options) {
  75. this.keywords = options.keywords
  76. this.loading = true
  77. this.getLists()
  78. },
  79. onReachBottom(e) {
  80. console.log('-->data', e)
  81. if (!this.isMore) return
  82. this.page += 1
  83. this.getLists()
  84. }
  85. }
  86. </script>
  87. <style lang="scss" scoped>
  88. .product-page {
  89. padding: 0 30rpx 80rpx;
  90. .product-list{
  91. margin-top: 40rpx;
  92. .product-item{
  93. width: 335rpx;
  94. margin-bottom: 50rpx;
  95. &:nth-child(2n){
  96. margin-left: 20rpx;
  97. }
  98. .cover-img{
  99. width: 335rpx;
  100. height: 370rpx;
  101. image{
  102. width: 100%;
  103. height: 100%;
  104. }
  105. }
  106. .detail{
  107. padding: 20rpx 0;
  108. font-size: 24rpx;
  109. color: #333333;
  110. }
  111. }
  112. }
  113. }
  114. </style>