coupon.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * 优惠券
  3. *
  4. * @typedef {'default'|'useless'|'disabled'} CouponCardStatus
  5. * @typedef {'discount'|'price'} CouponCardType
  6. *
  7. * @param {number} [id]
  8. * @param {CouponCardStatus} [status]
  9. * @param {CouponCardType} [type]
  10. */
  11. export function getCoupon(id = 0, status = 'default', type = (id % 2) + 1) {
  12. return {
  13. /** key */
  14. key: `${id}`,
  15. /** 优惠券状态 */
  16. status,
  17. /** 优惠券类型 */
  18. type,
  19. /** 折扣或者满减值 */
  20. value: type === 2 ? 5.5 : 1800,
  21. /** 标签 */
  22. tag: '',
  23. /** 描述 */
  24. desc: parseInt(id) > 0 ? `满${parseInt(id) * 100}元可用` : '无门槛使用',
  25. /** 订单底价,满n元 */
  26. base: 10000 * (parseInt(id) || 0),
  27. /** 标题 */
  28. title: type === 2 ? `生鲜折扣券 - ${id}` : `生鲜满减券 - ${id}`,
  29. /** 有效时间限制 */
  30. timeLimit: '2019.11.18-2023.12.18',
  31. /** 货币符号 */
  32. currency: '¥',
  33. };
  34. }
  35. /** 优惠券列表 */
  36. export function getCouponList(status = 'default', length = 10) {
  37. return new Array(length).fill(0).map((_, idx) => getCoupon(idx, status));
  38. }