Files
ipms-sjy-ui/src/views/mall/promotion/coupon/formatter.ts

61 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-08-26 22:29:55 +08:00
import { CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum } from '@/utils/constants'
import { formatDate } from '@/utils/formatTime'
import { CouponTemplateVO } from '@/api/mall/promotion/coupon/couponTemplate'
import { floatToFixed2 } from '@/utils'
// 格式化【优惠金额/折扣】
export const discountFormat = (row: CouponTemplateVO) => {
if (row.discountType === PromotionDiscountTypeEnum.PRICE.type) {
return `${floatToFixed2(row.discountPrice)}`
}
if (row.discountType === PromotionDiscountTypeEnum.PERCENT.type) {
2023-10-03 13:01:31 +08:00
return `${row.discountPercent}%`
2023-08-26 22:29:55 +08:00
}
return '未知【' + row.discountType + '】'
}
// 格式化【领取上限】
export const takeLimitCountFormat = (row: CouponTemplateVO) => {
2024-09-15 16:37:35 +08:00
if(row.takeLimitCount){
if (row.takeLimitCount === -1) {
return '无领取限制'
}
return `${row.takeLimitCount} 张/人`
}else{
return ' '
2023-08-26 22:29:55 +08:00
}
2024-09-15 16:37:35 +08:00
2023-08-26 22:29:55 +08:00
}
// 格式化【有效期限】
export const validityTypeFormat = (row: CouponTemplateVO) => {
if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
return `${formatDate(row.validStartTime)}${formatDate(row.validEndTime)}`
}
if (row.validityType === CouponTemplateValidityTypeEnum.TERM.type) {
return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`
}
return '未知【' + row.validityType + '】'
}
// 格式化【totalCount】
export const totalCountFormat = (row: CouponTemplateVO) => {
if (row.totalCount === -1) {
return '不限制'
}
return row.totalCount
}
2023-08-26 22:29:55 +08:00
// 格式化【剩余数量】
export const remainedCountFormat = (row: CouponTemplateVO) => {
if (row.totalCount === -1) {
return '不限制'
}
2023-08-26 22:29:55 +08:00
return row.totalCount - row.takeCount
}
// 格式化【最低消费】
2023-09-02 00:12:21 +08:00
export const usePriceFormat = (row: CouponTemplateVO) => {
2023-08-26 22:29:55 +08:00
return `${floatToFixed2(row.usePrice)}`
}