supermarket.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="content">
  3. <empty v-if="list.length === 0"></empty>
  4. <view class="guess" v-if="list.length !=0">
  5. <view v-for="(item, index) in list" :key="index" class="guess-item" @click="navToDetailPage(item)">
  6. <image :src="item.image"></image>
  7. <view class="guess-box">
  8. <view class="title clamp">{{ item.store_name }}</view>
  9. <view class="guessbtm-box flex">
  10. <view class="price">¥{{ item.price }} <text class="yuan">¥{{ item.ot_price }}</text> </view>
  11. <image @click.stop="toggleSpec(item.id)" class="btn" src="../../static/icon/cart.png" mode="">
  12. </image>
  13. </view>
  14. </view>
  15. </view>
  16. <uni-load-more :status="loadingType"></uni-load-more>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  22. import empty from '@/components/empty';
  23. import {
  24. getProducts,
  25. cartAdd
  26. } from '@/api/product.js';
  27. export default {
  28. data() {
  29. return {
  30. page: 1,
  31. limit: 20,
  32. loadingType: 'more',
  33. list: [],
  34. };
  35. },
  36. components: {
  37. empty,
  38. uniLoadMore
  39. },
  40. onLoad() {
  41. this.loadData();
  42. },
  43. onShow() {},
  44. onReachBottom() {
  45. this.loadData();
  46. },
  47. onReady() {},
  48. methods: {
  49. loadData() {
  50. if (this.loadingType == 'loading' || this.loadingType == 'nomore') {
  51. return
  52. }
  53. this.loadingType = 'loading'
  54. getProducts({
  55. page: this.page,
  56. limit: this.limit,
  57. cid: 1
  58. }).then(({
  59. data
  60. }) => {
  61. this.list = this.list.concat(data)
  62. this.page++
  63. if (data.length != this.limit) {
  64. this.loadingType = 'nomore'
  65. } else {
  66. this.loadingType = 'more'
  67. }
  68. })
  69. },
  70. toggleSpec(str) {
  71. cartAdd({
  72. cartNum: 1, //商品数量
  73. uniqueId: '', //商品标签
  74. new: 0, //商品是否新增加到购物车1为不加入0为加入
  75. mer_id: 0,
  76. is_consumer: 0,
  77. productId: str
  78. }).then(e => {
  79. uni.showToast({
  80. title: '成功加入购物车',
  81. type: 'top',
  82. duration: 2000
  83. });
  84. })
  85. },
  86. }
  87. };
  88. </script>
  89. <style lang="scss">
  90. page,
  91. .content {
  92. min-height: 100%;
  93. height: auto;
  94. }
  95. .guess {
  96. display: flex;
  97. justify-content: space-between;
  98. flex-wrap: wrap;
  99. padding: 20rpx;
  100. }
  101. .guess-item {
  102. margin-top: 20rpx;
  103. width: 345rpx;
  104. background: #FFFFFF;
  105. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  106. border-radius: 10rpx;
  107. image {
  108. width: 345rpx;
  109. height: 345rpx;
  110. border-radius: 10rpx;
  111. }
  112. .guess-box {
  113. padding: 28rpx 20rpx;
  114. width: 345rpx;
  115. .title {
  116. font-size: 30rpx;
  117. font-family: PingFang SC;
  118. font-weight: bold;
  119. color: #333333;
  120. }
  121. .price {
  122. font-size: 36rpx;
  123. font-family: PingFang SC;
  124. font-weight: bold;
  125. color: #FF6B2E;
  126. .yuan {
  127. display: inline-block;
  128. margin-left: 10rpx;
  129. font-size: 26rpx;
  130. font-family: PingFang SC;
  131. font-weight: 500;
  132. text-decoration: line-through;
  133. color: #989898;
  134. }
  135. }
  136. .btn {
  137. width: 44rpx;
  138. height: 44rpx;
  139. background: #00ca95;
  140. border-radius: 50rpx;
  141. }
  142. }
  143. }
  144. </style>