-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex2.html
More file actions
207 lines (201 loc) · 8.38 KB
/
Copy pathindex2.html
File metadata and controls
207 lines (201 loc) · 8.38 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Menú Restaurante</title>
<link rel="stylesheet" href="./src/index.css">
<link rel="stylesheet" href="./src/index2.css">
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div class="contain">
<header>
<div>
<button onClick="location.href='./index.html'" class="return"><img src="./img/flechita.png" alt="return"></button>
</div>
<div>
<h3>My Cart</h3>
</div>
</header>
<main>
<div id="pushList" class="elementosMenu2"></div>
</main>
<footer class="desglosePrecio">
<div class="precio">
<div class="columnaTexto">
<p>Subtotal</p>
<p>Tasas</p>
<p>Delivery</p>
<p>TOTAL</p>
</div>
<div id="price"></div>
</div>
<button class="boton2" onclick="window.location.href='https://www.paypal.com/signin?returnUri=https%3A%2F%2Fwww.paypal.com%2Fmyaccount%2Fmoney&state=%2F'">Enviar pedido</button>
</footer>
</div>
<script src="./src/listaplatos.js"></script>
<script type="text/babel">
class TotalSuma extends React.Component {
constructor(props){
super(props)
this.state = {
subtotal: 0,
tasas: 0.10
}
}
render(){
let array = []
Object.keys(localStorage).map((plate , element) =>{
return (
element = (listaPlatos[plate].precioPlato * localStorage.getItem(plate)),
this.state.subtotal = element,
array.push(element)
)
})
let total = 0
for (let i =0; i < array.length; i++){
total += array[i]
}
return (
<div className="columnaPrecio">
<p id="subtotal">{total}€</p>
<p id="tasas">{(total * this.state.tasas).toPrecision(2)}€</p>
<p id="delivery">FREE</p>
<p id="total">{total + (total * this.state.tasas)}€</p>
</div>
)
}
}
class TotalResta extends React.Component {
constructor(props){
super(props)
this.state = {
subtotal: 0,
tasas: 0.10
}
}
render(){
let array = []
Object.keys(localStorage).map((plate , element) =>{
return (
element = (listaPlatos[plate].precioPlato * localStorage.getItem(plate)),
this.state.subtotal = element,
array.push(element)
)
})
let total = 0
for (let i =0; i < array.length; i++){
total += array[i]
}
return (
<div className="columnaPrecio">
<p id="subtotal">{total}€</p>
<p id="tasas">{(total * this.state.tasas).toPrecision(2)}€</p>
<p id="delivery">FREE</p>
<p id="total">{total + (total * this.state.tasas)}€</p>
</div>
)
}
}
</script>
<script type="text/babel">
class Price extends React.Component {
constructor(props){
super(props)
this.state = {
subtotal: 0,
tasas: 0.10
}
}
render(){
Object.keys(localStorage).map((plate, id)=> {
return (
this.state.subtotal += listaPlatos[plate].precioPlato * localStorage.getItem(plate)
)
})
return (
<div className="columnaPrecio">
<p id="subtotal">{this.state.subtotal}€</p>
<p id="tasas">{(this.state.subtotal * this.state.tasas).toPrecision(2)}€</p>
<p id="delivery">FREE</p>
<p id="total">{this.state.subtotal + (this.state.subtotal * this.state.tasas)}€</p>
</div>
)
}
}
ReactDOM.render( <Price />, document.getElementById("price"));
</script>
<script type="text/babel">
class Contador extends React.Component {
constructor(props){
super(props)
this.state = {
counter: JSON.parse(localStorage.getItem(this.props.index))
}
}
resta = () => {
ReactDOM.render( <TotalResta />, document.getElementById("price"));
localStorage.setItem(this.props.index, this.state.counter - 1)
if (localStorage.getItem(this.props.index) >= 0 && this.state.counter >= 1){
this.setState((state) => {
return {counter: this.state.counter - 1}
})}
if (this.state.counter === 1){
localStorage.removeItem(this.props.index)
ReactDOM.render( <Items />, document.getElementById("pushList"));
ReactDOM.render( <TotalResta />, document.getElementById("price"));
}
}
suma = () => {
ReactDOM.render( <TotalSuma />, document.getElementById("price"));
localStorage.setItem(this.props.index, this.state.counter + 1)
this.setState((state) => {
return {counter: state.counter + 1}
})
}
render(){
return (
<div className="contador" data-numero={this.props.index}>
<button onClick={this.resta} className="resta">-</button>
<p className="quantity">{localStorage.getItem(this.props.index)}</p>
<button onClick={this.suma} className="suma">+</button>
</div>
)
}
}
</script>
<script type="text/babel">
class ItemsPush extends React.Component {
x = () => {
localStorage.removeItem(this.props.index)
ReactDOM.render( <Items />, document.getElementById("pushList"));
ReactDOM.render( <TotalResta />, document.getElementById("price"));
}
render (){
return (
<div className="elemento">
<img src={listaPlatos[this.props.index].imgPLato}/>
<div className="texto ">
<p>{listaPlatos[this.props.index].precioPlato}€</p>
<h5>{listaPlatos[this.props.index].nombrePlato}</h5>
<h6>{listaPlatos[this.props.index].descripcionPlato}</h6>
</div>
<Contador index={listaPlatos[this.props.index].id} counter={this.props.number}/>
<button className="botonEliminar" onClick={this.x}>x</button>
</div>
)}}
class Items extends React.Component {
render() {
const array = Object.keys(localStorage)
return (<div className="list">{array.map((value, index) => {
return <ItemsPush index={value} key={index} number={localStorage.getItem(value)}/>
})}</div>)
}
}
ReactDOM.render( <Items />, document.getElementById("pushList"));
</script>
</body>
</html>