@viur/shop-components 0.0.1-dev.2 → 0.0.1-dev.20

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.
@@ -0,0 +1,725 @@
1
+ <template>
2
+ <Loader v-if="!cartKey.length"></Loader>
3
+ <template v-else>
4
+ <pre> {{ state.nodes }}</pre>
5
+ <pre> {{ state.leaves }}</pre>
6
+ </template>
7
+
8
+ <!-- <CartNode></CartNode>
9
+ <CartLeaf></CartLeaf> -->
10
+ <!-- <template v-else>
11
+ <div class="bind viur-shop-cart-wrap">
12
+ <sl-dialog ref="confirm" @sl-hide="onDialogHide">
13
+ <p>Möchten Sie den Artikel wirklich aus dem Warenkorb entfernen?</p>
14
+ <div class="footer-wrap" slot="footer">
15
+ <sl-button variant="danger" @click="confirm.hide()" size="medium">
16
+ Abbrechen
17
+ </sl-button>
18
+ <sl-button variant="success" @click="onConfirm" size="medium">
19
+ Aus Warenkorb entfernen
20
+ </sl-button>
21
+ </div>
22
+ </sl-dialog>
23
+
24
+ <div class="viur-shop-cart-list">
25
+ <div class="viur-shop-cart-controlbar" v-if="mode !== 'basket'">
26
+ <div class="viur-shop-cart-button-list left">
27
+ <sl-input
28
+ ref="cartNameField"
29
+ name="cart-name"
30
+ placeholder="Warenkorbname"
31
+ v-model="cartStore.state.carts[cartStore.state.basket].info.name"
32
+ required="true"
33
+ inputmode="text"
34
+ class="viur-shop-cart-headline"
35
+ >
36
+ <sl-icon library="hsk" name="pen" slot="suffix"></sl-icon>
37
+ </sl-input>
38
+ </div>
39
+ <sl-dropdown distance="10">
40
+ <sl-icon
41
+ class="dots"
42
+ name="dots"
43
+ library="hsk"
44
+ slot="trigger"
45
+ ></sl-icon>
46
+ <sl-menu>
47
+ <sl-menu-item @click="saveCart" title="Warenkorb speichern">
48
+ <sl-icon
49
+ slot="prefix"
50
+ library="hsk"
51
+ name="save"
52
+ class="primary-icon"
53
+ ></sl-icon>
54
+ Warenkorb speichern
55
+ </sl-menu-item>
56
+ <sl-menu-item @click="saveCart" title="Zu Projekt hinzufügen">
57
+ <sl-icon
58
+ slot="prefix"
59
+ library="hsk"
60
+ name="project"
61
+ class="primary-icon"
62
+ ></sl-icon>
63
+ Zu Projekt hinzufügen
64
+ </sl-menu-item>
65
+ <sl-menu-item @click="saveCart" title="Warenkorb kopieren">
66
+ <sl-icon
67
+ slot="prefix"
68
+ library="hsk"
69
+ name="clone"
70
+ class="primary-icon"
71
+ ></sl-icon>
72
+ Warenkorb kopieren
73
+ </sl-menu-item>
74
+ <sl-menu-item @click="saveCart" title="Warenkorb löschen">
75
+ <sl-icon
76
+ slot="prefix"
77
+ library="hsk"
78
+ name="delete"
79
+ class="delete-icon"
80
+ ></sl-icon>
81
+ Warenkorb löschen
82
+ </sl-menu-item>
83
+ </sl-menu>
84
+ </sl-dropdown>
85
+ </div>
86
+ <sl-input
87
+ v-if="mode !== 'basket'"
88
+ name="cart-internalCartNo"
89
+ placeholder="Freifeld (Kommission)"
90
+ v-model="
91
+ cartStore.state.carts[cartStore.state.basket].info.customer_comment
92
+ "
93
+ inputmode="text"
94
+ class="viur-shop-cart-descr"
95
+ >
96
+ <sl-icon library="hsk" name="pen" slot="suffix"></sl-icon>
97
+ </sl-input>
98
+ <br />
99
+ <sl-alert
100
+ ref="cartActionInfo"
101
+ variant="primary"
102
+ duration="3000"
103
+ closable
104
+ >
105
+ <sl-icon slot="icon" name="check"></sl-icon>
106
+ <strong>Warenkorb gespeichert!</strong><br />
107
+ </sl-alert>
108
+ <sl-alert ref="cartErrorInfo" variant="danger" duration="3000" closable>
109
+ <sl-icon slot="icon" name="error"></sl-icon>
110
+ <strong>Warenkorb nicht gespeichert!</strong><br />
111
+ </sl-alert>
112
+
113
+ <sl-spinner v-if="!state.itemsIsInit"></sl-spinner>
114
+
115
+ <template v-else>
116
+ <sl-card
117
+ horizontal
118
+ class="viur-shop-cart-card"
119
+ v-for="item in cartStore.state.carts[cartStore.state.basket].items"
120
+ >
121
+ <img
122
+ class="viur-shop-cart-card-img"
123
+ slot="image"
124
+ src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80"
125
+ />
126
+ <div class="viur-shop-cart-card-header" slot="header">
127
+ <h4 class="viur-shop-cart-card-headline headline">
128
+ {{ item.article.dest.shop_name }} | 425018
129
+ </h4>
130
+ </div>
131
+ <div class="viur-shop-cart-card-body-row">
132
+ <div class="viur-shop-cart-card-body-info">
133
+ <div class="viur-shop-cart-card-descr">
134
+ Version: 900x900x2000 <br />
135
+ Farbe: Chromoptik <br />
136
+ Glasart: Klar hell mit Edelglasbeschichtung<br />
137
+ Anschlag: Beidseitig variabel<br />
138
+ Griff: Stangengriff Exklusiv (56)
139
+ </div>
140
+ <div class="viur-shop-cart-card-body-footer">
141
+ <sl-button
142
+ size="small"
143
+ outline
144
+ class="viur-shop-cart-card-add-to-favourites-btn"
145
+ variant="primary"
146
+ title="Add to favourites"
147
+ >
148
+ <sl-icon name="heart" slot="prefix"></sl-icon>
149
+ </sl-button>
150
+ <sl-button
151
+ size="small"
152
+ outline
153
+ class="viur-shop-cart-card-delete-btn"
154
+ variant="primary"
155
+ title="Remove from cart"
156
+ @click="
157
+ removeItem(
158
+ item,
159
+ item.article.dest.key,
160
+ cartStore.state.basket,
161
+ )
162
+ "
163
+ >
164
+ <sl-icon name="trash" slot="prefix"></sl-icon>
165
+ </sl-button>
166
+ </div>
167
+ </div>
168
+ <div class="viur-shop-cart-card-body-amount">
169
+ <sl-input
170
+ class="amount-input"
171
+ type="number"
172
+ label="Anzahl"
173
+ placeholder="Number"
174
+ min="0"
175
+ v-model="item.quantity"
176
+ @input="
177
+ updateItem(
178
+ item,
179
+ item.article.dest.key,
180
+ cartStore.state.basket,
181
+ item.quantity,
182
+ )
183
+ "
184
+ >
185
+ </sl-input>
186
+ </div>
187
+ <div class="viur-shop-cart-card-price-wrap" slot="footer">
188
+ <div class="viur-shop-cart-card-price-label">Preis</div>
189
+ <div class="viur-shop-cart-card-price">
190
+ {{ item.price.retail }}
191
+
192
+ </div>
193
+ <div class="viur-shop-cart-card-small-print">Brutto / Stk.</div>
194
+ </div>
195
+ </div>
196
+ </sl-card>
197
+ </template>
198
+ </div>
199
+
200
+ <teleport to="#order_sidebar" v-if="sidebar">
201
+ <h2 class="viur-shop-cart-sidebar-headline headline">
202
+ Zusammenfassung
203
+ </h2>
204
+ <br />
205
+
206
+ <sl-input label="Rabattcode eingeben"></sl-input>
207
+ <br />
208
+
209
+ <div class="viur-shop-cart-sidebar-info-line">
210
+ <span>Zwischensumme</span> -->
211
+ <!-- TODO: Preis in shop modul muss trotzdem ohne rabatt sein - extra feld für rabattierten preis und rabatt müssen ebenfalls hier sichtbar werden -->
212
+ <!-- {{ cartStore.state.carts[cartStore.state.basket].info.total }} €
213
+ </div>
214
+ <div class="viur-shop-cart-sidebar-info-line">
215
+ <span>Rabatt</span>
216
+ 0 €
217
+ </div>
218
+ <div class="viur-shop-cart-sidebar-info-line">
219
+ <span>Versandkosten</span>
220
+ 0 €
221
+ </div>
222
+ <div class="viur-shop-cart-sidebar-info-line total">
223
+ <span>Gesamt:</span>
224
+ {{ cartStore.state.carts[cartStore.state.basket].info.total }} €
225
+ </div>
226
+ <div class="viur-shop-cart-sidebar-btn-wrap">
227
+ <sl-button variant="info" size="small"> Jetzt Bestellen </sl-button>
228
+ <sl-button size="small" variant="primary">
229
+ <sl-icon name="paypal" slot="prefix"></sl-icon>
230
+ Paypal
231
+ </sl-button>
232
+ </div>
233
+ </teleport>
234
+ </div>
235
+ </template> -->
236
+ </template>
237
+
238
+ <script setup>
239
+ import { reactive, computed, onBeforeMount, ref } from "vue";
240
+ import Loader from "@viur/vue-utils/generic/Loader.vue";
241
+ import { useCartStore } from "../../stores/cart.js";
242
+ import CartNode from "./CartNode.vue";
243
+ import CartLeaf from "./CartLeaf.vue";
244
+
245
+ const props = defineProps({
246
+ mode: { type: String, default: "basket" },
247
+ cartKey: { type: String, required: true },
248
+ sidebar: { type: Boolean, default: true },
249
+ });
250
+
251
+ const cartStore = useCartStore();
252
+
253
+ const confirm = ref(null);
254
+
255
+ const state = reactive({
256
+ cartIsInit: computed(() => {
257
+ return cartStore.state.basketRootNode ? true : false;
258
+ }),
259
+ itemsIsInit: computed(() => {
260
+ return true;
261
+ }),
262
+ images: {},
263
+ currentItem: {},
264
+ nodes: [],
265
+ leaves: {},
266
+ });
267
+
268
+ const currentCartKey = computed(() => {
269
+ return props.mode === "basket" ? cartStore.state.basket : props.cartKey;
270
+ });
271
+
272
+ // function getImage(item) {
273
+ // Request.get(`/json/dk_variante/view/${item}`).then(async (resp) => {
274
+ // let data = await resp.json();
275
+
276
+ // data = data.values;
277
+
278
+ // let imageUrl = data.dk_artikel.dest.image
279
+ // ? Request.downloadUrlFor(data.dk_artikel.dest.image)
280
+ // : "https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80";
281
+
282
+ // state.images[item] = imageUrl;
283
+ // });
284
+
285
+ // return state.images[item];
286
+ // }
287
+
288
+ async function onConfirm() {
289
+ await cartStore.updateItem(
290
+ state.currentItem.article.dest.key,
291
+ cartStore.state.basket,
292
+ 0,
293
+ );
294
+ confirm.value.hide();
295
+ }
296
+
297
+ function updateItem(item, articleKey, cartKey, quantity) {
298
+ if (quantity === 0) {
299
+ confirm.value.show();
300
+ state.currentItem = item;
301
+ } else {
302
+ cartStore.updateItem(articleKey, cartKey, quantity);
303
+ }
304
+ }
305
+
306
+ function removeItem(item, articleKey, cartKey) {
307
+ confirm.value.show();
308
+ state.currentItem = item;
309
+ }
310
+
311
+ function onDialogHide() {
312
+ cartStore.state.carts[cartStore.state.basket].items.forEach((item) => {
313
+ if (item.key === state.currentItem.key) {
314
+ item.quantity = 1;
315
+ }
316
+ });
317
+ state.currentItem = {};
318
+ }
319
+
320
+ async function getChildren(parentKey = props.cartKey) {
321
+ console.log("debug getChildren parentKey from comp: ", parentKey);
322
+ const children = await cartStore.getChildren(parentKey);
323
+ console.log("getChildren children: ", children);
324
+
325
+ children.forEach(async (child) => {
326
+ if (child.skel_type === "node") {
327
+ state.nodes.push(child);
328
+ await getChildren(child.key);
329
+ } else {
330
+ if (!Object.keys(state.leaves).includes(parentKey)) {
331
+ state.leaves[parentKey] = [];
332
+ }
333
+ state.leaves[parentKey].push(child);
334
+ }
335
+ });
336
+ }
337
+
338
+ onBeforeMount(async () => {
339
+ await cartStore.init();
340
+ await getChildren();
341
+
342
+ console.log("state.nodes", state.nodes);
343
+
344
+ console.log("state.leaves", state.leaves);
345
+ });
346
+ </script>
347
+
348
+ <style scoped>
349
+ .viur-shop-cart-wrap {
350
+ flex-direction: row;
351
+ gap: var(--sl-spacing-x-large);
352
+ align-items: flex-start;
353
+ }
354
+
355
+ .viur-shop-cart-sidebar-btn-wrap {
356
+ display: flex;
357
+ flex-direction: column;
358
+ margin-top: var(--sl-spacing-large);
359
+
360
+ sl-button {
361
+ margin-bottom: var(--sl-spacing-x-small);
362
+ }
363
+ }
364
+
365
+ sl-alert {
366
+ margin-top: var(--sl-spacing-medium);
367
+ margin-bottom: var(--sl-spacing-medium);
368
+ }
369
+
370
+ .viur-shop-cart-controlbar {
371
+ width: 100%;
372
+ display: flex;
373
+ justify-content: space-between;
374
+ align-items: center;
375
+
376
+ sl-input {
377
+ flex: 1;
378
+
379
+ &::part(base) {
380
+ margin-bottom: 0;
381
+ }
382
+ }
383
+ }
384
+
385
+ .viur-shop-cart-button-list {
386
+ display: flex;
387
+ flex-direction: row;
388
+ gap: 10px;
389
+
390
+ &.left {
391
+ flex: 1;
392
+ margin-right: 10px;
393
+ }
394
+ }
395
+
396
+ .search {
397
+ flex: 1 1 100%;
398
+ margin-left: 10px;
399
+ }
400
+
401
+ .article-combobox {
402
+ float: left;
403
+ width: 75ch;
404
+ }
405
+
406
+ .viur-shop-cart-card-img {
407
+ aspect-ratio: 1;
408
+ }
409
+
410
+ .viur-shop-cart-selection {
411
+ flex: 1;
412
+ }
413
+
414
+ .cart-wrap {
415
+ display: flex;
416
+ flex-direction: column;
417
+ width: 100%;
418
+ }
419
+
420
+ .soma-input {
421
+ display: grid;
422
+ grid-template-columns: 120px 1fr;
423
+ align-items: center;
424
+ }
425
+
426
+ .soma-label {
427
+ display: flex;
428
+ flex-direction: row;
429
+ align-items: center;
430
+
431
+ sl-icon {
432
+ margin-left: 5px;
433
+ background-color: @highlightColor;
434
+ color: #fff;
435
+ aspect-ratio: 1;
436
+ border-radius: 50%;
437
+ padding: 0.3em;
438
+ font-size: 0.6em;
439
+ cursor: pointer;
440
+ }
441
+ }
442
+
443
+ sl-tooltip {
444
+ &::part(body) {
445
+ line-height: 1.2;
446
+ font-weight: 400;
447
+ padding: 10px;
448
+ }
449
+ }
450
+
451
+ .cart-tab {
452
+ sl-tab {
453
+ width: 25%;
454
+
455
+ &::part(base) {
456
+ width: 100%;
457
+ height: 100%;
458
+ display: flex;
459
+ justify-content: center;
460
+ align-items: center;
461
+ position: relative;
462
+ color: var(--sl-color-neutral-400);
463
+ }
464
+
465
+ &[aria-selected="true"]::part(base) {
466
+ color: var(--ignt-color-primary) !important;
467
+ }
468
+ }
469
+ }
470
+
471
+ .cart-status-text {
472
+ font-size: 0.8em;
473
+ color: inherit;
474
+ text-align: center;
475
+ margin-top: 0.6em;
476
+ white-space: initial;
477
+ }
478
+
479
+ .search-box {
480
+ display: flex;
481
+ flex-direction: row;
482
+ flex-wrap: nowrap;
483
+ align-items: stretch;
484
+ margin-bottom: 30px;
485
+
486
+ sl-button {
487
+ &::part(base) {
488
+ height: 100%;
489
+ }
490
+ }
491
+
492
+ @media (--ignt-mq-max-break-medium) {
493
+ flex-wrap: wrap;
494
+ }
495
+ }
496
+
497
+ .article-combobox {
498
+ flex: 1 1 100%;
499
+ margin-bottom: 10px;
500
+
501
+ &::part(base) {
502
+ margin-bottom: 0;
503
+ }
504
+
505
+ @media (--ignt-mq-max-break-medium) {
506
+ margin-bottom: 0;
507
+ }
508
+ }
509
+
510
+ .comission-box {
511
+ margin-right: 10px;
512
+
513
+ &::part(base) {
514
+ margin-bottom: 0;
515
+ }
516
+
517
+ @media (--ignt-mq-max-break-medium) {
518
+ flex: 1;
519
+ }
520
+ }
521
+
522
+ .search-amt {
523
+ margin-right: 10px;
524
+
525
+ &::part(base) {
526
+ margin-bottom: 0;
527
+ width: 80px;
528
+ }
529
+ }
530
+
531
+ .viur-shop-cart-headline {
532
+ &::part(base) {
533
+ background-color: transparent;
534
+ transition: all ease 0.3s;
535
+ border-bottom: 1px solid transparent;
536
+ height: auto;
537
+ }
538
+
539
+ :deep(.input--focused) {
540
+ border-bottom: 1px solid var(--sl-color-primary-500) !important;
541
+ }
542
+
543
+ &::part(input) {
544
+ color: var(--sl-color-primary-500);
545
+ font-weight: 300;
546
+ text-transform: uppercase;
547
+ font-size: 1.85em;
548
+ padding: 0.1em 0;
549
+ height: auto;
550
+ }
551
+
552
+ &::part(suffix) {
553
+ pointer-events: none;
554
+ width: 1.5em;
555
+ margin-left: -1em;
556
+ font-size: 1.5em;
557
+ }
558
+
559
+ &:hover {
560
+ &::part(base) {
561
+ border-bottom: 1px solid var(--sl-color-primary-500);
562
+ }
563
+ }
564
+ }
565
+
566
+ .viur-shop-cart-descr {
567
+ margin-top: 10px;
568
+
569
+ &::part(base) {
570
+ background-color: transparent;
571
+ transition: all ease 0.3s;
572
+ border-bottom: 1px solid transparent;
573
+ margin-bottom: 0;
574
+ }
575
+
576
+ &::part(input) {
577
+ padding: 0.1em 0;
578
+ height: auto;
579
+ color: var(--ignt-color-text);
580
+ }
581
+
582
+ &::part(suffix) {
583
+ pointer-events: none;
584
+ width: 1.5em;
585
+ margin-left: -1em;
586
+ font-size: 1.5em;
587
+ }
588
+
589
+ &:hover {
590
+ &::part(base) {
591
+ border-bottom: 1px solid var(--ignt-color-text);
592
+ }
593
+ }
594
+ }
595
+
596
+ sl-menu-item {
597
+ &::part(base) {
598
+ padding: 0.2em 0.9em 0.2em 0.8em;
599
+ }
600
+
601
+ &::part(checked-icon) {
602
+ display: none;
603
+ }
604
+
605
+ &::part(prefix) {
606
+ margin-right: 10px;
607
+ }
608
+
609
+ &::part(suffix) {
610
+ margin-right: -1.5em;
611
+ }
612
+ }
613
+
614
+ .primary-icon {
615
+ color: var(--ignt-color-primary);
616
+ }
617
+
618
+ .delete-icon {
619
+ color: @warnColor;
620
+ }
621
+
622
+ .dots {
623
+ color: var(--ignt-color-primary);
624
+ width: 1.5em;
625
+ height: 100%;
626
+ font-size: 1em;
627
+ padding: 0.4em;
628
+ }
629
+
630
+ .viur-shop-cart-sidebar-info-line {
631
+ display: flex;
632
+ flex-direction: row;
633
+ flex-wrap: nowrap;
634
+ margin: var(--sl-spacing-2x-small) 0;
635
+
636
+ &.total {
637
+ font-weight: 600;
638
+ border-top: 1px solid var(--sl-color-neutral-300);
639
+ border-bottom: 1px solid var(--sl-color-neutral-300);
640
+ padding: var(--sl-spacing-x-small) 0;
641
+ margin: var(--sl-spacing-small) 0;
642
+ }
643
+
644
+ span {
645
+ margin-right: auto;
646
+ }
647
+ }
648
+
649
+ .viur-shop-cart-card {
650
+ margin-bottom: var(--sl-spacing-x-large);
651
+
652
+ &::part(header) {
653
+ border-bottom: none;
654
+ padding-top: 0;
655
+ padding-right: 0;
656
+ }
657
+
658
+ &::part(image) {
659
+ flex-basis: 25%;
660
+ max-width: 250px;
661
+ }
662
+
663
+ &::part(body) {
664
+ display: flex;
665
+ flex: 1;
666
+ padding-top: 0;
667
+ padding-bottom: 0;
668
+ padding-right: 0;
669
+ }
670
+
671
+ &::part(group) {
672
+ padding: var(--sl-spacing-small) 0;
673
+ }
674
+ }
675
+
676
+ .viur-shop-cart-card-body-row {
677
+ display: grid;
678
+ grid-template-columns: 1fr auto auto;
679
+ gap: var(--sl-spacing-large);
680
+ flex: 1;
681
+ }
682
+
683
+ .viur-shop-cart-card-body-info {
684
+ display: flex;
685
+ flex-direction: column;
686
+ height: 100%;
687
+ }
688
+
689
+ .viur-shop-cart-card-descr {
690
+ margin-bottom: auto;
691
+ }
692
+
693
+ .viur-shop-cart-card-body-footer {
694
+ display: flex;
695
+ flex-direction: row;
696
+ gap: var(--sl-spacing-2x-small);
697
+ margin-top: var(--sl-spacing-large);
698
+ }
699
+
700
+ .amount-input {
701
+ width: 5em;
702
+ }
703
+
704
+ .viur-shop-cart-card-price-wrap {
705
+ display: flex;
706
+ flex-direction: column;
707
+
708
+ .viur-shop-cart-card-small-print {
709
+ font-size: 0.75em;
710
+ margin-left: auto;
711
+ }
712
+ }
713
+
714
+ .viur-shop-cart-card-price {
715
+ font-size: 1.3em;
716
+ }
717
+
718
+ .viur-shop-cart-card-price-label {
719
+ color: var(--ignt-color-primary);
720
+ font-weight: 600;
721
+ margin-bottom: 10px;
722
+ font-size: 1em;
723
+ margin-left: auto;
724
+ }
725
+ </style>