merge master into develop - CscListRForm.jsp FAQ 아코디언 버그 수정
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
const EventView = (function() {
|
||||
let timer;
|
||||
let remainingTime;
|
||||
let currentEventId;
|
||||
let startTime;
|
||||
let eventWindow; // 열린 이벤트 창
|
||||
let eventCheckInterval; // 자식 창 상태 확인 타이머
|
||||
let currentMlgRwdAmt; // 현재 이벤트의 마일리지 보상 금액
|
||||
|
||||
// 이벤트 시작 함수
|
||||
function startEventView(bnfInnb, linkUrl, seconds, mlgRwdAmt) {
|
||||
|
||||
// 먼저 이벤트의 적립 상태를 확인
|
||||
if (isEventAccumulated(bnfInnb)) {
|
||||
alert('이미 적립이 완료된 이벤트입니다.');
|
||||
window.open(linkUrl, 'eventView', 'width=800,height=600');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: '/sopmal/bnft/startEventView',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ bnfInnb: bnfInnb }),
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
currentEventId = bnfInnb;
|
||||
remainingTime = seconds;
|
||||
startTime = new Date().getTime();
|
||||
currentMlgRwdAmt = mlgRwdAmt; // 현재 마일리지 값 저장
|
||||
|
||||
// 이벤트 창 열기
|
||||
eventWindow = window.open(linkUrl, 'eventView', 'width=800,height=600');
|
||||
$('.topupPoint').show(); // 초 카운트 표시
|
||||
startTimer();
|
||||
|
||||
// 자식 창 상태 주기적으로 확인
|
||||
eventCheckInterval = setInterval(function() {
|
||||
if (eventWindow.closed) {
|
||||
stopTimer();
|
||||
$('.topupPoint').hide(); // 초 카운트 숨기기
|
||||
clearInterval(eventCheckInterval);
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
alert(response.message || '이벤트 시작에 실패했습니다.');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert('이벤트 시작 요청 중 오류가 발생했습니다.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 타이머 시작 함수
|
||||
function startTimer() {
|
||||
updateTimerDisplay();
|
||||
|
||||
clearInterval(timer); // 기존 타이머 제거
|
||||
timer = setInterval(function() {
|
||||
remainingTime--;
|
||||
updateTimerDisplay();
|
||||
|
||||
if (remainingTime <= 0) {
|
||||
clearInterval(timer);
|
||||
completeMileageAccumulation();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
// 타이머 디스플레이 업데이트 함수
|
||||
function updateTimerDisplay() {
|
||||
$('#countdown').text(remainingTime);
|
||||
}
|
||||
|
||||
// 마일리지 적립 완료 처리 함수
|
||||
function completeMileageAccumulation() {
|
||||
let endTime = new Date().getTime();
|
||||
let duration = (endTime - startTime) / 1000;
|
||||
|
||||
$.ajax({
|
||||
url: '/sopmal/bnft/completeMileageAccumulation',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
bnfInnb: currentEventId,
|
||||
duration: duration,
|
||||
mlgRwdAmt: currentMlgRwdAmt // 마일리지 값을 서버로 전송
|
||||
}),
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
alert('마일리지가 적립되었습니다!');
|
||||
updateEventStatus(currentEventId);
|
||||
$('.topupPoint').hide(); // 초 카운트 숨기기
|
||||
} else {
|
||||
alert(response.message || '마일리지 적립에 실패했습니다.');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error:', error);
|
||||
alert('마일리지 적립 중 오류가 발생했습니다. 다시 시도해주세요.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 타이머 멈추기 함수
|
||||
function stopTimer() {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
if (eventCheckInterval) {
|
||||
clearInterval(eventCheckInterval);
|
||||
}
|
||||
}
|
||||
|
||||
function isEventAccumulated(bnfInnb) {
|
||||
return $(`.li_mile[data-bnf-innb="${bnfInnb}"]`).hasClass('on');
|
||||
}
|
||||
|
||||
function updateEventStatus(bnfInnb) {
|
||||
const mileElement = $(`.li_mile[data-bnf-innb="${bnfInnb}"]`);
|
||||
mileElement.addClass('on').find('span').text('적립완료');
|
||||
}
|
||||
|
||||
return {
|
||||
start: startEventView,
|
||||
stop: stopTimer
|
||||
};
|
||||
})();
|
||||
|
||||
// 창이 닫힐 때 타이머 멈추기
|
||||
$(window).on('beforeunload', function() {
|
||||
EventView.stop();
|
||||
});
|
||||
|
||||
// 디버깅을 위한 콘솔 로그 추가
|
||||
console.log('EventView script loaded');
|
||||
Reference in New Issue
Block a user