feat(pos-live): 고객 검색/매핑 + 비동기 마일리지 표시
- GET /api/customers/search: CD_PERSON 검색 (최근 활동순)
- PUT /api/pos-live/{order}/customer: SALE_MAIN 고객 업데이트
- GET /api/customers/{code}/mileage: 비동기 마일리지 조회
- UI: 고객 뱃지 클릭 → 검색 모달 → 선택 → 업데이트
- 마일리지: 이름+전화뒤4자리 매칭, 비동기 표시
This commit is contained in:
@@ -263,11 +263,159 @@
|
||||
font-weight: 600;
|
||||
color: #1e293b;
|
||||
}
|
||||
.customer {
|
||||
.customer-badge {
|
||||
display: inline-block;
|
||||
padding: 4px 10px;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.customer-badge:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
.customer-badge.has-name {
|
||||
background: #dbeafe;
|
||||
color: #1e40af;
|
||||
}
|
||||
.customer-badge.has-name:hover {
|
||||
background: #bfdbfe;
|
||||
}
|
||||
.customer-badge.no-name {
|
||||
background: #f1f5f9;
|
||||
color: #94a3b8;
|
||||
border: 1px dashed #cbd5e1;
|
||||
}
|
||||
.customer-badge.no-name:hover {
|
||||
background: #e2e8f0;
|
||||
border-color: #3b82f6;
|
||||
color: #2563eb;
|
||||
}
|
||||
.mileage-badge {
|
||||
display: inline-block;
|
||||
padding: 2px 6px;
|
||||
margin-left: 6px;
|
||||
background: linear-gradient(135deg, #fbbf24, #f59e0b);
|
||||
color: white;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* 고객 검색 모달 */
|
||||
.customer-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0; bottom: 0;
|
||||
background: rgba(0,0,0,0.6);
|
||||
z-index: 2000;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.customer-modal.show { display: flex; }
|
||||
.customer-modal-content {
|
||||
background: #fff;
|
||||
border-radius: 16px;
|
||||
padding: 24px;
|
||||
max-width: 500px;
|
||||
width: 90%;
|
||||
max-height: 80vh;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.customer-modal h3 {
|
||||
margin: 0 0 16px 0;
|
||||
color: #1e40af;
|
||||
font-size: 18px;
|
||||
}
|
||||
.customer-search-box {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.customer-search-input {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: 2px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.customer-search-input:focus {
|
||||
outline: none;
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
.customer-search-btn {
|
||||
padding: 12px 20px;
|
||||
background: #3b82f6;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
}
|
||||
.customer.non-member {
|
||||
.customer-search-btn:hover {
|
||||
background: #2563eb;
|
||||
}
|
||||
.customer-results {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
max-height: 400px;
|
||||
}
|
||||
.customer-result-item {
|
||||
padding: 12px;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
.customer-result-item:hover {
|
||||
background: #f0f9ff;
|
||||
border-color: #3b82f6;
|
||||
}
|
||||
.customer-result-name {
|
||||
font-weight: 600;
|
||||
color: #1e293b;
|
||||
}
|
||||
.customer-result-birth {
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
margin-left: 8px;
|
||||
}
|
||||
.customer-result-activity {
|
||||
font-size: 12px;
|
||||
color: #94a3b8;
|
||||
margin-top: 4px;
|
||||
}
|
||||
.customer-result-activity.recent {
|
||||
color: #22c55e;
|
||||
}
|
||||
.customer-modal-close {
|
||||
margin-top: 16px;
|
||||
padding: 10px 20px;
|
||||
background: #f1f5f9;
|
||||
color: #64748b;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
}
|
||||
.customer-modal-close:hover {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
.customer-no-results {
|
||||
text-align: center;
|
||||
color: #94a3b8;
|
||||
padding: 40px 20px;
|
||||
}
|
||||
.customer-order-info {
|
||||
background: #f0f9ff;
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 13px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
/* 결제수단 뱃지 */
|
||||
@@ -917,7 +1065,13 @@
|
||||
|
||||
const rows = data.sales.map((sale, idx) => {
|
||||
const payBadge = getPayBadge(sale.pay_method);
|
||||
const customerClass = sale.customer === '[비고객]' ? 'customer non-member' : 'customer';
|
||||
const hasCustomer = sale.customer && sale.customer !== '[비고객]' && sale.customer_code !== '0000000000';
|
||||
const mileageSpan = hasCustomer
|
||||
? `<span class="mileage-badge" id="mileage-${sale.customer_code}" style="display:none;"></span>`
|
||||
: '';
|
||||
const customerBadge = hasCustomer
|
||||
? `<span class="customer-badge has-name" onclick="event.stopPropagation();openCustomerModal('${sale.order_no}', '${escapeHtml(sale.customer)}', '${sale.customer_code}')">${escapeHtml(sale.customer)}</span>${mileageSpan}`
|
||||
: `<span class="customer-badge no-name" onclick="event.stopPropagation();openCustomerModal('${sale.order_no}', '', '0000000000')">미입력</span>`;
|
||||
const qrIcon = sale.qr_issued
|
||||
? '<span class="status-icon qr-yes">✓</span>'
|
||||
: '<span class="status-icon qr-no">✗</span>';
|
||||
@@ -944,7 +1098,7 @@
|
||||
</td>
|
||||
<td onclick="showDetail('${sale.order_no}', ${idx})"><span class="time">${sale.time}</span></td>
|
||||
<td class="right" onclick="showDetail('${sale.order_no}', ${idx})"><span class="amount">₩${Math.floor(sale.amount).toLocaleString()}</span></td>
|
||||
<td onclick="showDetail('${sale.order_no}', ${idx})"><span class="${customerClass}">${sale.customer}</span></td>
|
||||
<td>${customerBadge}</td>
|
||||
<td class="center" onclick="showDetail('${sale.order_no}', ${idx})">${payBadge}</td>
|
||||
<td class="center" onclick="showDetail('${sale.order_no}', ${idx})">${sale.item_count}</td>
|
||||
<td class="center" onclick="showDetail('${sale.order_no}', ${idx})">${qrIcon}</td>
|
||||
@@ -955,6 +1109,37 @@
|
||||
|
||||
document.getElementById('salesTable').innerHTML = rows;
|
||||
updateSelectedCount();
|
||||
|
||||
// 비동기로 마일리지 조회
|
||||
fetchMileagesAsync(data.sales);
|
||||
}
|
||||
|
||||
async function fetchMileagesAsync(sales) {
|
||||
// 고객코드 있는 건들만 수집 (중복 제거)
|
||||
const cusCodes = [...new Set(
|
||||
sales
|
||||
.filter(s => s.customer_code && s.customer_code !== '0000000000')
|
||||
.map(s => s.customer_code)
|
||||
)];
|
||||
|
||||
// 각 고객코드에 대해 비동기 조회
|
||||
for (const code of cusCodes) {
|
||||
try {
|
||||
const res = await fetch(`/api/customers/${code}/mileage`);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success && data.mileage !== null) {
|
||||
// 해당 코드의 모든 mileage-badge 업데이트
|
||||
const badges = document.querySelectorAll(`#mileage-${code}`);
|
||||
badges.forEach(badge => {
|
||||
badge.textContent = data.mileage.toLocaleString() + 'P';
|
||||
badge.style.display = 'inline-block';
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(`마일리지 조회 실패 (${code}):`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getPayBadge(method) {
|
||||
@@ -1481,6 +1666,149 @@
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(toastStyle);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// 고객 검색/매핑 모달
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
|
||||
let currentOrderNo = null;
|
||||
let currentCustomerName = '';
|
||||
|
||||
function escapeHtml(str) {
|
||||
if (!str) return '';
|
||||
return str.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function openCustomerModal(orderNo, customerName, customerCode) {
|
||||
currentOrderNo = orderNo;
|
||||
currentCustomerName = customerName;
|
||||
|
||||
document.getElementById('customerOrderInfo').textContent =
|
||||
`주문번호: ${orderNo} | 현재: ${customerName || '미입력'}`;
|
||||
document.getElementById('customerSearchInput').value = customerName || '';
|
||||
document.getElementById('customerResults').innerHTML =
|
||||
'<div class="customer-no-results">이름을 검색하세요</div>';
|
||||
|
||||
document.getElementById('customerModal').classList.add('show');
|
||||
document.getElementById('customerSearchInput').focus();
|
||||
}
|
||||
|
||||
function closeCustomerModal() {
|
||||
document.getElementById('customerModal').classList.remove('show');
|
||||
currentOrderNo = null;
|
||||
}
|
||||
|
||||
async function searchCustomers() {
|
||||
const name = document.getElementById('customerSearchInput').value.trim();
|
||||
if (name.length < 2) {
|
||||
document.getElementById('customerResults').innerHTML =
|
||||
'<div class="customer-no-results">2자 이상 입력하세요</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/customers/search?name=${encodeURIComponent(name)}`);
|
||||
const data = await res.json();
|
||||
|
||||
if (!data.success) {
|
||||
document.getElementById('customerResults').innerHTML =
|
||||
`<div class="customer-no-results">${data.error}</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.results.length === 0) {
|
||||
document.getElementById('customerResults').innerHTML =
|
||||
'<div class="customer-no-results">검색 결과가 없습니다</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
const html = data.results.map(c => {
|
||||
const birthDisplay = c.birth
|
||||
? `(${c.birth.substring(0,2)}.${c.birth.substring(2,4)}.${c.birth.substring(4,6)})`
|
||||
: '';
|
||||
let activityHtml = '';
|
||||
if (c.activity_type && c.days_ago !== null) {
|
||||
const isRecent = c.days_ago <= 30;
|
||||
activityHtml = `<div class="customer-result-activity ${isRecent ? 'recent' : ''}">
|
||||
${c.activity_type === '조제' ? '📋' : '🛒'}
|
||||
${c.activity_type} ${c.days_ago === 0 ? '오늘' : c.days_ago + '일 전'}
|
||||
</div>`;
|
||||
} else {
|
||||
activityHtml = '<div class="customer-result-activity">활동 기록 없음</div>';
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="customer-result-item" onclick="selectCustomer('${c.cus_code}', '${escapeHtml(c.name)}')">
|
||||
<span class="customer-result-name">${escapeHtml(c.name)}</span>
|
||||
<span class="customer-result-birth">${birthDisplay}</span>
|
||||
${activityHtml}
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
document.getElementById('customerResults').innerHTML = html;
|
||||
|
||||
} catch (err) {
|
||||
document.getElementById('customerResults').innerHTML =
|
||||
`<div class="customer-no-results">오류: ${err.message}</div>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function selectCustomer(cusCode, cusName) {
|
||||
if (!currentOrderNo) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/pos-live/${currentOrderNo}/customer`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ cus_code: cusCode, cus_name: cusName })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
showToast(`${cusName}님으로 업데이트됨`, 'success');
|
||||
closeCustomerModal();
|
||||
loadSales(); // 테이블 새로고침
|
||||
} else {
|
||||
showToast('업데이트 실패: ' + data.error, 'error');
|
||||
}
|
||||
} catch (err) {
|
||||
showToast('오류: ' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Enter 키로 검색
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
document.getElementById('customerSearchInput')?.addEventListener('keypress', e => {
|
||||
if (e.key === 'Enter') searchCustomers();
|
||||
});
|
||||
});
|
||||
|
||||
// 모달 외부 클릭 시 닫기
|
||||
document.getElementById('customerModal')?.addEventListener('click', e => {
|
||||
if (e.target.id === 'customerModal') closeCustomerModal();
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- 고객 검색 모달 -->
|
||||
<div class="customer-modal" id="customerModal">
|
||||
<div class="customer-modal-content">
|
||||
<h3>👤 고객 매핑</h3>
|
||||
<div class="customer-order-info" id="customerOrderInfo">주문번호: -</div>
|
||||
<div class="customer-search-box">
|
||||
<input type="text" class="customer-search-input" id="customerSearchInput"
|
||||
placeholder="이름 검색..." autocomplete="off">
|
||||
<button class="customer-search-btn" onclick="searchCustomers()">검색</button>
|
||||
</div>
|
||||
<div class="customer-results" id="customerResults">
|
||||
<div class="customer-no-results">이름을 검색하세요</div>
|
||||
</div>
|
||||
<button class="customer-modal-close" onclick="closeCustomerModal()">닫기</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user