gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import type { MallCouponTemplateApi } from '#/api/mall/promotion/coupon/couponTemplate';
 
import {
  CouponTemplateValidityTypeEnum,
  PromotionDiscountTypeEnum,
} from '..\..\..\..\packages\constants\src';
import { floatToFixed2, formatDate } from '..\..\..\..\packages\utils\src';
 
/** 格式化【优惠金额/折扣】 */
export function discountFormat(row: MallCouponTemplateApi.CouponTemplate) {
  if (row.discountType === PromotionDiscountTypeEnum.PRICE.type) {
    return `¥${floatToFixed2(row.discountPrice)}`;
  }
  if (row.discountType === PromotionDiscountTypeEnum.PERCENT.type) {
    return `${row.discountPercent}%`;
  }
  return `未知【${row.discountType}】`;
}
 
/** 格式化【领取上限】 */
export function takeLimitCountFormat(
  row: MallCouponTemplateApi.CouponTemplate,
) {
  if (row.takeLimitCount) {
    if (row.takeLimitCount === -1) {
      return '无领取限制';
    }
    return `${row.takeLimitCount} 张/人`;
  } else {
    return ' ';
  }
}
 
/** 格式化【有效期限】 */
export function validityTypeFormat(row: MallCouponTemplateApi.CouponTemplate) {
  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 function totalCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
  if (row.totalCount === -1) {
    return '不限制';
  }
  return `${row.totalCount}`;
}
 
/** 格式化【剩余数量】 */
export function remainedCountFormat(row: MallCouponTemplateApi.CouponTemplate) {
  if (row.totalCount === -1) {
    return '不限制';
  }
  return `${row.totalCount - row.takeCount}`;
}
 
/** 格式化【最低消费】 */
export function usePriceFormat(row: MallCouponTemplateApi.CouponTemplate) {
  return `¥${floatToFixed2(row.usePrice)}`;
}