supermarket.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. navToDetailPage(opt) {
  70. uni.navigateTo({
  71. url: '/pages/product/product?id=' + opt.id
  72. })
  73. },
  74. loadData() {
  75. if (this.loadingType == 'loading' || this.loadingType == 'nomore') {
  76. return
  77. }
  78. this.loadingType = 'loading'
  79. getProducts({
  80. page: this.page,
  81. limit: this.limit,
  82. cid: 1
  83. }).then(({
  84. data
  85. }) => {
  86. this.list = this.list.concat(data)
  87. this.page++
  88. if (data.length != this.limit) {
  89. this.loadingType = 'nomore'
  90. } else {
  91. this.loadingType = 'more'
  92. }
  93. })
  94. },
  95. toggleSpec(str) {
  96. cartAdd({
  97. cartNum: 1, //商品数量
  98. uniqueId: '', //商品标签
  99. new: 0, //商品是否新增加到购物车1为不加入0为加入
  100. mer_id: 0,
  101. is_consumer: 0,
  102. productId: str
  103. }).then(e => {
  104. uni.showToast({
  105. title: '成功加入购物车',
  106. type: 'top',
  107. duration: 2000
  108. });
  109. })
  110. },
  111. }
  112. };
  113. </script>
  114. <style lang="scss">
  115. page,
  116. .content {
  117. min-height: 100%;
  118. height: auto;
  119. }
  120. .guess {
  121. display: flex;
  122. justify-content: space-between;
  123. flex-wrap: wrap;
  124. padding: 20rpx;
  125. }
  126. .guess-item {
  127. margin-top: 20rpx;
  128. width: 345rpx;
  129. background: #FFFFFF;
  130. box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
  131. border-radius: 10rpx;
  132. image {
  133. width: 345rpx;
  134. height: 345rpx;
  135. border-radius: 10rpx;
  136. }
  137. .guess-box {
  138. padding: 28rpx 20rpx;
  139. width: 345rpx;
  140. .title {
  141. font-size: 30rpx;
  142. font-family: PingFang SC;
  143. font-weight: bold;
  144. color: #333333;
  145. }
  146. .price {
  147. font-size: 36rpx;
  148. font-family: PingFang SC;
  149. font-weight: bold;
  150. color: #FF6B2E;
  151. .yuan {
  152. display: inline-block;
  153. margin-left: 10rpx;
  154. font-size: 26rpx;
  155. font-family: PingFang SC;
  156. font-weight: 500;
  157. text-decoration: line-through;
  158. color: #989898;
  159. }
  160. }
  161. .btn {
  162. width: 44rpx;
  163. height: 44rpx;
  164. background: #00ca95;
  165. border-radius: 50rpx;
  166. }
  167. }
  168. }
  169. </style>