Coupon.mjs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { createVNode as _createVNode } from "vue";
  2. import { computed, defineComponent } from "vue";
  3. import { makeStringProp, createNamespace, makeRequiredProp } from "../utils/index.mjs";
  4. import { getDate, formatAmount, formatDiscount } from "./utils.mjs";
  5. import { Checkbox } from "../checkbox/index.mjs";
  6. const [name, bem, t] = createNamespace("coupon");
  7. var stdin_default = defineComponent({
  8. name,
  9. props: {
  10. chosen: Boolean,
  11. coupon: makeRequiredProp(Object),
  12. disabled: Boolean,
  13. currency: makeStringProp("\xA5")
  14. },
  15. setup(props) {
  16. const validPeriod = computed(() => {
  17. const {
  18. startAt,
  19. endAt
  20. } = props.coupon;
  21. return `${getDate(startAt)} - ${getDate(endAt)}`;
  22. });
  23. const faceAmount = computed(() => {
  24. const {
  25. coupon,
  26. currency
  27. } = props;
  28. if (coupon.valueDesc) {
  29. return [coupon.valueDesc, _createVNode("span", null, [coupon.unitDesc || ""])];
  30. }
  31. if (coupon.denominations) {
  32. const denominations = formatAmount(coupon.denominations);
  33. return [_createVNode("span", null, [currency]), ` ${denominations}`];
  34. }
  35. if (coupon.discount) {
  36. return t("discount", formatDiscount(coupon.discount));
  37. }
  38. return "";
  39. });
  40. const conditionMessage = computed(() => {
  41. const condition = formatAmount(props.coupon.originCondition || 0);
  42. return condition === "0" ? t("unlimited") : t("condition", condition);
  43. });
  44. return () => {
  45. const {
  46. chosen,
  47. coupon,
  48. disabled
  49. } = props;
  50. const description = disabled && coupon.reason || coupon.description;
  51. return _createVNode("div", {
  52. "class": bem({
  53. disabled
  54. })
  55. }, [_createVNode("div", {
  56. "class": bem("content")
  57. }, [_createVNode("div", {
  58. "class": bem("head")
  59. }, [_createVNode("h2", {
  60. "class": bem("amount")
  61. }, [faceAmount.value]), _createVNode("p", {
  62. "class": bem("condition")
  63. }, [coupon.condition || conditionMessage.value])]), _createVNode("div", {
  64. "class": bem("body")
  65. }, [_createVNode("p", {
  66. "class": bem("name")
  67. }, [coupon.name]), _createVNode("p", {
  68. "class": bem("valid")
  69. }, [validPeriod.value]), !disabled && _createVNode(Checkbox, {
  70. "class": bem("corner"),
  71. "modelValue": chosen
  72. }, null)])]), description && _createVNode("p", {
  73. "class": bem("description")
  74. }, [description])]);
  75. };
  76. }
  77. });
  78. export {
  79. stdin_default as default
  80. };