-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (74 loc) · 2.42 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/vue"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Simple table</title>
</head>
<body>
<h2 style="text-align:center;">Simple table for TR Logic LLC</h2>
<div class="panel-body" id="app">
<table style="margin:0 auto; width: 600px;"class="table table-hover table-bordered">
<thead align="left">
<th>Наименование</th>
<th>Количество</th>
<th>Цена</th>
<th></th>
</thead>
<tbody>
<tr v-for="(item, index) in items">
<td><input class="form-control" v-model.number="item.name" size="25"></td>
<td><input class="form-control" v-model.number="item.qty" size="1"></td>
<td><input class="form-control" v-model.number="item.price" size="3"></td>
<td>
<button class="btn btn-primary btn-xs" @click="addRow(index)">Добавить</button>
<button class="btn btn-danger btn-xs" @click="removeRow(index)">Удалить</button>
</td>
</tr>
<tr>
<td class="table-total"><strong>Итог</strong></td>
<td></td>
<td><strong>{{total}}</strong></td>
</tr>
</tbody>
</table>
</div>
<script>
var app = new Vue({
el: '#app',
data: {
// Начальные значения
items: [
{name: "Товар 1", qty: 12, price: 97 },
{name: "Товар 2", qty: 5, price: 44 },
{name: "Товар 3", qty: 11, price: 11 },
{name: "Товар 4", qty: 2, price: 31 }
],
},
computed: {
// Итог
total() {
return this.items.reduce((total, item) => {
return total + item.qty * item.price;
}, 0);
}
},
methods: {
// Добавление ряда
addRow(index) {
this.items.splice(index + 1, 0, {
qty: 1, price: 0
});
},
// Удаление ряда
removeRow(index) {
this.items.splice(index, 1);
}
}
});
</script>
</body>
</html>