-
Notifications
You must be signed in to change notification settings - Fork 41
/
createProductJson.html
216 lines (199 loc) · 5.55 KB
/
createProductJson.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
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
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Product code</title>
<!-- Load font awesome icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"
crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" type="text/css" href="css/home_products.css">
<script src="data/products.js"></script>
<script src="js/classes.js"></script>
<script src="js/dungchung.js"></script>
<style>
* {
outline: none;
font-family: sans-serif;
}
table {
padding: 5px 3px;
border : 1px solid #333;
margin: 10px auto;
}
td {
padding: 5px 3px;
border-bottom: 1pt solid #333;
}
input {
padding: 5px 3px;
height: 26px;
font-size: 20px;
}
button {
border-radius: 10px;
margin: 10px auto;
font-size: 20px;
padding: 10px 5px;
border: none;
cursor: pointer;
background: #487;
}
button:hover {
background: #4a7;
}
textarea {
padding: 5px 3px;
font-size: 16px;
}
.homeproduct li {
width: 250px;
}
</style>
<script>
// Thêm sản phẩm vào trang
function addProduct(p, id) {
promo = new Promo(p.promo.name, p.promo.value); // class Promo
product = new Product(p.img, p.name, p.price, p.star, p.rateCount, promo); // Class product
addToWeb(product, id);
}
function getResult() {
var name = document.getElementById('name').value;
var company = document.getElementById('company').value;
var img = document.getElementById('img').value;
var price = document.getElementById('price').value;
var star = document.getElementById('star').value || 0;
var rateCount = document.getElementById('rateCount').value || 0;
var promoName = document.getElementById('promoName').value;
var promoValue = document.getElementById('promoValue').value;
if(img.indexOf('http') < 0) {
img = "img/products/"+ img;
}
return {
"name": name,
"company": company,
"img": img,
"price": price,
"star": star,
"rateCount": rateCount,
"promo": {
"name": promoName,
"value": promoValue
}
};
}
function saveToDatabase() {
var r = getResult();
if(!r.name || !r.price) {
alert('Chưa nhập tên hoặc giá tiền');
return;
}
addProduct(r, 'products');
var textarea = document.getElementById('t_a');
if(textarea.innerHTML == '')
textarea.innerHTML += JSON.stringify(r, null, "\t");
else textarea.innerHTML += ',\n'+JSON.stringify(r, null, "\t");
}
function valueChange() {
document.getElementById('live').innerHTML = '';
addProduct(getResult(), 'live');
}
window.onload = function() {
var inp = document.getElementsByTagName('input');
for(var i = 0; i < inp.length; i++) {
inp[i].onkeyup = valueChange;
}
document.getElementById('company').onchange = valueChange;
}
</script>
</head>
<body>
<table>
<tr>
<td>
<table cellpadding="7">
<tr>
<td>Tên sản phẩm:</td>
<td><input id="name" type="text" onchange=""></td>
</tr>
<tr>
<td>Tên Hãng:</td>
<td>
<select name="" id="company">
<option value="Apple">Apple</option>
<option value="Samsung">Samsung</option>
<option value="Oppo">Oppo</option>
<option value="Nokia">Nokia</option>
<option value="Huawei">Huawei</option>
<option value="Xiaomi">Xiaomi</option>
<option value="Realme">Realme</option>
<option value="Vivo">Vivo</option>
<option value="Philips">Philips</option>
<option value="Mobell">Mobell</option>
<option value="Mobiistar">Mobiistar</option>
<option value="Itel">Itel</option>
<option value="Coolpad">Coolpad</option>
<option value="HTC">HTC</option>
<option value="Motorola">Motorola</option>
</select>
</td>
</tr>
<tr>
<td>Tên file ảnh</td>
<td><input id="img" type="text"></td>
</tr>
<tr>
<td>Giá tiền:</td>
<td><input id="price" type="text"></td>
</tr>
<tr>
<td>Đánh giá (mấy sao):</td>
<td><input id="star" type="text"></td>
</tr>
<tr>
<td>Số lượt đánh giá:</td>
<td><input id="rateCount" type="text"></td>
</tr>
<tr>
<td>Khuyến mãi:</td>
<td>
<select name="km" id="promoName" onchange="valueChange()">
<option value="">Không khuyến mãi</option>
<option value="tragop">Trả góp</option>
<option value="giamgia">Giảm giá</option>
<option value="moiramat">Mới ra mắt</option>
<option value="giareonline">Giá rẻ online</option>
</select>
</td>
</tr>
<tr>
<td>Giá trị khuyến mãi:</td>
<td><input id="promoValue" type="text"></td>
</tr>
</table>
</td>
<td>
<ul class="homeproduct group flexContain" id="live"></ul>
</td>
</tr>
<tr>
<td colspan="2">
<button onclick="saveToDatabase()">Lưu vào database</button>
</td>
</tr>
<tr>
<td colspan="2">
<ul class="homeproduct" id="products"></ul>
</td>
</tr>
<tr>
<td colspan="2">
<p>Kết quả Database:</p>
<textarea rows="13" cols="70" id="t_a"></textarea>
</td>
</tr>
</table>
</body>
</html>