goods-price.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. let type
  64. if (this.productData.activeStatus > 0) {
  65. type = 'activity'
  66. } else if (this.productData.collageStatus > 0) {
  67. type = 'group'
  68. } else if (this.productData.discountStatus > 0) {
  69. type = 'time-limit'
  70. } else {
  71. type = 'normal'
  72. }
  73. return type
  74. },
  75. // 有可使用优惠券
  76. hasCouponPrice() {
  77. return this.productData.couponStatus === 1
  78. },
  79. // 商品拼团信息
  80. collageInfo() {
  81. return this.productData?.collageProduct
  82. }
  83. },
  84. watch: {
  85. priceType(nVal) {
  86. if (nVal === 'time-limit') {
  87. this.countDown()
  88. }
  89. }
  90. },
  91. methods: {
  92. // 倒计时
  93. countDown() {
  94. const startTime = Date.now()
  95. const endTime = new Date(this.productData.discountEndTime).getTime()
  96. this.timer && clearTimeout(this.timer)
  97. countDown(endTime, startTime, {}, item => {
  98. this.countDownTime = item.conttainer
  99. this.timer = item.t
  100. })
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. .goods-price {
  107. position: relative;
  108. padding: 24rpx;
  109. background-color: #fff;
  110. .row {
  111. @extend .cm-flex-center;
  112. justify-content: flex-start;
  113. &:nth-child(2) {
  114. margin-top: 4rpx;
  115. }
  116. }
  117. .price {
  118. .amount {
  119. font-size: 48rpx;
  120. font-weight: bold;
  121. color: #ff457b;
  122. &::before {
  123. content: '¥';
  124. font-size: 24rpx;
  125. vertical-align: 2rpx;
  126. }
  127. }
  128. .delete {
  129. margin-left: 16rpx;
  130. font-size: 26rpx;
  131. font-weight: 400;
  132. color: #999999;
  133. text-decoration: line-through;
  134. &::before {
  135. content: '¥';
  136. }
  137. }
  138. }
  139. .price-tags {
  140. margin-left: 24rpx;
  141. @extend .cm-flex-center;
  142. justify-content: flex-start;
  143. margin-top: 10rpx;
  144. .tag-pt {
  145. @extend .cm-flex-center;
  146. height: 32rpx;
  147. padding: 0 8rpx;
  148. background: linear-gradient(90deg, #6431f2 0%, #b03bb8 49%, #ff457b 100%);
  149. border-radius: 4rpx;
  150. font-size: 22rpx;
  151. color: #fff;
  152. }
  153. .tag-hd,
  154. .tag-xs {
  155. @extend .cm-flex-center;
  156. display: block;
  157. height: 30rpx;
  158. padding: 0 8rpx;
  159. background: #fff3f7;
  160. border: 1rpx solid #ff457b;
  161. border-radius: 4rpx;
  162. font-size: 22rpx;
  163. color: #ff457b;
  164. }
  165. }
  166. .tag-qh {
  167. @extend .cm-flex-center;
  168. height: 40rpx;
  169. background: #ff457b;
  170. border-radius: 25rpx;
  171. padding: 0 15rpx;
  172. font-size: 24rpx;
  173. font-weight: bold;
  174. color: #ffffff;
  175. }
  176. }
  177. .countdown-box {
  178. position: absolute;
  179. top: 50%;
  180. right: 24rpx;
  181. transform: translateY(-50%);
  182. @extend .cm-flex-center;
  183. flex-direction: column;
  184. width: 160rpx;
  185. .tip {
  186. font-size: 24rpx;
  187. color: #ff457b;
  188. }
  189. .time {
  190. margin-top: 20rpx;
  191. width: 160rpx;
  192. @extend .cm-flex-between;
  193. font-size: 24rpx;
  194. font-weight: bold;
  195. color: #333333;
  196. text {
  197. @extend .cm-flex-center;
  198. width: 40rpx;
  199. height: 40rpx;
  200. background: #333;
  201. border-radius: 4rpx;
  202. color: #ffffff;
  203. }
  204. }
  205. }
  206. </style>