storelist.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="content">
  3. <view class="goods-list">
  4. <view v-for="(item, index) in goodsList" :key="index" class="goods-item" @click="navToDetailPage(item)">
  5. <view class="image-wrapper"><image :src="item.image" mode="aspectFill"></image></view>
  6. <text class="title clamp">{{ item.store_name }}</text>
  7. <view class="price-box">
  8. <text class="price">{{ item.price }}</text>
  9. <text>原价 {{ item.ot_price }}</text>
  10. </view>
  11. </view>
  12. </view>
  13. <uni-load-more :status="loadingType"></uni-load-more>
  14. </view>
  15. </template>
  16. <script>
  17. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  18. import { store_shoping } from '@/api/index.js';
  19. export default {
  20. components: {
  21. uniLoadMore
  22. },
  23. data() {
  24. return {
  25. loadingType: 'more', //加载更多状态
  26. limit: 6, //每次加载数据条数
  27. page: 1, //当前页数
  28. goodsList: [] //商品列表
  29. };
  30. },
  31. onLoad(options) {
  32. this.loadData();
  33. },
  34. //下拉刷新
  35. onPullDownRefresh() {
  36. this.loadData('refresh');
  37. },
  38. //监听页面是否滚动到底部加载更多
  39. onReachBottom() {
  40. this.loadData();
  41. },
  42. methods: {
  43. //加载商品 ,带下拉刷新和上滑加载
  44. async loadData(type = 'add', loading) {
  45. let obj = this;
  46. let data = {
  47. page: obj.page,
  48. limit: obj.limit,
  49. };
  50. //没有更多直接返回
  51. if (type === 'add') {
  52. if (obj.loadingType === 'nomore') {
  53. return;
  54. }
  55. obj.loadingType = 'loading';
  56. } else {
  57. obj.loadingType = 'more';
  58. }
  59. if (type === 'refresh') {
  60. // 清空数组
  61. obj.goodsList = [];
  62. obj.page = 1;
  63. }
  64. store_shoping(data).then(function(e) {
  65. console.log(e.data);
  66. const arr = e.data.list;
  67. obj.goodsList = obj.goodsList.concat(arr);
  68. //判断是否还有下一页,有是more 没有是nomore
  69. if (obj.limit == arr.length) {
  70. obj.page++;
  71. obj.loadingType = 'more';
  72. } else {
  73. obj.loadingType = 'nomore';
  74. }
  75. if (type === 'refresh') {
  76. if (loading == 1) {
  77. uni.hideLoading();
  78. } else {
  79. uni.stopPullDownRefresh();
  80. }
  81. }
  82. });
  83. },
  84. //详情
  85. navToDetailPage(item) {
  86. let id = item.id;
  87. if (this.sid == 52) {
  88. uni.navigateTo({
  89. url: `/pages/product/product?id=${id}&isVip=1`
  90. });
  91. } else {
  92. uni.navigateTo({
  93. url: `/pages/product/product?id=${id}`
  94. });
  95. }
  96. }
  97. }
  98. };
  99. </script>
  100. <style lang="scss">
  101. page,
  102. .content {
  103. background: $page-color-base;
  104. }
  105. /* 商品列表 */
  106. .goods-list {
  107. display: flex;
  108. flex-wrap: wrap;
  109. padding: 0 30rpx;
  110. padding-top: 30rpx;
  111. .goods-item {
  112. display: flex;
  113. flex-direction: column;
  114. width: 48%;
  115. padding-bottom: 20rpx;
  116. &:nth-child(2n + 1) {
  117. margin-right: 4%;
  118. }
  119. background: #fff;
  120. margin-bottom: 20rpx;
  121. border-radius: 10rpx;
  122. overflow: hiddens;
  123. }
  124. .image-wrapper {
  125. width: 100%;
  126. height: 330rpx;
  127. border-radius: 3px;
  128. overflow: hidden;
  129. position: relative;
  130. image {
  131. width: 100%;
  132. height: 100%;
  133. opacity: 1;
  134. }
  135. }
  136. .title {
  137. font-size: $font-lg;
  138. color: $font-color-dark;
  139. line-height: 80rpx;
  140. padding: 0 10rpx;
  141. }
  142. .price-box {
  143. display: flex;
  144. align-items: center;
  145. justify-content: space-between;
  146. font-size: 24rpx;
  147. color: $font-color-light;
  148. padding: 0 10rpx;
  149. }
  150. .price {
  151. font-size: $font-lg;
  152. color: #ff4c4c;
  153. line-height: 1;
  154. &:before {
  155. content: '¥';
  156. font-size: 26rpx;
  157. }
  158. }
  159. }
  160. </style>