goods-receive-buy-popup.vue 7.0 KB

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