/** * QREvntMain.js - QR 이벤트 모듈 (기존 모달 시스템 사용) */ const QREvent = (function() { let participationId = null; /** * 초기화 함수 */ function init() { console.log('QREvent init'); // 서버에서 넘어온 참여 결과에 따라 모달 표시 showResultModal(); } /** * 서버 결과에 따른 모달 표시 */ function showResultModal() { // participationResult는 JSP에서 생성된 전역 변수 if (typeof participationResult === 'undefined') { console.log('참여 결과 데이터가 없습니다.'); return; } console.log('참여 결과:', participationResult); // errorCode 확인해서 적절한 모달 표시 if (typeof qrEventErrorCode !== 'undefined' && qrEventErrorCode === 'NO_EVENT') { // 진행중인 이벤트 없음 showNoEventModal(); } else if (!participationResult.success) { // 참여 실패 (이미 참여했거나, 참여 기간이 아니거나 등) showMessageModal(participationResult.message); } else if (participationResult.isWinner) { // 당첨 participationId = participationResult.participationId; showWinningModal(); } else { // 미당첨 showNotWinningModal(); } } /** * 쿠폰 상세 보기 (유일한 Ajax 호출) */ function viewCoupon() { if (!participationId) { showMessageModal('참여 정보를 찾을 수 없습니다.'); return; } $.ajax({ url: '/sopmal/bnft/getWinningDetail', method: 'POST', contentType: 'application/json; charset=UTF-8', data: JSON.stringify({ bnfPrtInnb: participationId }), success: function(response) { console.log('쿠폰 상세 정보:', response); if (response) { showCouponModal(response); } else { showMessageModal('쿠폰 정보를 조회하지 못했습니다.'); } }, error: function(xhr, status, error) { console.error('쿠폰 정보 조회 실패:', error); showMessageModal('쿠폰 정보를 불러오는 중 오류가 발생했습니다.'); } }); } // --- 모달 표시 헬퍼 함수 --- /** * 범용 메시지 모달 표시 * @param {string} message - 표시할 메시지 */ function showMessageModal(message) { $('#modal-message #modalMessage').text(message || '오류가 발생했습니다.'); openModal('modal-message'); // 기존 시스템 함수 사용 } /** * 당첨 모달 표시 */ function showWinningModal() { // storeInfo는 JSP에서 생성된 전역 변수 if (typeof storeInfo !== 'undefined' && storeInfo.strNm) { $('#modal-winning #winningStoreName').text(storeInfo.strNm); } openModal('modal-winning'); // 기존 시스템 함수 사용 } /** * 미당첨 모달 표시 */ function showNotWinningModal() { // 필요 시 서버 메시지로 교체 가능 $('#modal-notwinning #notWinningMessage').text('이번에는 당첨되지 않았네요.'); openModal('modal-notwinning'); // 기존 시스템 함수 사용 } /** * 쿠폰 상세 모달 표시 * @param {object} data - 쿠폰 상세 정보 */ function showCouponModal(data) { // 쿠폰 번호, 매장명 설정 $('#modal-coupon #couponNo').text(data.couponNb || ''); $('#modal-coupon #couponStoreName').text(data.strNm || ''); // 사용 조건 (하드코딩) $('#modal-coupon #couponTerms').text('10,000원 이상 구매시 사용 가능'); // 유효 기간 설정 if (data.expiryDateTime) { $('#modal-coupon #couponValidity').text(`${data.expiryDateTime} 까지`); } else { $('#modal-coupon #couponValidity').text('유효기간 없음'); } // 할인 정보 또는 상품 정보 처리 const contentEl = $('#modal-coupon #couponContent'); const discountTypeEl = $('#modal-coupon #couponDiscountType'); if (data.dscntAmt || data.dscntRt) { // 금액 또는 비율 할인 const discountInfo = data.dscntAmt ? `${data.dscntAmt.toLocaleString()}` : // 1,000 `${data.dscntRt}`; // 10 const discountUnit = data.dscntAmt ? '원' : '%'; contentEl.html(`${discountInfo}${discountUnit}`); discountTypeEl.text('할인쿠폰').show(); } else { // 상품 증정 contentEl.text(data.couponName || '증정품'); contentEl.removeClass('price'); // 금액 표시 클래스 제거 discountTypeEl.hide(); // '할인쿠폰' 텍스트 숨김 } // 당첨 모달 닫고 쿠폰 모달 표시 closeModal('modal-winning'); // 기존 시스템 함수 사용 openModal('modal-coupon'); // 기존 시스템 함수 사용 } /** * 진행중인 이벤트 없음 모달 표시 */ function showNoEventModal() { // 전역 변수에서 메시지 가져오기 if (typeof qrEventMessage !== 'undefined') { $('#modal-no-event #noEventMessage').text(qrEventMessage); } if (typeof qrEventDetailMessage !== 'undefined') { $('#modal-no-event #noEventDetailMessage').text(qrEventDetailMessage); } openModal('modal-no-event'); // 기존 시스템 함수 사용 } // 공개 메서드 return { init: init, viewCoupon: viewCoupon }; })(); // DOM 로드 시 초기화 $(document).ready(function() { QREvent.init(); // 모든 모달의 닫기 버튼 클릭 시 /sopmal/bnft/bnftMain 으로 이동 $('.microModal__close').on('click', function() { window.location.href = '/sopmal/bnft/bnftMain'; }); });