supermarket.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 class="cart">
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  24. import empty from '@/components/empty';
  25. import {
  26. getCartList,
  27. } from '@/api/cart.js';
  28. import {
  29. getProducts,
  30. cartAdd
  31. } from '@/api/product.js';
  32. export default {
  33. data() {
  34. return {
  35. page: 1,
  36. limit: 20,
  37. loadingType: 'more',
  38. list: [],
  39. total:0
  40. };
  41. },
  42. components: {
  43. empty,
  44. uniLoadMore
  45. },
  46. onLoad() {
  47. this.loadData();
  48. },
  49. onShow() {
  50. this.loadCart();
  51. },
  52. onReachBottom() {
  53. this.loadData();
  54. },
  55. onReady() {},
  56. methods: {
  57. async loadCart() {
  58. let obj = this;
  59. getCartList({
  60. type:1
  61. })
  62. .then(function(e) {
  63. obj.total = e.data.valid.length;
  64. })
  65. .catch(function(e) {
  66. console.log(e);
  67. });
  68. },
  69. loadData() {
  70. if (this.loadingType == 'loading' || this.loadingType == 'nomore') {
  71. return
  72. }
  73. this.loadingType = 'loading'
  74. getProducts({
  75. page: this.page,
  76. limit: this.limit,
  77. cid: 1
  78. }).then(({
  79. data
  80. }) => {
  81. this.list = this.list.concat(data)
  82. this.page++
  83. if (data.length != this.limit) {
  84. this.loadingType = 'nomore'
  85. } else {
  86. this.loadingType = 'more'
  87. }
  88. })
  89. },
  90. toggleSpec(str) {
  91. cartAdd({
  92. cartNum: 1, //商品数量
  93. uniqueId: '', //商品标签
  94. new: 0, //商品是否新增加到购物车1为不加入0为加入
  95. mer_id: 0,
  96. is_consumer: 0,
  97. productId: str
  98. }).then(e => {
  99. uni.showToast({
  100. title: '成功加入购物车',
  101. type: 'top',
  102. duration: 2000
  103. });
  104. })
  105. },
  106. }
  107. };
  108. </script>
  109. <style lang="scss">
  110. page,
  111. .content {
  112. min-height: 100%;
  113. height: auto;
  114. }
  115. .guess {
  116. display: flex;
  117. justify-content: space-between;
  118. flex-wrap: wrap;
  119. padding: 20rpx;
  120. }
  121. .guess-item {
  122. margin-top: 20rpx;
  123. width: 345rpx;
  124. background: #FFFFFF;
  125. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  126. border-radius: 10rpx;
  127. image {
  128. width: 345rpx;
  129. height: 345rpx;
  130. border-radius: 10rpx;
  131. }
  132. .guess-box {
  133. padding: 28rpx 20rpx;
  134. width: 345rpx;
  135. .title {
  136. font-size: 30rpx;
  137. font-family: PingFang SC;
  138. font-weight: bold;
  139. color: #333333;
  140. }
  141. .price {
  142. font-size: 36rpx;
  143. font-family: PingFang SC;
  144. font-weight: bold;
  145. color: #FF6B2E;
  146. .yuan {
  147. display: inline-block;
  148. margin-left: 10rpx;
  149. font-size: 26rpx;
  150. font-family: PingFang SC;
  151. font-weight: 500;
  152. text-decoration: line-through;
  153. color: #989898;
  154. }
  155. }
  156. .btn {
  157. width: 44rpx;
  158. height: 44rpx;
  159. background: #00ca95;
  160. border-radius: 50rpx;
  161. }
  162. }
  163. }
  164. </style>