UNPKG

2.7 kBJavaScriptView Raw
1var __defProp = Object.defineProperty;
2var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3var __getOwnPropNames = Object.getOwnPropertyNames;
4var __hasOwnProp = Object.prototype.hasOwnProperty;
5var __export = (target, all) => {
6 for (var name2 in all)
7 __defProp(target, name2, { get: all[name2], enumerable: true });
8};
9var __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};
17var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18var stdin_exports = {};
19__export(stdin_exports, {
20 couponCellProps: () => couponCellProps,
21 default: () => stdin_default
22});
23module.exports = __toCommonJS(stdin_exports);
24var import_vue = require("vue");
25var import_utils = require("../utils");
26var import_cell = require("../cell");
27const [name, bem, t] = (0, import_utils.createNamespace)("coupon-cell");
28const 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};
39const 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};
52function 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}
71var 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});