goods-price.vue 5.7 KB

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