tek-ms-recap 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Recap/index.d.ts +9 -4
- package/dist/ms-recap.js +52 -38
- package/package.json +1 -1
package/dist/Recap/index.d.ts
CHANGED
|
@@ -8,17 +8,22 @@ export interface RecapItem {
|
|
|
8
8
|
quantity: number;
|
|
9
9
|
}
|
|
10
10
|
export interface RenderInterfaceRecap {
|
|
11
|
-
|
|
12
|
-
onConfirm: (
|
|
13
|
-
onCancel: () => void;
|
|
14
|
-
onRemove: (idx: number) => void;
|
|
11
|
+
items: RecapItem[];
|
|
12
|
+
onConfirm: (items: RecapItem[]) => void;
|
|
13
|
+
onCancel: (items: RecapItem[]) => void;
|
|
15
14
|
}
|
|
16
15
|
export declare class RecapSheet {
|
|
17
16
|
private el;
|
|
18
17
|
private items;
|
|
18
|
+
private total;
|
|
19
19
|
constructor(mountPoint: HTMLElement);
|
|
20
20
|
getItems(): RecapItem[];
|
|
21
21
|
setItems(_items: RecapItem[]): void;
|
|
22
|
+
getTotal(): number;
|
|
23
|
+
setTotal(_total: number): void;
|
|
22
24
|
onClose(): void;
|
|
25
|
+
removeFromCartItems(idx: number): void;
|
|
26
|
+
private renderItems;
|
|
27
|
+
private renderRecapTotal;
|
|
23
28
|
render(interfaceRender: RenderInterfaceRecap): void;
|
|
24
29
|
}
|
package/dist/ms-recap.js
CHANGED
|
@@ -7,6 +7,7 @@ function e(e) {
|
|
|
7
7
|
var t = class {
|
|
8
8
|
el;
|
|
9
9
|
items = [];
|
|
10
|
+
total = 0;
|
|
10
11
|
constructor(e) {
|
|
11
12
|
this.el = e;
|
|
12
13
|
}
|
|
@@ -16,37 +17,58 @@ var t = class {
|
|
|
16
17
|
setItems(e) {
|
|
17
18
|
this.items = e;
|
|
18
19
|
}
|
|
20
|
+
getTotal() {
|
|
21
|
+
return this.total;
|
|
22
|
+
}
|
|
23
|
+
setTotal(e) {
|
|
24
|
+
this.total = e;
|
|
25
|
+
}
|
|
19
26
|
onClose() {
|
|
20
|
-
this.el.innerHTML = "";
|
|
27
|
+
this.setItems([]), this.el.innerHTML = "";
|
|
28
|
+
}
|
|
29
|
+
removeFromCartItems(e) {
|
|
30
|
+
let t = this.getItems();
|
|
31
|
+
t.splice(e, 1), this.setItems(t), this.renderItems(), this.renderRecapTotal(), t.length == 0 && this.onClose();
|
|
32
|
+
}
|
|
33
|
+
renderItems() {
|
|
34
|
+
this.el.querySelector("#recap-items").innerHTML = `
|
|
35
|
+
${this.getItems().map((t, n) => `
|
|
36
|
+
<div class="recap-row">
|
|
37
|
+
<span class="ic">${t.icon}</span>
|
|
38
|
+
<div class="info">
|
|
39
|
+
<div class="pname">${t.name}</div>
|
|
40
|
+
<div class="qty" style="color:var(--rust)">× ${t.quantity}</div>
|
|
41
|
+
</div>
|
|
42
|
+
<span class="amt">${e(t.price)}</span>
|
|
43
|
+
<button class="del" data-idx="${n}">✕</button>
|
|
44
|
+
</div>
|
|
45
|
+
`).join("")}
|
|
46
|
+
`, this.el.querySelectorAll(".del").forEach((e) => {
|
|
47
|
+
e.addEventListener("click", () => {
|
|
48
|
+
let t = parseInt(e.dataset.idx ?? "0");
|
|
49
|
+
this.removeFromCartItems(t);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
renderRecapTotal() {
|
|
54
|
+
let t = this.getItems().reduce((e, t) => e + t.price * t.quantity, 0);
|
|
55
|
+
this.setTotal(t), this.el.querySelector("#recap-total").innerHTML = `${e(t)}`, this.el.querySelector("#total").innerHTML = `${e(t)}`;
|
|
21
56
|
}
|
|
22
57
|
render(t) {
|
|
23
|
-
|
|
24
|
-
this.setItems(t.cart), this.el.innerHTML = `
|
|
58
|
+
this.setItems(t.items), this.el.innerHTML = `
|
|
25
59
|
<div class="overlay show" id="recap-overlay">
|
|
26
60
|
<div class="sheet modal-recap" style="max-height:88vh;">
|
|
27
61
|
<div class="sheet-handle"></div>
|
|
28
62
|
<h3>Récapitulatif</h3>
|
|
29
63
|
<div class="catalog-price" style="margin-bottom:10px;">Vérifiez avant de confirmer</div>
|
|
30
|
-
<div class="recap-items" id="recap-items">
|
|
31
|
-
${t.cart.map((t, n) => `
|
|
32
|
-
<div class="recap-row">
|
|
33
|
-
<span class="ic">${t.icon}</span>
|
|
34
|
-
<div class="info">
|
|
35
|
-
<div class="pname">${t.name}</div>
|
|
36
|
-
<div class="qty">× ${t.quantity}</div>
|
|
37
|
-
</div>
|
|
38
|
-
<span class="amt">${e(t.quantity * t.price)}</span>
|
|
39
|
-
<button class="del" data-idx="${n}">✕</button>
|
|
40
|
-
</div>
|
|
41
|
-
`).join("")}
|
|
42
|
-
</div>
|
|
64
|
+
<div class="recap-items" id="recap-items"></div>
|
|
43
65
|
<div class="recap-totals">
|
|
44
|
-
<div class="sum-row"><span>Sous-total</span><span>${e(
|
|
66
|
+
<div class="sum-row"><span>Sous-total</span><span id="recap-total">${e(this.getTotal())}</span></div>
|
|
45
67
|
<div class="sum-row"><span>Remise</span><span style="color:var(--green);">— 0 F</span></div>
|
|
46
68
|
</div>
|
|
47
69
|
<div class="recap-total-box">
|
|
48
70
|
<span class="lab">TOTAL</span>
|
|
49
|
-
<span class="amt">${e(
|
|
71
|
+
<span class="amt" id="total">${e(this.getTotal())}</span>
|
|
50
72
|
</div>
|
|
51
73
|
<div class="price-field">
|
|
52
74
|
<div style="flex:1;">
|
|
@@ -67,28 +89,20 @@ var t = class {
|
|
|
67
89
|
</div>
|
|
68
90
|
</div>
|
|
69
91
|
`;
|
|
70
|
-
let
|
|
71
|
-
let e = parseFloat(
|
|
92
|
+
let n = this.el.querySelector("#amount-received"), r = this.el.querySelector("#change-amount"), i = this.el.querySelector("#change-row"), a = this.el.querySelector("#btn-confirm"), o = () => {
|
|
93
|
+
let e = parseFloat(n.value);
|
|
72
94
|
return Number.isFinite(e) ? e : 0;
|
|
73
|
-
},
|
|
74
|
-
let t =
|
|
75
|
-
|
|
76
|
-
let
|
|
77
|
-
|
|
95
|
+
}, s = () => {
|
|
96
|
+
let t = o(), n = t - this.getTotal();
|
|
97
|
+
r.textContent = e(Math.max(0, n));
|
|
98
|
+
let s = t < this.getTotal();
|
|
99
|
+
i.classList.toggle("insufficient", s), a.disabled = s || t === 0;
|
|
78
100
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}), this.el.querySelector("#btn-cancel")?.addEventListener("click", () => {
|
|
85
|
-
t.onCancel();
|
|
86
|
-
}), o.addEventListener("click", () => {
|
|
87
|
-
let e = s();
|
|
88
|
-
if (e < n) return;
|
|
89
|
-
let r = e - n;
|
|
90
|
-
t.onConfirm(e, r);
|
|
91
|
-
});
|
|
101
|
+
n.addEventListener("input", s), s(), this.el.querySelector("#btn-cancel")?.addEventListener("click", () => {
|
|
102
|
+
t.onCancel(this.getItems()), this.onClose();
|
|
103
|
+
}), a.addEventListener("click", () => {
|
|
104
|
+
t.onConfirm(this.getItems());
|
|
105
|
+
}), this.renderItems(), this.renderRecapTotal();
|
|
92
106
|
}
|
|
93
107
|
};
|
|
94
108
|
//#endregion
|