add-cart.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view v-if="showed" class="add-cart" @touchmove.stop="">
  3. <view class="content">
  4. <view class="close" @tap="showed = false">
  5. <text class="cuIcon-close"></text>
  6. </view>
  7. <view class="info">
  8. <view class="item-info">
  9. <image :src="item.main_img" mode=""></image>
  10. <view class="ellipsis">{{ item.name }}</view>
  11. <view class="shop-car" @click="toCart">
  12. <text class="cuIcon-cartfill"></text>
  13. </view>
  14. </view>
  15. <view v-for="(size, index) in item.size" :key="index" class="size-item">
  16. <view class="left">
  17. <text>{{ size }}</text>
  18. <text class="basecolor">¥{{ item.money }}/{{ item.unit }}</text>
  19. <!-- <text>库存:{{ item.storage[index] }}</text> -->
  20. </view>
  21. <NumInput :value="item.cart[index]" :args="[item.size_id[index]]" @change="numChange" />
  22. </view>
  23. </view>
  24. <view class="add" @tap="addCart">加入购物车</view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import NumInput from '@/components/public/num-input.vue'
  30. export default {
  31. components: { NumInput },
  32. data() {
  33. return {
  34. showed: false,
  35. item: {}
  36. }
  37. },
  38. computed: {
  39. choosedNum () {
  40. return this.item.cart.reduce((t, e) => t + e, 0)
  41. }
  42. },
  43. methods: {
  44. show(item) {
  45. this.showed = true
  46. this.item = item
  47. console.log(item)
  48. },
  49. hide() {
  50. this.showed = false
  51. },
  52. numChange(value, size_id) {
  53. this.$set(this.item.cart, this.item.size_id.findIndex(e => e === size_id), value)
  54. },
  55. addCart() {
  56. if (this.choosedNum) {
  57. this.item.choosed = true
  58. this.item.sizeChoosed = Array(this.item.size.length).fill(true)
  59. this.$store.commit('cart/ADD', this.item)
  60. this.hide()
  61. } else {
  62. uni.showToast({ title: '请选择尺寸', icon: 'none' })
  63. }
  64. },
  65. toCart() {
  66. uni.switchTab({ url: '../../pages/shop-car1/shop-car1' })
  67. }
  68. }
  69. }
  70. </script>
  71. <style lang="scss" scoped>
  72. .add-cart {
  73. position: fixed;
  74. width: 100vw;
  75. height: 100vh;
  76. z-index: 1;
  77. background: rgba(0, 0, 0, .3);
  78. .content {
  79. left: 0;
  80. right: 0;
  81. bottom: 0;
  82. height: 960rpx;
  83. @include flex(column);
  84. position: absolute;
  85. background: #FFFFFF;
  86. .close {
  87. top: 0;
  88. right: 0;
  89. width: 100rpx;
  90. height: 70rpx;
  91. font-size: 40rpx;
  92. @include flex();
  93. z-index: 1;
  94. position: absolute;
  95. }
  96. .info {
  97. width: 100%;
  98. height: 860rpx;
  99. overflow: auto;
  100. padding: 30rpx;
  101. position: relative;
  102. box-sizing: border-box;
  103. .item-info {
  104. height: 180rpx;
  105. @include flex();
  106. margin-bottom: 30rpx;
  107. align-items: flex-start;
  108. justify-content: flex-start;
  109. image {
  110. width: 180rpx;
  111. height: 180rpx;
  112. margin: 0 37rpx 0 18rpx;
  113. }
  114. .ellipsis {
  115. color: #181818;
  116. font-size: 32rpx;
  117. font-weight: bold;
  118. line-height: 3;
  119. }
  120. .shop-car {
  121. flex: 1;
  122. height: 100%;
  123. @include flex();
  124. text {
  125. @include flex();
  126. border-radius: 50%;
  127. background: $app-base-color;
  128. width: 100rpx;
  129. height: 100rpx;
  130. font-size: 48rpx;
  131. color: #FFFFFF;
  132. }
  133. }
  134. }
  135. .size-item {
  136. @include flex()
  137. height: 227rpx;
  138. padding: 36rpx 18rpx;
  139. box-sizing: border-box;
  140. border-top: 2rpx solid #CCCCCC;
  141. .left {
  142. flex: 1;
  143. height: 100%;
  144. font-size: 28rpx;
  145. margin-right: 24px;
  146. @include flex(column);
  147. align-items: flex-start;
  148. justify-content: space-between;
  149. .num {
  150. width: 100%;
  151. @include flex();
  152. justify-content: space-between;
  153. }
  154. }
  155. }
  156. }
  157. .add {
  158. @include flex();
  159. color: #FFFFFF;
  160. font-size: 36rpx;
  161. flex: 1;
  162. width: 100%;
  163. background: $app-base-color;
  164. }
  165. }
  166. }
  167. </style>