CouponCell.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. couponCellProps: () => couponCellProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_utils = require("../utils");
  26. var import_cell = require("../cell");
  27. const [name, bem, t] = (0, import_utils.createNamespace)("coupon-cell");
  28. const couponCellProps = {
  29. title: String,
  30. border: import_utils.truthProp,
  31. editable: import_utils.truthProp,
  32. coupons: (0, import_utils.makeArrayProp)(),
  33. currency: (0, import_utils.makeStringProp)("\xA5"),
  34. chosenCoupon: {
  35. type: [Number, Array],
  36. default: -1
  37. }
  38. };
  39. const getValue = (coupon) => {
  40. const {
  41. value,
  42. denominations
  43. } = coupon;
  44. if ((0, import_utils.isDef)(value)) {
  45. return value;
  46. }
  47. if ((0, import_utils.isDef)(denominations)) {
  48. return denominations;
  49. }
  50. return 0;
  51. };
  52. function formatValue({
  53. coupons,
  54. chosenCoupon,
  55. currency
  56. }) {
  57. let value = 0;
  58. let isExist = false;
  59. (Array.isArray(chosenCoupon) ? chosenCoupon : [chosenCoupon]).forEach((i) => {
  60. const coupon = coupons[+i];
  61. if (coupon) {
  62. isExist = true;
  63. value += getValue(coupon);
  64. }
  65. });
  66. if (isExist) {
  67. return `-${currency} ${(value / 100).toFixed(2)}`;
  68. }
  69. return coupons.length === 0 ? t("noCoupon") : t("count", coupons.length);
  70. }
  71. var stdin_default = (0, import_vue.defineComponent)({
  72. name,
  73. props: couponCellProps,
  74. setup(props) {
  75. return () => {
  76. const selected = Array.isArray(props.chosenCoupon) ? props.chosenCoupon.length : props.coupons[+props.chosenCoupon];
  77. return (0, import_vue.createVNode)(import_cell.Cell, {
  78. "class": bem(),
  79. "value": formatValue(props),
  80. "title": props.title || t("title"),
  81. "border": props.border,
  82. "isLink": props.editable,
  83. "valueClass": bem("value", {
  84. selected
  85. })
  86. }, null);
  87. };
  88. }
  89. });