goods.helper.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // 获取产品活动类型 (拼团 活动价 限时特价)
  2. export function generateActivityType(productData) {
  3. const { collageStatus = 0, activeStatus = 0, discountStatus = 0 } = productData
  4. // 拼团价
  5. if (collageStatus > 0) {
  6. return 'group' // 拼团价
  7. }
  8. // 限时活动
  9. else if (discountStatus > 0) {
  10. return 'time-limit'
  11. }
  12. // 普通活动价
  13. else if (activeStatus > 0) {
  14. return 'activity'
  15. }
  16. // 普通商品
  17. return 'normal' // 普通价
  18. }
  19. // 获取产品价格类型
  20. export function generatePriceType(productData) {
  21. const { couponStatus = 0, collageStatus = 0, activeStatus = 0, discountStatus = 0, couponId } = productData
  22. // 拼团价
  23. if (collageStatus > 0) {
  24. if (couponStatus === 1 && couponId) {
  25. return 'groupWithCoupon' // 拼团券后价
  26. } else {
  27. return 'group' // 拼团价
  28. }
  29. }
  30. // 限时活动
  31. else if (discountStatus > 0 || activeStatus > 0) {
  32. if (couponStatus === 1 && couponId) {
  33. return 'activityWithCoupon' // 券后价
  34. } else {
  35. return 'normal' // 限时活动价格
  36. }
  37. }
  38. // 无活动价
  39. else {
  40. if (couponStatus === 1 && couponId) {
  41. return 'normalWithCoupon' // 普通券后价
  42. } else {
  43. return 'normal' // 普通价
  44. }
  45. }
  46. }
  47. // 导航栏按钮类别
  48. const navbarButtonGroup = {
  49. // 仅拼团
  50. group: {
  51. left: ['单独购买', '¥1000.00'],
  52. right: ['拼团购买', '¥1000.00']
  53. },
  54. // 拼团 + 优惠券
  55. groupWithCoupon: {
  56. left: ['领券单独购买', '¥1000.00'],
  57. right: ['领券拼团购买', '¥1000.00']
  58. },
  59. // 限时活动 / 活动价 + 优惠券
  60. activityWithCoupon: {
  61. left: ['加入购物车'],
  62. right: ['领券购买', '¥1000.00']
  63. },
  64. // 限时活动 / 活动价 + 优惠券
  65. normalWithCoupon: {
  66. left: ['加入购物车'],
  67. right: ['领券购买', '¥1000.00']
  68. },
  69. // 普通方式 不使用优惠券
  70. normal: {
  71. left: ['加入购物车'],
  72. right: ['立即购买']
  73. }
  74. }
  75. export function generateNavbarButtonText(productData) {
  76. const { priceType } = productData
  77. const navbarButton = navbarButtonGroup[priceType]
  78. // 拼团券后价购买
  79. if (priceType === 'groupWithCoupon') {
  80. navbarButton.left[1] = `¥${productData.normalCouponPrice.toFixed(2)}`
  81. navbarButton.right[1] = `¥${productData.couponPrice.toFixed(2)}`
  82. }
  83. // 拼团价购买
  84. else if (priceType === 'group') {
  85. navbarButton.left[1] = `¥${productData.normalPrice.toFixed(2)}`
  86. navbarButton.right[1] = `¥${productData.price.toFixed(2)}`
  87. }
  88. // 活动价券后价购买(限时特价|普通活动)
  89. else if (priceType === 'activityWithCoupon') {
  90. navbarButton.right[1] = `¥${productData.couponPrice.toFixed(2)}`
  91. }
  92. // 普通价券后价购买
  93. else if (priceType === 'normalWithCoupon') {
  94. navbarButton.right[1] = `¥${productData.couponPrice.toFixed(2)}`
  95. } else {
  96. navbarButton.right[1] = ''
  97. }
  98. return navbarButton
  99. }