goods-receive-buy-popup.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="goods-receive-buy-pupup" v-if="productData">
  3. <uni-popup ref="popup" type="bottom">
  4. <view class="close iconfont icon-iconfontguanbi" @click="close"></view>
  5. <view class="popup-content" :style="{ paddingBottom: safeArea ? 0 : '40rpx' }">
  6. <view class="content">
  7. <!-- 商品图片 -->
  8. <image :src="productData.mainImage" class="cover"></image>
  9. <view class="info">
  10. <!-- 数量 -->
  11. <view class="row">
  12. <view class="count">
  13. <view class="label">数量</view>
  14. <cm-number-box class="number-box" v-model="count" :max="limitedNum"></cm-number-box>
  15. {{ limitedNum }}
  16. </view>
  17. <view
  18. class="clickable"
  19. @click="$emit('detail')"
  20. v-if="productData.activeStatus > 0 && productData.ladderList.length > 0"
  21. >
  22. 查看活动价
  23. </view>
  24. </view>
  25. <!-- 单价 -->
  26. <view class="row">
  27. <view class="label">单价</view>
  28. <view class="amount">{{ productPrice | priceFormat }}</view>
  29. </view>
  30. <!-- 券后价 -->
  31. <view class="row" v-if="productData.couponStatus > 0">
  32. <view class="tag-qh">券后价¥{{ productData.couponPrice | priceFormat }}</view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="tip">
  37. <template v-if="productData.couponStatus > 0">
  38. 当前商品可使用
  39. <text v-text="currentCoupon.couponTitle"></text>
  40. 优惠券
  41. </template>
  42. </view>
  43. <tui-button type="base" width="600rpx" height="90rpx" shape="circle" @click="$emit('submit', count)">
  44. {{ navbarType === 'buy' ? (productData.couponStatus > 0 ? '领券购买' : '立即购买') : '加入购物车' }}
  45. </tui-button>
  46. </view>
  47. </uni-popup>
  48. </view>
  49. </template>
  50. <script>
  51. import { mapGetters } from 'vuex'
  52. export default {
  53. name: 'goods-receive-buy-pupup',
  54. props: {
  55. productData: {
  56. type: Object,
  57. default: () => null
  58. },
  59. currentCoupon: {
  60. type: Object,
  61. default: () => null
  62. },
  63. navbarType: {
  64. type: String,
  65. default: 'buy'
  66. }
  67. },
  68. data() {
  69. return {
  70. count: 1
  71. }
  72. },
  73. computed: {
  74. ...mapGetters(['safeArea']),
  75. productPrice() {
  76. return this.generatePrice()
  77. },
  78. limitedNum() {
  79. if (this.productData.collageStatus > 0) {
  80. return this.productData.collageProduct.limitedNum || this.productData.stock
  81. }
  82. return this.productData.stock
  83. }
  84. },
  85. watch: {
  86. count() {
  87. console.log(this.count, typeof this.count)
  88. }
  89. },
  90. methods: {
  91. open() {
  92. this.$refs.popup.open()
  93. this.$emit('open')
  94. this.count = 1
  95. },
  96. close() {
  97. this.$refs.popup.close()
  98. this.$emit('close')
  99. this.count = 1
  100. },
  101. generatePrice() {
  102. // 非阶梯价
  103. if (this.productData.activeStatus <= 0) {
  104. return this.productData.price
  105. }
  106. // 阶梯价列表为空
  107. if (!this.productData.ladderList) {
  108. return this.productData.price
  109. }
  110. // 阶梯价
  111. const lastItem = this.productData.ladderList
  112. .sort((a, b) => b.buyNum - a.buyNum)
  113. .find(item => this.count >= item.buyNum)
  114. return lastItem ? lastItem.buyPrice : this.productData.price
  115. }
  116. }
  117. }
  118. </script>
  119. <style>
  120. .vue-ref {
  121. border-radius: 16rpx 16rpx 0 0;
  122. overflow: hidden;
  123. }
  124. </style>
  125. <style lang="scss" scoped>
  126. .goods-receive-buy-pupup {
  127. position: relative;
  128. .close {
  129. position: absolute;
  130. right: 24rpx;
  131. top: 24rpx;
  132. color: #999;
  133. font-size: 32rpx;
  134. }
  135. .popup-content {
  136. @extend .cm-flex-center;
  137. flex-direction: column;
  138. padding: 40rpx 32rpx;
  139. background-color: #fff;
  140. border-radius: 16rpx 16rpx 0 0;
  141. &::after {
  142. position: absolute;
  143. content: '';
  144. width: 100%;
  145. height: 80rpx;
  146. bottom: -80rpx;
  147. left: 0;
  148. background-color: #fff;
  149. }
  150. .content {
  151. width: 100%;
  152. @extend .cm-flex-between;
  153. justify-content: flex-start;
  154. .cover {
  155. width: 180rpx;
  156. height: 180rpx;
  157. }
  158. .info {
  159. margin-left: 24rpx;
  160. .row {
  161. @extend .cm-flex-center;
  162. justify-content: flex-start;
  163. &:first-child {
  164. margin-bottom: 40rpx;
  165. }
  166. }
  167. .count {
  168. @extend .cm-flex-center;
  169. justify-content: flex-start;
  170. .number-box {
  171. margin: 0 24rpx;
  172. }
  173. }
  174. .label {
  175. font-size: 24rpx;
  176. color: #666666;
  177. &::after {
  178. content: ':';
  179. }
  180. }
  181. .clickable {
  182. font-size: 26rpx;
  183. color: #ff457b;
  184. }
  185. .amount {
  186. font-size: 26rpx;
  187. color: #ff457b;
  188. font-weight: bold;
  189. &::before {
  190. content: '¥';
  191. }
  192. }
  193. .tag-qh {
  194. display: inline-block;
  195. line-height: 40rpx;
  196. height: 40rpx;
  197. margin-top: 14rpx;
  198. background: #ff457b;
  199. border-radius: 25rpx;
  200. padding: 0 15rpx;
  201. font-size: 24rpx;
  202. font-weight: bold;
  203. color: #ffffff;
  204. }
  205. }
  206. }
  207. .tip {
  208. margin: 70rpx 0 24rpx;
  209. font-size: 24rpx;
  210. color: #666;
  211. text {
  212. color: #ff457b;
  213. }
  214. }
  215. }
  216. }
  217. </style>