This repository was archived by the owner on Jan 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
393 lines (370 loc) · 12.3 KB
/
index.html
File metadata and controls
393 lines (370 loc) · 12.3 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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no"
/>
<title>재고조사 웹앱</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: 'Noto Sans KR', sans-serif;
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
background-color: #fafafa;
color: #333;
}
.top-bar {
background: #ffffff;
padding: 1rem;
position: sticky;
top: 0;
z-index: 10;
border-bottom: 1px solid #ddd;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.top-bar input[type='text'] {
width: 100%;
padding: 0.75rem;
font-size: 1rem;
border: 1px solid #ccc;
border-radius: 8px;
}
.top-bar .actions {
margin-top: 0.5rem;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.top-bar .tabs {
display: flex;
gap: 0.5rem;
margin-top: 0.5rem;
}
.top-bar .tabs button {
flex: 1;
padding: 8px 12px;
background: #eee;
border: none;
border-radius: 6px;
cursor: pointer;
}
.top-bar .tabs button.active {
background: #333;
color: white;
}
.main {
flex: 1;
overflow-y: auto;
padding: 0.5rem;
}
.product-card {
touch-action: manipulation;
-webkit-tap-highlight-color: transparent;
background: #fff;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
margin-bottom: 0.5rem;
padding: 0.5rem;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
transition: background 0.3s ease;
}
.product-card.highlight {
background: #e6f7ff;
}
.product-card .delete-x {
font-size: 0.8rem;
padding: 2px 8px 2px 8px;
margin-left: 0.5rem;
color: #ffffff;
cursor: pointer;
}
.product-info {
position: relative;
flex: 1;
font-size: 0.9rem;
line-height: 1.5;
}
.product-controls {
display: flex;
flex-direction: column;
align-items: center;
}
.product-controls input {
width: 50px;
padding: 4px 6px;
text-align: center;
font-size: 1rem;
}
.product-controls .qty-buttons {
display: flex;
gap: 4px;
margin-top: 4px;
}
.product-controls button {
width: 34px;
padding: 6px 6px;
font-size: 1rem;
text-align: center;
}
button {
padding: 6px 6px;
font-size: 1rem;
border-radius: 6px;
border: none;
background: #333;
color: #fff;
cursor: pointer;
}
#totalCount {
font-weight: 600;
font-size: 1rem;
}
#toast {
position: fixed;
bottom: 40px;
left: 50%;
transform: translateX(-50%);
background: #333;
color: #fff;
padding: 10px 20px;
border-radius: 6px;
opacity: 0;
transition: opacity 0.3s ease;
z-index: 999;
}
</style>
</head>
<body>
<div class="top-bar">
<input
type="text"
id="barcodeInput"
placeholder="바코드를 입력하세요"
autofocus
/>
<div class="tabs">
<button class="active" onclick="showTab('scan')">재고조사 하기</button>
<button onclick="showTab('sku')">SKU별 재고 보기</button>
</div>
<div class="actions">
<div id="totalCount">총 수량: 0개</div>
<button onclick="finalizeInventory()">재고조사 완료</button>
</div>
</div>
<div class="main" id="productList"></div>
<div class="main" id="skuSummaryList" style="display: none"></div>
<div id="toast"></div>
<script>
const apiEndpoint = 'https://partnerhub.prd.external.theppbs.com/stocktake';
let inventory = [];
let latestIndex = -1;
document.addEventListener('touchend', function (e) {
const now = new Date().getTime();
if (now - (window._lastTouchEnd || 0) < 300) e.preventDefault();
window._lastTouchEnd = now;
}, false);
async function addToInventory(barcode) {
try {
const response = await fetch(`${apiEndpoint}/${barcode}`);
if (!response.ok) {
return alert('등록되지 않은 바코드입니다.');
}
const product = await response.json();
inventory.push({
barcode,
sku: product.sku || '',
brand: product.brand || '',
product_name: product.product_name || '',
quantity: 1,
});
latestIndex = inventory.length - 1;
renderInventoryList();
updateTotalCount();
setTimeout(
() =>
(document.querySelector('.main').scrollTop =
document.querySelector('.main').scrollHeight),
100
);
} catch (error) {
console.error('API 호출 오류:', error);
alert('상품 정보를 가져오는데 실패했습니다.');
}
}
function deleteItem(index) {
if (!confirm('정말 삭제할까요?')) return;
inventory.splice(index, 1);
renderInventoryList();
updateTotalCount();
showToast('삭제되었습니다.');
}
function showToast(msg) {
const toast = document.getElementById('toast');
toast.textContent = msg;
toast.style.opacity = 1;
setTimeout(() => (toast.style.opacity = 0), 2000);
}
function renderInventoryList() {
const list = document.getElementById('productList');
list.innerHTML = '';
inventory.forEach((item, idx) => {
const card = document.createElement('div');
card.className =
'product-card' + (idx === latestIndex ? ' highlight' : '');
card.innerHTML = `
<div class="product-info">
<strong>${item.brand}
<button class="delete-x" onclick="deleteItem(${idx})">삭제</button>
</strong><br />
${item.product_name}
</div>
<div class="product-controls">
<input type="number" value="${item.quantity}" onchange="updateQuantity(${idx}, this.value)" />
<div class="qty-buttons">
<button onclick="changeQty(${idx}, 1)">+</button>
<button onclick="changeQty(${idx}, -1)">−</button>
</div>
</div>
`;
list.appendChild(card);
});
}
function updateQuantity(index, value) {
inventory[index].quantity = Math.max(1, parseInt(value) || 1);
updateTotalCount();
}
function changeQty(index, delta) {
inventory[index].quantity = Math.max(
1,
inventory[index].quantity + delta
);
renderInventoryList();
updateTotalCount();
}
function updateTotalCount() {
const total = inventory.reduce((sum, item) => sum + item.quantity, 0);
document.getElementById(
'totalCount'
).textContent = `총 수량: ${total}개`;
}
function finalizeInventory() {
if (!inventory.length) return alert('조사된 항목이 없습니다.');
if (!confirm('저장할까요?')) return;
const storeName = prompt('매장명을 입력하세요');
if (!storeName) return;
const now = new Date();
const filename = `${storeName}_${now.toISOString().split('T')[0]}.csv`;
const skuMap = {};
inventory.forEach((item) => {
if (!skuMap[item.sku]) skuMap[item.sku] = { ...item };
else skuMap[item.sku].quantity += item.quantity;
});
// let csvContent =
// 'data:text/csv;charset=utf-8,barcode,sku,brand,product_name,quantity\n';
// Object.values(skuMap).forEach((item) => {
// csvContent += `${item.barcode},${item.sku},${item.brand},${item.product_name},${item.quantity}\n`;
// });
//
// const encodedUri = encodeURI(csvContent);
// const link = document.createElement('a');
// link.setAttribute('href', encodedUri);
// link.setAttribute('download', filename);
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
const esc = (v) => {
if (v === null || v === undefined) return '';
const s = String(v);
if (/[",\r\n]/.test(s)) return `"${s.replace(/"/g, '""')}"`;
return s;
};
let csv = '\uFEFF' + ['barcode','sku','brand','product_name','quantity'].join(',') + '\n';
Object.values(skuMap).forEach((item) => {
csv += [
esc(item.barcode),
esc(item.sku),
esc(item.brand),
esc(item.product_name),
esc(item.quantity),
].join(',') + '\n';
});
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = filename.endsWith('.csv') ? filename : `${filename}.csv`;
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
}
function showTab(tab) {
const btns = document.querySelectorAll('.tabs button');
btns.forEach((b) => b.classList.remove('active'));
if (tab === 'scan') {
document.getElementById('productList').style.display = 'block';
document.getElementById('skuSummaryList').style.display = 'none';
btns[0].classList.add('active');
} else {
renderSkuSummary();
document.getElementById('productList').style.display = 'none';
document.getElementById('skuSummaryList').style.display = 'block';
btns[1].classList.add('active');
}
}
function renderSkuSummary() {
const list = document.getElementById('skuSummaryList');
list.innerHTML = '';
const skuMap = {};
inventory.forEach((item) => {
if (!skuMap[item.sku]) skuMap[item.sku] = { ...item };
else skuMap[item.sku].quantity += item.quantity;
});
Object.values(skuMap).forEach((item) => {
const card = document.createElement('div');
card.className = 'product-card';
card.innerHTML = `
<div class="product-info">
<strong>${item.brand}</strong><br />
${item.product_name}<br />
SKU: ${item.sku}<br />
수량: ${item.quantity}개
</div>`;
list.appendChild(card);
});
const backBtn = document.createElement('button');
backBtn.textContent = '재고조사 계속하기';
backBtn.onclick = () => showTab('scan');
list.appendChild(backBtn);
}
// 입력창 포커스 유지
setInterval(() => {
const el = document.activeElement;
const input = document.getElementById('barcodeInput');
if (el !== input) input.focus();
}, 1500);
document
.getElementById('barcodeInput')
.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
addToInventory(e.target.value.trim());
e.target.value = '';
}
});
window.addEventListener('beforeunload', function (e) {
e.preventDefault();
e.returnValue = '새로고침하면 내용이 삭제됩니다.';
});
</script>
</body>
</html>