add-cart.vue 6.0 KB

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