-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.html
More file actions
353 lines (302 loc) · 13.4 KB
/
Order.html
File metadata and controls
353 lines (302 loc) · 13.4 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Main Page</title>
<style>
/* 추가된 스타일: 스크롤을 위한 스타일 */
#saved-details {
max-height: 300px;
overflow-y: auto;
}
</style>
<link rel="stylesheet" href="Style.css">
</head>
<body>
<header>
<h1>Make Your Beauty</h1>
<div class="button-container">
<a href="AIPage.html" class="navigation-button">AI Recommend</a>
<a href="Order.html" class="navigation-button">Order</a>
<a href="shareThings.html" class="navigation-button">Community</a>
<a href="mypage.html" class="navigation-button">MyPage</a>
</div>
</header>
<section class="main-container ">
<div class="main-section">
<label for="cosmetic-type"><img src="images/Lipstick.png" width="20">화장품 종류 선택:</label>
<select id="cosmetic-type">
<option value="skin">피부</option>
<option value="lip">립</option>
<option value="blusher">블러셔</option>
<option value="eyebrow">아이브로우</option>
<option value="eyeliner">아이라이너</option>
</select>
<button id="select-button" >선택</button>
</div>
<div class="main-section">
<div id="skin-options" style="display: none;">
<h2>피부 종류 선택:</h2>
<label for="skin-color">색깔:</label>
<select id="skin-color">
<option value="pink">핑크</option>
<option value="neutral">뉴트럴</option>
<option value="yellow">옐로우</option>
</select>
<label for="brightness">명도:</label>
<select id="brightness">
<option value="13">13</option>
<option value="17">17</option>
<option value="19">19</option>
<option value="21">21</option>
<option value="23">23</option>
</select>
<label for="texture">텍스처:</label>
<select id="texture">
<option value="matte">매트</option>
<option value="semi-matte">세미 매트</option>
<option value="glow">글로우</option>
</select>
<button id="skin-select-button">선택 완료</button>
</div>
<div id="lip-options" style="display: none;">
<h2>립 종류 선택:</h2>
<label for="lip-color">색깔:</label>
<select id="lip-color">
<option value="pink">핑크</option>
<option value="red">레드</option>
<option value="orange">오렌지</option>
<option value="coral">코랄</option>
</select>
<label for="lip-texture">텍스처:</label>
<select id="lip-texture">
<option value="glow">글로우</option>
<option value="matte">매트</option>
</select>
<label for="pigmentation">착색력:</label>
<select id="pigmentation">
<option value="strong">강</option>
<option value="medium">중</option>
<option value="weak">약</option>
</select>
<label for="spreadability">발림성:</label>
<select id="spreadability">
<option value="watery">워터리</option>
<option value="oily">오일리</option>
<option value="solid">고체형</option>
</select>
<button id="lip-select-button">선택 완료</button>
</div>
<div id="blusher-options" style="display: none;">
<h2>블러셔 종류 선택:</h2>
<label for="blusher-color">색깔:</label>
<select id="blusher-color">
<option value="pink">핑크</option>
<option value="coral">코랄</option>
<option value="orange">오랜지</option>
<option value="lavender">라벤더</option>
<option value="red">레드</option>
</select>
<label for="blusher-texture">텍스처:</label>
<select id="blusher-texture">
<option value="solid">고체형</option>
<option value="liquid">액체형</option>
<option value="powder">가루형</option>
</select>
<button id="blusher-select-button">선택 완료</button>
</div>
<div id="eyebrow-options" style="display: none;">
<h2>아이브로우 종류 선택:</h2>
<label for="eyebrow-color">색깔:</label>
<select id="eyebrow-color">
<option value="black">블랙</option>
<option value="ash">애쉬</option>
<option value="chocolate-brown">초코브라운</option>
<option value="dark-brown">다크브라운</option>
<option value="light-brown">라이트 브라운</option>
<option value="blonde">블론드</option>
</select>
<label for="eyebrow-tool">툴:</label>
<select id="eyebrow-tool">
<option value="stick">스틱</option>
<option value="screw-brow">스크류 브로우</option>
</select>
<button id="eyebrow-select-button">선택 완료</button>
</div>
<div id="eyeliner-options" style="display: none;">
<h2>아이라이너 종류 선택:</h2>
<label for="eyeliner-color">색깔:</label>
<select id="eyeliner-color">
<option value="black">블랙</option>
<option value="dark-brown">다크 브라운</option>
<option value="chocolate-brown">초코 브라운</option>
<option value="light-brown">라이트 브라운</option>
</select>
<label for="eyeliner-tool">툴:</label>
<select id="eyeliner-tool">
<option value="pencil">펜슬</option>
<option value="brush-pen">붓펜</option>
<option value="gel">젤</option>
</select>
<button id="eyeliner-select-button">선택 완료</button>
</div>
</div>
<div class="main-section">
<div id="selected-details" style="display: none;">
<h2>수량 선택</h2>
<ul id="details-list"></ul>
<label for="quantity">개수:</label>
<input type="number" id="quantity" placeholder="개수를 입력하세요">
<button id="save-button">저장</button>
</div>
</div>
<div class="main-section">
<div id="saved-details">
<h2>장바구니</h2>
<ul id="saved-details-list"></ul>
<br>
<br>
<br>
<br>
<br>
</div>
<a href="#" class="checkout-button" id="checkout-button">주문 하기</a>
</div>
</section>
<script>
const cosmeticTypeDropdown = document.getElementById("cosmetic-type");
const selectButton = document.getElementById("select-button");
const selectedDetailsDiv = document.getElementById("selected-details");
const detailsList = document.getElementById("details-list");
const dynamicOptionsContainer = document.getElementById("dynamic-options-container");
const checkoutButton = document.getElementById("checkout-button");
const mypageButton = document.getElementById("mypage-button");
const cosmeticTypes = ["skin", "lip", "blusher", "eyebrow", "eyeliner"];
selectButton.addEventListener("click", function () {
const selectedType = cosmeticTypeDropdown.value;
displayOptions(selectedType);
});
checkoutButton.addEventListener("click", function () {
const isConfirmed = confirm("주문을 확인하시겠습니까?");
if (isConfirmed) {
moveSessionDataToLocalStorage();
// 장바구니 비우기
clearSessionData();
window.location.href = "mypage.html";
} else {
// 사용자가 확인을 취소한 경우
alert("주문이 취소되었습니다.");
}
});
function displayOptions(selectedType) {
// 세부 정보 목록 초기화
detailsList.innerHTML = "";
// 선택된 화장품 유형 옵션 div 가져오기
const selectedOptionsDiv = document.getElementById(`${selectedType}-options`);
// 동적으로 생성된 옵션들을 표시
cosmeticTypes.forEach(type => {
const optionsDiv = document.getElementById(`${type}-options`);
if (type === selectedType) {
optionsDiv.style.display = "block";
} else {
optionsDiv.style.display = "none";
}
});
// 해당 "선택" 버튼에 이벤트 리스너 추가
const selectButton = document.getElementById(`${selectedType}-select-button`);
selectButton.addEventListener("click", function () {
// 선택된 화장품 유형에 기반하여 값 동적으로 가져오기
const optionValues = getOptionValues(selectedType);
displaySelectedDetails(selectedType, ...optionValues);
});
}
function getOptionValues(selectedType) {
const optionValues = [];
const options = document.querySelectorAll(`#${selectedType}-options select`);
options.forEach(option => {
optionValues.push(option.value);
});
return optionValues;
}
function displaySelectedDetails(type, ...options) {
selectedDetailsDiv.style.display = "block";
const listItem = document.createElement("li");
listItem.textContent = `${type} - ${options.join(", ")} `;
detailsList.appendChild(listItem);
}
const saveButton = document.getElementById("save-button");
saveButton.addEventListener("click", function () {
const selectedType = cosmeticTypeDropdown.value;
const optionValues = getOptionValues(selectedType);
const quantity = document.getElementById("quantity").value;
const date = new Date();
saveSelectedDetails(selectedType, optionValues, quantity, date);
displaySavedDetails();
});
function saveSelectedDetails(type, options, quantity, date) {
// 세션 스토리지에서 저장된 데이터 불러오기
const savedDetails = JSON.parse(sessionStorage.getItem("savedDetails")) || {};
// 같은 화장품에 대한 세부 정보가 이미 있다면 배열에 추가
if (savedDetails[type]) {
savedDetails[type].push({ options, quantity, date });
} else {
// 없다면 새로운 배열로 저장
savedDetails[type] = [{ options, quantity,date }];
}
// 세션 스토리지에 저장
sessionStorage.setItem("savedDetails", JSON.stringify(savedDetails));
}
function createDeleteButton(type, options) {
const deleteButton = document.createElement("button");
deleteButton.textContent = "삭제";
deleteButton.addEventListener("click", function () {
deleteSavedDetails(type, options);
displaySavedDetails();
});
return deleteButton;
}
function deleteSavedDetails(type, options) {
// 로컬 스토리지에서 해당 세부 정보 삭제
const savedDetails = JSON.parse(sessionStorage.getItem("savedDetails")) || {};
delete savedDetails[type];
sessionStorage.setItem("savedDetails", JSON.stringify(savedDetails));
}
function displaySavedDetails() {
const savedDetailsList = document.getElementById("saved-details-list");
savedDetailsList.innerHTML = ""; // 기존 목록 초기화
// 세션 스토리지에서 저장된 데이터 불러오기
const savedDetails = JSON.parse(sessionStorage.getItem("savedDetails")) || {};
// 저장된 세부 정보를 화면에 표시
for (const type in savedDetails) {
const detailsArray = savedDetails[type];
// 리스트에 저장된 개수만큼 아이템 생성
detailsArray.forEach(item => {
const listItem = document.createElement("li");
listItem.textContent = `${type} - ${item.options.join(", ")} - 개수: ${item.quantity}`;
listItem.appendChild(createDeleteButton(type, item.options));
savedDetailsList.appendChild(listItem);
});
}
}
function getSelectedQuantity() {
return document.getElementById("quantity").value;
}
function moveSessionDataToLocalStorage() {
// 세션 스토리지의 값들을 로컬 스토리지에 저장하는 코드
const savedDetails = JSON.parse(sessionStorage.getItem("savedDetails")) || {};
const orderHistory = JSON.parse(localStorage.getItem("orderHistory")) || [];
// 주문 내역에 추가
orderHistory.push(savedDetails);
// 로컬 스토리지에 저장
localStorage.setItem("orderHistory", JSON.stringify(orderHistory));
}
function clearSessionData() {
// 세션 스토리지 비우기
sessionStorage.removeItem("savedDetails");
}
// 페이지 로드시 저장된 세부 정보 표시
displaySavedDetails();
</script>
</body>
</html>