-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshop.html
More file actions
444 lines (406 loc) · 15.8 KB
/
shop.html
File metadata and controls
444 lines (406 loc) · 15.8 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE html>
<html lang="en">
<head>
<title>Developer's community - Develonity</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Mukta:300,400,700"
/>
<link rel="stylesheet" href="fonts/icomoon/style.css" />
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/magnific-popup.css" />
<link rel="stylesheet" href="css/jquery-ui.css" />
<link rel="stylesheet" href="css/owl.carousel.min.css" />
<link rel="stylesheet" href="css/owl.theme.default.min.css" />
<link rel="stylesheet" href="css/aos.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/paging.css" />
</head>
<body>
<div class="site-wrap">
<header class="site-navbar" role="banner">
<div class="site-navbar-top">
<div class="container">
<div class="row align-items-center">
<div
class="col-6 col-md-4 order-2 order-md-1 site-search-icon text-left"
>
<form action="" class="site-block-top-search"></form>
</div>
<div
class="col-12 mb-3 mb-md-0 col-md-4 order-1 order-md-2 text-center"
>
<div class="site-logo">
<a href="index.html" class="js-logo-clone">Develonity</a>
</div>
</div>
<div class="col-6 col-md-4 order-3 order-md-3 text-right">
<div class="site-top-icons">
<ul>
<li id="logoutPlace"></li>
<li id="loginedPerson">
<a href="signUp.html" class="icon icon-person"> </a>
</li>
<li>
<a href="#" class="icon icon-heart-o"></a>
</li>
<li>
<a href="orderList.html" class="site-cart">
<span class="icon icon-shopping_cart"></span>
</a>
</li>
<li class="d-inline-block d-md-none ml-md-0">
<a href="#" class="site-menu-toggle js-menu-toggle"
><span class="icon-menu"></span
></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<nav
class="site-navigation text-right text-md-center"
role="navigation"
>
<div class="container">
<ul class="site-menu js-clone-nav d-none d-md-block">
<li><a href="index.html">Home</a></li>
<li><a onclick="community()">Community</a></li>
<li><a href="QnA.html">Q&A</a></li>
<li><a href="shop.html">GiftCard Shop</a></li>
</ul>
</div>
</nav>
</header>
<div class="bg-light py-3">
<div class="container">
<div class="row">
<div class="col-md-12 mb-0">
<a href="index.html">Home</a> <span class="mx-2 mb-0">/</span>
<strong class="text-black">GiftCard Shop</strong>
</div>
</div>
</div>
</div>
<div class="site-section" id="please">
<div class="container">
<div class="row mb-5">
<div class="col-md-9 order-2">
<div class="row" id="categoryAndSort">
<div class="col-md-12 mb-5">
<div class="float-md-left mb-4">
<h2 class="text-black h5" id="categoryName"></h2>
</div>
<div id="sortBox">
<div class="pagination" style="float: right">
정렬:
<select id="sorting" onchange="giftCardListing()">
<option value="name">상품명</option>
<option value="price">가격</option>
</select>
<input
type="radio"
name="isAsc"
value="true"
onchange="giftCardListing()"
checked
/>
오름차순
<input
type="radio"
name="isAsc"
value="false"
onchange="giftCardListing()"
/>
내림차순
</div>
<div id="pagination" class="pagination"></div>
</div>
</div>
</div>
<div class="row mb-5" id="gift-cards-box"></div>
<div class="row" data-aos="fade-up">
<div class="col-md-12 text-center">
<div class="site-block-27">
<ul id="pages">
<!-- <li><a href="#"><</a></li>
<li class="active"><span>1</span></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li><a href="#">></a></li> -->
</ul>
</div>
</div>
</div>
</div>
<div class="col-md-3 order-1 mb-5 mb-md-0">
<div class="border p-4 rounded mb-4">
<h3 class="mb-3 h6 text-uppercase text-black d-block">
Categories
</h3>
<ul class="list-unstyled mb-0">
<li
class="mb-1"
onclick="getGiftCardList(this)"
class="d-flex"
style="cursor: pointer; color: #7971ea"
>
<span id="AllCategory">All</span>
<span class="text-black ml-auto"></span>
</li>
<li
class="mb-1"
onclick="getGiftCardList(this)"
class="d-flex"
style="cursor: pointer; color: #7971ea"
>
<span id="CafeCategory">Cafe</span>
<span class="text-black ml-auto"></span>
</li>
<li
class="mb-1"
onclick="getGiftCardList(this)"
class="d-flex"
style="cursor: pointer; color: #7971ea"
>
<span id="ChickenCategory">Chicken</span>
<span class="text-black ml-auto"></span>
</li>
<li
class="mb-1"
onclick="getGiftCardList(this)"
class="d-flex"
style="cursor: pointer; color: #7971ea"
>
<span id="ConvenienceCategory">Convenience Store</span>
<span class="text-black ml-auto"></span>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/aos.js"></script>
<script src="js/main.js"></script>
<script>
$(document).ready(function () {
giftCardListing();
});
let TOTAL_ELEMENTS = 0; // 데이터 총 개수
const SIZE = 6; // 화면에 출력 개수
let TOTAL_PAGES = 0; // 총 페이지
const VIEW_SECTION = 5; // 페이지 버튼 출력 개수
let TOTAL_SECTION = Math.ceil(TOTAL_PAGES / VIEW_SECTION); // 총 구역 수
var page = 1; // 페이지가 1부터 시작할 때
let currentPage;
function giftCardListing() {
let sorting = $("#sorting option:selected").val();
let isAsc = $(':radio[name="isAsc"]:checked').val();
let category = localStorage.getItem("categoryName");
let currentPage = localStorage.getItem("currentPage");
if (currentPage == null) {
currentPage = 1;
}
if (!category) {
localStorage.setItem("categoryName", "ALL");
getItems("ALL", page, sorting, isAsc);
} else {
getItems(category, currentPage, sorting, isAsc);
}
}
// 상품가져오는 API 호출하는 함수
function getItems(category, currentPage, sorting, isAsc) {
var settings = {
url: `http://52.79.252.88:8080/api/gift-cards/category?category=${category}¤tPage=${currentPage}&size=6&sortBy=${sorting}&ascOrDesc=${isAsc}`,
method: "GET",
timeout: 3000,
};
$.ajax(settings)
.done(function (response) {
$("#gift-cards-box").empty();
console.log(response);
let rows = response["content"];
for (let i = 0; i < rows.length; i++) {
let name = rows[i]["name"];
let details = rows[i]["details"];
let imageUrl = rows[i]["imagePath"];
let price = rows[i]["price"];
let id = rows[i]["id"];
let temp_html = `<div class="col-sm-6 col-lg-4 mb-4" data-aos="fade-up">
<div class="block-4 text-center border">
<figure class="block-4-image">
<a href="shop-single.html" onclick="setGiftCard(${id})"><img src="${imageUrl}" alt="Image" class="img-fluid"></a>
</figure>
<div class="block-4-text p-4">
<h3><a href="shop-single.html" onclick="setGiftCard(${id})">${name}</a></h3>
<p class="mb-0">${details}</p>
<p class="text-primary font-weight-bold">${price}원</p>
<button type="button" class="btn btn-secondary" onclick="directOrder(${id})">구매하기</button>
</div>
</div>
</div>`;
$("#gift-cards-box").append(temp_html);
}
TOTAL_PAGES = response["totalPages"];
TOTAL_ELEMENTS = response["totalElements"];
localStorage.setItem("currentPage", currentPage);
paging(TOTAL_ELEMENTS, currentPage);
})
.fail(function (response) {
console.log(response);
alert(response["responseJSON"].message);
});
}
function setCurrentPage(num, element) {
return () => {
localStorage.setItem("currentPage", num);
console.log(element);
giftCardListing();
};
}
function paging(totalElements, currentPage) {
const dataPerPage = 6; // 페이지 당 보여줄 데이터 개수
const pageCount = 5; // 한번에 보여줄 페이지 번호 개수
currentPage = localStorage.getItem("currentPage");
let totalPage = Math.ceil(totalElements / dataPerPage); // 총 페이지 수
let pageGroup = Math.ceil(currentPage / pageCount); // 페이지 그룹
let last = pageGroup * pageCount; // 화면에 보여질 마지막 페이지 번호
if (last > totalPage) {
last = totalPage;
}
let first = last - (pageCount - 1); // 화면에 보여질 첫번째 페이지 번호
const next = last + 1;
const prev = first - 1;
if (totalPage < 1) {
first = last;
}
const pages = $("#pages");
pages.empty();
if (last > 5) {
const pageLi = document.createElement("li");
const pageA = document.createElement("a");
pageA.onclick = setCurrentPage(Number(currentPage) - 1, pageLi);
pageA.text = "<";
pageLi.appendChild(pageA);
pages.append(pageLi);
}
for (let j = first; j <= last; j++) {
if (currentPage == j) {
const pageLi = document.createElement("li");
pageLi.className = "active";
const pageA = document.createElement("a");
pageA.onclick = setCurrentPage(j, pageLi);
pageA.text = j;
pageLi.appendChild(pageA);
pages.append(pageLi);
} else if (j > 0) {
const pageLi = document.createElement("li");
const pageA = document.createElement("a");
pageA.onclick = setCurrentPage(j, pageLi);
pageA.text = j;
pageLi.appendChild(pageA);
pages.append(pageLi);
}
}
if (next > 5 && next <= totalPage) {
const pageLi = document.createElement("li");
const pageA = document.createElement("a");
pageA.onclick = setCurrentPage(Number(currentPage) + 1, pageLi);
pageA.text = ">";
pageLi.appendChild(pageA);
pages.append(pageLi);
}
}
function getGiftCardList(element) {
$("#pages").empty();
localStorage.setItem("currentPage", 1);
var categoryName = element.children[0].getAttribute("id");
var category;
if (categoryName === "AllCategory") {
category = "ALL";
} else if (categoryName === "CafeCategory") {
category = "CAFE";
} else if (categoryName === "ChickenCategory") {
category = "CHICKEN";
} else if (categoryName === "ConvenienceCategory") {
category = "CONVENIENCE_STORE";
}
localStorage.setItem("categoryName", category);
let sorting = $("#sorting option:selected").val();
let isAsc = $(':radio[name="isAsc"]:checked').val();
let currentPage = localStorage.getItem("currentPage");
getItems(category, currentPage, sorting, isAsc);
paging(TOTAL_ELEMENTS, currentPage);
}
function directOrder(id) {
localStorage.setItem("giftCardId", id);
window.location = "/order.html";
}
function setGiftCard(id) {
localStorage.setItem("giftCardId", id);
}
function community() {
alert(
"해당 기능은 시간관계상 프론트 구현을 하지 못하여 이용이 어렵습니다. 죄송합니다."
);
}
</script>
<script>
$(function () {
var settings = {
url: "http://52.79.252.88:8080/api/user/me/profile",
method: "GET",
timeout: 0,
headers: {
Authorization: localStorage.getItem("accessToken"),
},
};
$.ajax(settings)
.done(function (response) {
console.log(response);
$("#loginedPerson").empty();
$("#loginedPerson").append(
`<a href=myProfile.html class="icon icon-person"> </a>`
);
$("#logoutPlace").append(
`<button style="font-size: 12px; cursor: pointer" onclick="logout()">
로그아웃
</button>`
);
})
.fail(function (response) {
var settings2 = {
url: "http://52.79.252.88:8080/api/reissue",
method: "POST",
timeout: 0,
headers: {
Refresh: localStorage.getItem("refreshToken"),
},
};
$.ajax(settings2).done(function (response) {
localStorage.setItem("accessToken", response.accessToken);
localStorage.setItem("refreshToken", response.refreshToken);
location.reload(true);
});
});
});
</script>
</body>
</html>