150 lines
4.4 KiB
HTML
150 lines
4.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Lekcja 4</title>
|
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
|
<style>
|
|
* {
|
|
box-sizing: border-box;
|
|
font-family: monospace;
|
|
}
|
|
|
|
.progressbar {
|
|
background-color: darkgray;
|
|
width: 100%;
|
|
height: 1rem;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.progressbar-inside {
|
|
background-color: chartreuse;
|
|
height: 1rem;
|
|
}
|
|
|
|
.flex {
|
|
display: flex;
|
|
justify-content: flex-start;
|
|
}
|
|
|
|
.flex>div {
|
|
width: 33%;
|
|
margin-left: 0.33%;
|
|
background-color: darkgray;
|
|
padding: .5rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="app">
|
|
<h2>Koszyk krok po kroku: v-if, v-model, computed, checkbox, radio, range, select</h2>
|
|
|
|
<hr>
|
|
|
|
<div class="progressbar">
|
|
<div class="progressbar-inside" :style="{ width: (step * 34) + '%' }">
|
|
</div>
|
|
</div><br>
|
|
|
|
<div class="flex">
|
|
<div>
|
|
<h2>Krok 1: Wybierz sprzęt</h2>
|
|
<input type="checkbox" name="sprzet" id="s1" @change="s_change"><label for="s1">Myszka
|
|
bezprzewodowa</label><br>
|
|
<input type="checkbox" name="sprzet" id="s2" @change="s_change"><label for="s2">Laptop Dev
|
|
Edition</label><br>
|
|
<input type="checkbox" name="sprzet" id="s3" @change="s_change"><label for="s3">Stacja Robocza
|
|
PC</label><br>
|
|
|
|
<p>Liczba zestawów: {{ s_k }}</p>
|
|
<input type="range" name="zestawy" id="z1" min="1" max="10" v-model="s_k">
|
|
</div>
|
|
<div v-if="step > 0">
|
|
<h2>Krok 2: Forma odbioru</h2>
|
|
<select v-model="delivery" @change="d_change">
|
|
<option value="">-- wybierz dostawę --</option>
|
|
<option>Kurier</option>
|
|
<option>Poczta</option>
|
|
<option>Osobiście</option>
|
|
</select>
|
|
<p>Sposób dostawy: {{ delivery }}</p>
|
|
</div>
|
|
<div v-if="step > 1">
|
|
<h2>Krok 3: Podsumowanie i zgoda</h2>
|
|
<input type="checkbox" name="agreement" v-model="agreement" id="agreement"
|
|
@change="agreement_change"><label for="agreement">Potwierdzam zgodność danych</label>
|
|
<p>Ilość: {{ s_k }} zestawów</p>
|
|
<p>Status: {{ status_msg() }}</p>
|
|
<button :disabled="!agreement" @click="order">Zamów zestaw</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
|
|
<script>
|
|
const app = Vue.createApp({
|
|
data() {
|
|
return {
|
|
step: 0,
|
|
|
|
s_k: 1,
|
|
s_checked: 0,
|
|
|
|
delivery: '',
|
|
agreement: false
|
|
}
|
|
},
|
|
methods: {
|
|
s_change(e) {
|
|
if (e.target.checked) {
|
|
this.s_checked += 1;
|
|
} else {
|
|
this.s_checked -= 1;
|
|
}
|
|
|
|
if (this.s_checked > 0) {
|
|
if (this.step < 2) {
|
|
this.step = 1;
|
|
this.d_change();
|
|
}
|
|
} else {
|
|
this.step = 0;
|
|
}
|
|
},
|
|
d_change() {
|
|
if (this.delivery != '') {
|
|
this.step = 2;
|
|
if (this.agreement) {
|
|
this.step = 3;
|
|
}
|
|
} else {
|
|
this.step = 1;
|
|
}
|
|
},
|
|
agreement_change(e) {
|
|
this.agreement = e.target.checked;
|
|
if (this.agreement) {
|
|
this.step = 3;
|
|
} else {
|
|
this.step = 2;
|
|
}
|
|
},
|
|
status_msg() {
|
|
if (this.agreement) {
|
|
return 'Gotowe do wysłania!';
|
|
} else {
|
|
return 'Zaznacz zgodę';
|
|
}
|
|
},
|
|
order() {
|
|
alert(`Zamówienie przyjęte!\nIlość: ${this.s_k} zestawów\nDostawa: ${this.delivery}`);
|
|
}
|
|
}
|
|
}).mount("#app");
|
|
|
|
</script>
|
|
|
|
</html> |