index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _utils = require("../utils");
  6. var _constant = require("../utils/constant");
  7. var _string = require("../utils/format/string");
  8. var _checkbox = _interopRequireDefault(require("../checkbox"));
  9. var _createNamespace = (0, _utils.createNamespace)('coupon'),
  10. createComponent = _createNamespace[0],
  11. bem = _createNamespace[1],
  12. t = _createNamespace[2];
  13. function getDate(timeStamp) {
  14. var date = new Date(timeStamp * 1000);
  15. return date.getFullYear() + "." + (0, _string.padZero)(date.getMonth() + 1) + "." + (0, _string.padZero)(date.getDate());
  16. }
  17. function formatDiscount(discount) {
  18. return (discount / 10).toFixed(discount % 10 === 0 ? 0 : 1);
  19. }
  20. function formatAmount(amount) {
  21. return (amount / 100).toFixed(amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2);
  22. }
  23. var _default = createComponent({
  24. props: {
  25. coupon: Object,
  26. chosen: Boolean,
  27. disabled: Boolean,
  28. currency: {
  29. type: String,
  30. default: '¥'
  31. }
  32. },
  33. computed: {
  34. validPeriod: function validPeriod() {
  35. var _this$coupon = this.coupon,
  36. startAt = _this$coupon.startAt,
  37. endAt = _this$coupon.endAt;
  38. return getDate(startAt) + " - " + getDate(endAt);
  39. },
  40. faceAmount: function faceAmount() {
  41. var coupon = this.coupon;
  42. if (coupon.valueDesc) {
  43. return coupon.valueDesc + "<span>" + (coupon.unitDesc || '') + "</span>";
  44. }
  45. if (coupon.denominations) {
  46. var denominations = formatAmount(coupon.denominations);
  47. return "<span>" + this.currency + "</span> " + denominations;
  48. }
  49. if (coupon.discount) {
  50. return t('discount', formatDiscount(coupon.discount));
  51. }
  52. return '';
  53. },
  54. conditionMessage: function conditionMessage() {
  55. var condition = formatAmount(this.coupon.originCondition);
  56. return condition === '0' ? t('unlimited') : t('condition', condition);
  57. }
  58. },
  59. render: function render() {
  60. var h = arguments[0];
  61. var coupon = this.coupon,
  62. disabled = this.disabled;
  63. var description = disabled && coupon.reason || coupon.description;
  64. return h("div", {
  65. "class": bem({
  66. disabled: disabled
  67. })
  68. }, [h("div", {
  69. "class": bem('content')
  70. }, [h("div", {
  71. "class": bem('head')
  72. }, [h("h2", {
  73. "class": bem('amount'),
  74. "domProps": {
  75. "innerHTML": this.faceAmount
  76. }
  77. }), h("p", {
  78. "class": bem('condition')
  79. }, [this.coupon.condition || this.conditionMessage])]), h("div", {
  80. "class": bem('body')
  81. }, [h("p", {
  82. "class": bem('name')
  83. }, [coupon.name]), h("p", {
  84. "class": bem('valid')
  85. }, [this.validPeriod]), !this.disabled && h(_checkbox.default, {
  86. "attrs": {
  87. "size": 18,
  88. "value": this.chosen,
  89. "checkedColor": _constant.RED
  90. },
  91. "class": bem('corner')
  92. })])]), description && h("p", {
  93. "class": bem('description')
  94. }, [description])]);
  95. }
  96. });
  97. exports.default = _default;