index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 _checkbox = _interopRequireDefault(require("../checkbox"));
  7. var _use = (0, _utils.use)('coupon'),
  8. sfc = _use[0],
  9. bem = _use[1],
  10. t = _use[2];
  11. function padZero(num) {
  12. return (num < 10 ? '0' : '') + num;
  13. }
  14. function getDate(timeStamp) {
  15. var date = new Date(timeStamp * 1000);
  16. return date.getFullYear() + "." + padZero(date.getMonth() + 1) + "." + padZero(date.getDate());
  17. }
  18. function formatDiscount(discount) {
  19. return (discount / 10).toFixed(discount % 10 === 0 ? 0 : 1);
  20. }
  21. function formatAmount(amount) {
  22. return (amount / 100).toFixed(amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2);
  23. }
  24. var _default = sfc({
  25. props: {
  26. coupon: Object,
  27. chosen: Boolean,
  28. disabled: Boolean,
  29. currency: {
  30. type: String,
  31. "default": '¥'
  32. }
  33. },
  34. computed: {
  35. validPeriod: function validPeriod() {
  36. return t('valid') + "\uFF1A" + getDate(this.coupon.startAt) + " - " + getDate(this.coupon.endAt);
  37. },
  38. faceAmount: function faceAmount() {
  39. var coupon = this.coupon;
  40. if (coupon.valueDesc) {
  41. return coupon.valueDesc + "<span>" + (coupon.unitDesc || '') + "</span>";
  42. }
  43. return coupon.denominations ? "<span>" + this.currency + "</span> " + formatAmount(this.coupon.denominations) : coupon.discount ? t('discount', formatDiscount(this.coupon.discount)) : '';
  44. },
  45. conditionMessage: function conditionMessage() {
  46. var condition = this.coupon.originCondition;
  47. condition = condition % 100 === 0 ? Math.round(condition / 100) : (condition / 100).toFixed(2);
  48. return condition === 0 ? t('unlimited') : t('condition', condition);
  49. }
  50. },
  51. render: function render(h) {
  52. var coupon = this.coupon,
  53. disabled = this.disabled;
  54. var description = disabled && coupon.reason || coupon.description;
  55. return h("div", {
  56. "class": bem({
  57. disabled: disabled
  58. })
  59. }, [h("div", {
  60. "class": bem('content')
  61. }, [h("div", {
  62. "class": bem('head')
  63. }, [h("h2", {
  64. "domProps": {
  65. "innerHTML": this.faceAmount
  66. }
  67. }), h("p", [this.coupon.condition || this.conditionMessage])]), h("div", {
  68. "class": bem('body')
  69. }, [h("h2", [coupon.name]), h("p", [this.validPeriod]), this.chosen && h(_checkbox["default"], {
  70. "attrs": {
  71. "value": true
  72. },
  73. "class": bem('corner')
  74. })])]), description && h("p", {
  75. "class": bem('description')
  76. }, [description])]);
  77. }
  78. });
  79. exports["default"] = _default;