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

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