list.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="u-wrap">
  3. <view class="u-search-box">
  4. <view class="u-search-inner">
  5. <u-icon name="search" color="#909399" :size="28"></u-icon>
  6. <u-input class="u-search-text" type="text" height="50" @click="toSearch" />
  7. </view>
  8. </view>
  9. <view class="u-body-wrap">
  10. <u-row v-for="(item,index) in goodsList" :key="index">
  11. <u-col :span="4" class="gl-img">
  12. <u-image width="170rpx" height="170rpx" :src="item.img" @click="toDetail(item.id)"></u-image>
  13. </u-col>
  14. <u-col :span="8" @click="toDetail(item.id)">
  15. <view class="gl-name">{{item.name}}</view>
  16. <view class="gl-descript">{{item.descript}}</view>
  17. <view class="gl-price">¥{{formatPrice(item.price)}}</view>
  18. </u-col>
  19. </u-row>
  20. <u-loadmore :status="status" :load-text="loadText" style="margin-top:30rpx;" />
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. data() {
  27. return {
  28. idCategory: undefined,
  29. goodsList: [],
  30. listQuery: {
  31. page: 1,
  32. limit: 20,
  33. idCategory: undefined
  34. },
  35. total: 0,
  36. status: 'loadmore',
  37. loadText: {
  38. loadmore: '轻轻上拉',
  39. loading: '努力加载中',
  40. nomore: '没有更多了'
  41. }
  42. }
  43. },
  44. onLoad(option) {
  45. this.idCategory = option.idCategory
  46. this.init()
  47. },
  48. onReachBottom() {
  49. this.listQuery.page = this.listQuery.page + 1
  50. this.getGoods(this.idCategory)
  51. },
  52. methods: {
  53. init() {
  54. this.getGoods(this.idCategory)
  55. },
  56. toSearch() {
  57. this.$u.route({
  58. url: '/pages/shop/search'
  59. })
  60. },
  61. getGoods(idCategory) {
  62. this.status = 'loading'
  63. this.listQuery['idCategory'] = idCategory
  64. const page = this.listQuery.page
  65. const limit = this.listQuery.limit
  66. const baseApi = this.baseApi;
  67. this.$u.get('goods/queryGoods?page=' + page + '&limit=' + limit + '&idCategory=' + idCategory).then(res => {
  68. let list = res.records
  69. this.total = res.total
  70. if (list.length < limit) {
  71. this.status = 'nomore'
  72. } else {
  73. this.status = 'loadmore'
  74. }
  75. for (var index in list) {
  76. const item = list[index]
  77. item.img = baseApi + '/file/getImgStream?idFile=' + item.pic
  78. this.goodsList.push(item)
  79. }
  80. }).catch((err) => {
  81. Toast(err)
  82. })
  83. },
  84. formatPrice(price) {
  85. return (price / 100).toFixed(2)
  86. },
  87. toDetail(id) {
  88. this.$u.route({
  89. url: '/pages/goods/goods',
  90. params: {
  91. id: id
  92. }
  93. })
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .u-wrap {
  100. height: calc(100vh);
  101. /* #ifdef H5 */
  102. height: calc(100vh - var(--window-top));
  103. /* #endif */
  104. display: flex;
  105. flex-direction: column;
  106. }
  107. .u-search-box {
  108. padding: 10rpx 30rpx;
  109. }
  110. .u-search-inner {
  111. background-color: rgb(234, 234, 234);
  112. border-radius: 100rpx;
  113. display: flex;
  114. align-items: center;
  115. padding: 10rpx 16rpx;
  116. }
  117. .u-search-text {
  118. font-size: 24rpx;
  119. color: $u-tips-color;
  120. margin-left: 10rpx;
  121. }
  122. .gl-title {
  123. padding: 20rpx;
  124. }
  125. .gl-img {
  126. padding: 30rpx;
  127. }
  128. .gl-name {
  129. font-size: 26rpx;
  130. }
  131. .gl-descript {
  132. font-size: 20rpx;
  133. }
  134. .gl-price {
  135. font-size: 24rpx;
  136. color: #FA3534;
  137. }
  138. </style>