goods-price.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="goods-price" v-if="productData">
  3. <view class="row">
  4. <view class="price">
  5. <text class="amount">{{ productData.price | priceFormat }}</text>
  6. <text class="delete" v-if="priceType !== 'normal' && productData.normalPrice">
  7. {{ productData.normalPrice | priceFormat }}
  8. </text>
  9. </view>
  10. <view class="price-tags">
  11. <template v-if="priceType !== 'normal'">
  12. <view class="tag-pt" v-if="priceType === 'group'">
  13. <text v-if="collageInfo">{{ collageInfo.memberNum }}人拼团</text>
  14. </view>
  15. <view class="tag-hd" v-else-if="priceType === 'activity'">活动价</view>
  16. <view class="tag-xs" v-else>限时特价</view>
  17. </template>
  18. </view>
  19. <!-- 券后价 -->
  20. <view class="tag-qh" v-if="hasCouponPrice && priceType === 'normal'">
  21. 券后价¥{{ productData.couponPrice | priceFormat }}
  22. </view>
  23. </view>
  24. <!-- 券后价 -->
  25. <view class="row" v-if="hasCouponPrice && priceType !== 'normal'">
  26. <view class="tag-qh">券后价¥{{ productData.couponPrice | priceFormat }}</view>
  27. </view>
  28. <!-- 限时特价结束时间 -->
  29. <view class="countdown-box" v-if="priceType === 'time-limit'">
  30. <view class="tip">距离结束</view>
  31. <view class="time">
  32. <!-- 时 -->
  33. <text class="hh" v-text="countDownTime.ddhh"></text>
  34. :
  35. <!-- 分 -->
  36. <text class="mm" v-text="countDownTime.mm"></text>
  37. :
  38. <!-- 秒 -->
  39. <text class="ss" v-text="countDownTime.ss"></text>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import { countDown } from '@/common/utils.js'
  46. export default {
  47. name: 'goods-price',
  48. props: {
  49. productData: {
  50. type: Object,
  51. default: () => null
  52. }
  53. },
  54. data() {
  55. return {
  56. timer: null,
  57. countDownTime: {}
  58. }
  59. },
  60. computed: {
  61. /* 商品价格类型 normal: 普通价 | group: 拼团价 | activity: 活动价 | time-limit: 限时特价 | coupon: 券后价 */
  62. priceType() {
  63. return this.productData?.activityType
  64. },
  65. // 有可使用优惠券
  66. hasCouponPrice() {
  67. return this.productData.couponStatus === 1
  68. },
  69. // 商品拼团信息
  70. collageInfo() {
  71. return this.productData?.collageProduct
  72. }
  73. },
  74. watch: {
  75. priceType(nVal) {
  76. if (nVal === 'time-limit') {
  77. this.countDown()
  78. }
  79. }
  80. },
  81. methods: {
  82. // 倒计时
  83. countDown() {
  84. const startTime = Date.now()
  85. const endTime = new Date(this.productData.discountEndTime).getTime()
  86. this.timer && clearTimeout(this.timer)
  87. countDown(endTime, startTime, {}, item => {
  88. this.countDownTime = item.conttainer
  89. this.timer = item.t
  90. })
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss" scoped>
  96. .goods-price {
  97. position: relative;
  98. padding: 24rpx;
  99. background-color: #fff;
  100. .row {
  101. @extend .cm-flex-center;
  102. justify-content: flex-start;
  103. &:nth-child(2) {
  104. margin-top: 4rpx;
  105. }
  106. }
  107. .price {
  108. .amount {
  109. font-size: 48rpx;
  110. font-weight: bold;
  111. color: #ff457b;
  112. &::before {
  113. content: '¥';
  114. font-size: 24rpx;
  115. vertical-align: 2rpx;
  116. }
  117. }
  118. .delete {
  119. margin-left: 16rpx;
  120. font-size: 26rpx;
  121. font-weight: 400;
  122. color: #999999;
  123. text-decoration: line-through;
  124. &::before {
  125. content: '¥';
  126. }
  127. }
  128. }
  129. .price-tags {
  130. margin-left: 24rpx;
  131. @extend .cm-flex-center;
  132. justify-content: flex-start;
  133. margin-top: 10rpx;
  134. .tag-pt {
  135. @extend .cm-flex-center;
  136. height: 32rpx;
  137. padding: 0 8rpx;
  138. background: linear-gradient(90deg, #6431f2 0%, #b03bb8 49%, #ff457b 100%);
  139. border-radius: 4rpx;
  140. font-size: 22rpx;
  141. color: #fff;
  142. }
  143. .tag-hd,
  144. .tag-xs {
  145. @extend .cm-flex-center;
  146. display: block;
  147. height: 30rpx;
  148. padding: 0 8rpx;
  149. background: #fff3f7;
  150. border: 1rpx solid #ff457b;
  151. border-radius: 4rpx;
  152. font-size: 22rpx;
  153. color: #ff457b;
  154. }
  155. }
  156. .tag-qh {
  157. @extend .cm-flex-center;
  158. height: 40rpx;
  159. background: #ff457b;
  160. border-radius: 25rpx;
  161. padding: 0 15rpx;
  162. font-size: 24rpx;
  163. font-weight: bold;
  164. color: #ffffff;
  165. }
  166. }
  167. .countdown-box {
  168. position: absolute;
  169. top: 50%;
  170. right: 24rpx;
  171. transform: translateY(-50%);
  172. @extend .cm-flex-center;
  173. flex-direction: column;
  174. width: 160rpx;
  175. .tip {
  176. font-size: 24rpx;
  177. color: #ff457b;
  178. }
  179. .time {
  180. margin-top: 20rpx;
  181. width: 160rpx;
  182. @extend .cm-flex-between;
  183. font-size: 24rpx;
  184. font-weight: bold;
  185. color: #333333;
  186. text {
  187. @extend .cm-flex-center;
  188. width: 40rpx;
  189. height: 40rpx;
  190. background: #333;
  191. border-radius: 4rpx;
  192. color: #ffffff;
  193. }
  194. }
  195. }
  196. </style>