formatter.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum } from '@/utils/constants'
  2. import { formatDate } from '@/utils/formatTime'
  3. import { CouponTemplateVO } from '@/api/mall/promotion/coupon/couponTemplate'
  4. import { floatToFixed2 } from '@/utils'
  5. // 格式化【优惠金额/折扣】
  6. export const discountFormat = (row: CouponTemplateVO) => {
  7. if (row.discountType === PromotionDiscountTypeEnum.PRICE.type) {
  8. return `¥${floatToFixed2(row.discountPrice)}`
  9. }
  10. if (row.discountType === PromotionDiscountTypeEnum.PERCENT.type) {
  11. return `${row.discountPercent}%`
  12. }
  13. return '未知【' + row.discountType + '】'
  14. }
  15. // 格式化【领取上限】
  16. export const takeLimitCountFormat = (row: CouponTemplateVO) => {
  17. if (row.takeLimitCount) {
  18. if (row.takeLimitCount === -1) {
  19. return '无领取限制'
  20. }
  21. return `${row.takeLimitCount} 张/人`
  22. } else {
  23. return ' '
  24. }
  25. }
  26. // 格式化【有效期限】
  27. export const validityTypeFormat = (row: CouponTemplateVO) => {
  28. if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
  29. return `${formatDate(row.validStartTime)} 至 ${formatDate(row.validEndTime)}`
  30. }
  31. if (row.validityType === CouponTemplateValidityTypeEnum.TERM.type) {
  32. return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`
  33. }
  34. return '未知【' + row.validityType + '】'
  35. }
  36. // 格式化【totalCount】
  37. export const totalCountFormat = (row: CouponTemplateVO) => {
  38. if (row.totalCount === -1) {
  39. return '不限制'
  40. }
  41. return row.totalCount
  42. }
  43. // 格式化【剩余数量】
  44. export const remainedCountFormat = (row: CouponTemplateVO) => {
  45. if (row.totalCount === -1) {
  46. return '不限制'
  47. }
  48. return row.totalCount - row.takeCount
  49. }
  50. // 格式化【最低消费】
  51. export const usePriceFormat = (row: CouponTemplateVO) => {
  52. return `¥${floatToFixed2(row.usePrice)}`
  53. }