formatter.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.discountPrice}%`
  12. }
  13. return '未知【' + row.discountType + '】'
  14. }
  15. // 格式化【领取上限】
  16. export const takeLimitCountFormat = (row: CouponTemplateVO) => {
  17. if (row.takeLimitCount === -1) {
  18. return '无领取限制'
  19. }
  20. return `${row.takeLimitCount} 张/人`
  21. }
  22. // 格式化【有效期限】
  23. export const validityTypeFormat = (row: CouponTemplateVO) => {
  24. if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
  25. return `${formatDate(row.validStartTime)} 至 ${formatDate(row.validEndTime)}`
  26. }
  27. if (row.validityType === CouponTemplateValidityTypeEnum.TERM.type) {
  28. return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`
  29. }
  30. return '未知【' + row.validityType + '】'
  31. }
  32. // 格式化【剩余数量】
  33. export const remainedCountFormat = (row: CouponTemplateVO) => {
  34. return row.totalCount - row.takeCount
  35. }
  36. // 格式化【最低消费】
  37. export const userPriceFormat = (row: CouponTemplateVO) => {
  38. return `¥${floatToFixed2(row.usePrice)}`
  39. }