add-cart.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view v-if="showed" class="add-cart" catchtouchmove="ture">
  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="info_top">
  9. <view class="info_top_left">
  10. <image :src="item.main_img" mode="widthFix"></image>
  11. </view>
  12. <view class="info_top_right">
  13. <view>{{ item.name }}</view>
  14. <view class="shop-car" @click="toCart">
  15. <text class="cuIcon-cartfill"></text>
  16. </view>
  17. </view>
  18. </view>
  19. <scroll-view :scroll-y="true" class="info_top_bottom">
  20. <view v-for="(size, index) in item.size" :key="index" class="size-item">
  21. <view class="left">
  22. <text>{{ size }}</text>
  23. <text class="basecolor">¥{{ item.money }}/{{ item.unit }}</text>
  24. <!-- <text>库存:{{ item.storage[index] }}</text> -->
  25. </view>
  26. <view v-if="+item.storage[index] > 0">
  27. <NumInput :value="item.cart[index]" :args="[item.size_id[index]]" :num="item.step"
  28. @change="numChange" />
  29. </view>
  30. <view v-else>暂无库存</view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. <view class="add" @tap="addCart">加入购物车</view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import NumInput from '@/components/public/num-input.vue'
  40. export default {
  41. components: {
  42. NumInput
  43. },
  44. data() {
  45. return {
  46. showed: false,
  47. item: {}
  48. }
  49. },
  50. watch: {
  51. showed(a) {
  52. if (a) {
  53. let body = document.getElementsByTagName('body')[0]
  54. body.setAttribute('style', 'position: fixed;top:0;bottom:0;left:0;right:0;')
  55. } else {
  56. let body = document.getElementsByTagName('body')[0]
  57. body.removeAttribute('style')
  58. }
  59. }
  60. },
  61. computed: {
  62. choosedNum() {
  63. return this.item.cart.reduce((t, e) => t + e, 0)
  64. }
  65. },
  66. destroyed() {
  67. let body = document.getElementsByTagName('body')[0]
  68. body.removeAttribute('style')
  69. },
  70. methods: {
  71. mask() {
  72. return false
  73. },
  74. show(item) {
  75. this.showed = true
  76. this.item = item
  77. console.log(item, 'item')
  78. },
  79. hide() {
  80. this.showed = false
  81. },
  82. numChange(value, size_id) {
  83. this.$set(this.item.cart, this.item.size_id.findIndex(e => e === size_id), value)
  84. },
  85. addCart() {
  86. if (this.choosedNum) {
  87. this.item.choosed = true
  88. this.item.sizeChoosed = Array(this.item.size.length).fill(true)
  89. this.$store.commit('cart/ADD', this.item)
  90. this.item.open = false
  91. this.hide()
  92. } else {
  93. uni.showToast({
  94. title: '请选择尺寸',
  95. icon: 'none'
  96. })
  97. }
  98. },
  99. toCart() {
  100. uni.switchTab({
  101. url: '../../pages/shop-car1/shop-car1'
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .add-cart {
  109. position: fixed;
  110. width: 100%;
  111. height: 100%;
  112. z-index: 1;
  113. background: rgba(0, 0, 0, .3);
  114. overflow: hidden;
  115. .content {
  116. left: 0;
  117. right: 0;
  118. bottom: 0;
  119. height: 960rpx;
  120. display: flex;
  121. justify-content: space-between;
  122. flex-direction: column;
  123. position: absolute;
  124. background: #FFFFFF;
  125. .close {
  126. top: 0;
  127. right: 0;
  128. width: 100rpx;
  129. height: 70rpx;
  130. font-size: 40rpx;
  131. @include flex();
  132. z-index: 1;
  133. position: absolute;
  134. }
  135. .info {
  136. flex: 1;
  137. width: 100%;
  138. overflow: auto;
  139. padding: 30rpx;
  140. position: relative;
  141. display: flex;
  142. justify-content: flex-start;
  143. flex-direction: column;
  144. overflow: hidden;
  145. align-items: center;
  146. .info_top {
  147. width: 100%;
  148. height: 180rpx;
  149. display: flex;
  150. justify-content: space-between;
  151. margin-bottom: 10rpx;
  152. background-color: #FFFFFF;
  153. .info_top_left {
  154. width: 180rpx;
  155. height: 180rpx;
  156. display: flex;
  157. justify-content: center;
  158. align-items: center;
  159. }
  160. .info_top_right {
  161. padding-left: 10rpx;
  162. flex: 1;
  163. color: #181818;
  164. font-size: 32rpx;
  165. font-weight: bold;
  166. height: 180rpx;
  167. display: flex;
  168. justify-content: center;
  169. flex-direction: column;
  170. .shop-car {
  171. width: 100%;
  172. @include flex();
  173. justify-content: flex-end;
  174. text {
  175. @include flex();
  176. border-radius: 50%;
  177. background: $app-base-color;
  178. width: 100rpx;
  179. height: 100rpx;
  180. font-size: 48rpx;
  181. color: #FFFFFF;
  182. }
  183. }
  184. }
  185. }
  186. .info_top_bottom {
  187. width: 100%;
  188. height: calc(100% - 190rpx);
  189. }
  190. .item-info {
  191. @include flex();
  192. margin-bottom: 30rpx;
  193. align-items: flex-start;
  194. justify-content: space-between;
  195. width: 100%;
  196. height: 180rpx !important;
  197. overflow: hidden;
  198. .main_img_box {
  199. width: 180rpx;
  200. height: 180rpx;
  201. margin: 0 18rpx 0 18rpx;
  202. display: flex;
  203. align-items: center;
  204. justify-content: center;
  205. image {
  206. display: block;
  207. width: 225rpx !important;
  208. height: 180rpx !important;
  209. }
  210. }
  211. .ellipsis {
  212. color: #181818;
  213. font-size: 32rpx;
  214. font-weight: bold;
  215. line-height: 3;
  216. }
  217. .shop-car {
  218. flex: 1;
  219. height: 100%;
  220. @include flex();
  221. text {
  222. @include flex();
  223. border-radius: 50%;
  224. background: $app-base-color;
  225. width: 100rpx;
  226. height: 100rpx;
  227. font-size: 48rpx;
  228. color: #FFFFFF;
  229. }
  230. }
  231. }
  232. .size-item {
  233. @include flex() padding: 36rpx 18rpx;
  234. box-sizing: border-box;
  235. border-top: 2rpx solid #CCCCCC;
  236. .left {
  237. flex: 1;
  238. height: 100%;
  239. font-size: 28rpx;
  240. margin-right: 24px;
  241. @include flex(column);
  242. align-items: flex-start;
  243. justify-content: space-between;
  244. .num {
  245. width: 100%;
  246. @include flex();
  247. justify-content: space-between;
  248. }
  249. }
  250. }
  251. }
  252. .add {
  253. @include flex();
  254. color: #FFFFFF;
  255. font-size: 36rpx;
  256. height: 80rpx;
  257. width: 100%;
  258. background: $app-base-color;
  259. }
  260. }
  261. }
  262. </style>