merge master into develop - CscListRForm.jsp FAQ 아코디언 버그 수정
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
$(document).ready(function() {
|
||||
// 관심분야 목록 렌더링 함수
|
||||
function renderInterestList() {
|
||||
const $favoriteList = $('.favoriteList');
|
||||
$favoriteList.empty(); // 기존 목록 초기화
|
||||
// 각 관심분야에 대해 리스트 아이템 생성
|
||||
interestAreas.forEach(function(interest) {
|
||||
const $li = $('<li>');
|
||||
const $a = $('<a>').attr('href', '#');
|
||||
const $imgP = $('<p>').addClass('img');
|
||||
const $img = $('<img>')
|
||||
.attr('alt', interest.name)
|
||||
.attr('data-interest-id', interest.id);
|
||||
const $titleP = $('<p>').addClass('tit').text(interest.name);
|
||||
$imgP.append($img);
|
||||
$a.append($imgP).append($titleP);
|
||||
$li.append($a);
|
||||
$favoriteList.append($li);
|
||||
// 이미지 로드
|
||||
loadImage(interest.id, interest.beforeImagePath);
|
||||
});
|
||||
// 클릭 이벤트 리스너 추가
|
||||
$('.favoriteList li a').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$(this).closest('li').toggleClass('on');
|
||||
});
|
||||
|
||||
// 사용자 관심분야 조회 및 UI 업데이트
|
||||
getUserInterests();
|
||||
}
|
||||
|
||||
// 사용자 관심분야 조회 함수 추가
|
||||
function getUserInterests() {
|
||||
const bnfInnb = $('#bnfInnb').val();
|
||||
$.ajax({
|
||||
url: '/sopmal/bnft/selectUserInterests',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ bnfInnb: bnfInnb }),
|
||||
success: function(response) {
|
||||
if (response && response.interestAreas) {
|
||||
updateUIWithUserInterests(response.interestAreas);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to fetch user interests:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// UI 업데이트 함수 추가
|
||||
function updateUIWithUserInterests(userInterests) {
|
||||
$('.favoriteList li').removeClass('on');
|
||||
userInterests.forEach(function(interest) {
|
||||
$('.favoriteList li img[data-interest-id="' + interest.bnfIntrstInnb + '"]')
|
||||
.closest('li')
|
||||
.addClass('on');
|
||||
});
|
||||
}
|
||||
|
||||
// 이미지 로드 함수
|
||||
function loadImage(interestId, imagePath) {
|
||||
$.ajax({
|
||||
url: '/sopmal/bnft/image',
|
||||
method: 'GET',
|
||||
data: { path: imagePath },
|
||||
xhrFields: {
|
||||
responseType: 'blob'
|
||||
},
|
||||
success: function(data) {
|
||||
var $img = $('img[data-interest-id="' + interestId + '"]');
|
||||
var imageUrl = URL.createObjectURL(data);
|
||||
$img.attr('src', imageUrl);
|
||||
},
|
||||
error: function() {
|
||||
console.error('Failed to load image for interest:', interestId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 마일리지 상태 업데이트 함수 추가
|
||||
function updateMileageStatus() {
|
||||
const bnfInnb = $('#bnfInnb').val();
|
||||
$.ajax({
|
||||
url: '/sopmal/bnft/selectUserInterestSaveStatus',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({ bnfInnb: bnfInnb }),
|
||||
success: function(response) {
|
||||
if (response.savedYn === 'Y') {
|
||||
if (response.mileageAccumulatedYn === 'Y') {
|
||||
$('.topupPoint.noSticky span').html('마일리지 ' + response.mlgRwdAmt + '원 적립완료');
|
||||
} else {
|
||||
$('.topupPoint.noSticky span').html('마일리지 ' + response.mlgRwdAmt + '원 적립완료');
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Failed to get user interest save status:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 초기 관심분야 목록 렌더링
|
||||
renderInterestList();
|
||||
|
||||
// 초기 마일리지 상태 업데이트
|
||||
updateMileageStatus();
|
||||
|
||||
// 저장 버튼 초기 상태 설정
|
||||
$('#saveBtn').prop('disabled', true);
|
||||
|
||||
// 체크박스 상태 변경 이벤트 핸들러
|
||||
$('#agreementCheckbox').on('change', function() {
|
||||
$('#saveBtn').prop('disabled', !this.checked);
|
||||
});
|
||||
|
||||
// 저장 버튼 클릭 이벤트 핸들러
|
||||
$('#saveBtn').on('click', function() {
|
||||
var agreementChecked = $('#agreementCheckbox').is(':checked');
|
||||
|
||||
// 동의 체크박스 확인
|
||||
if (!agreementChecked) {
|
||||
showToast('관심분야 정보받기에 동의해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
// 선택된 관심분야 수집
|
||||
var selectedInterests = $('.favoriteList li.on').map(function() {
|
||||
return {
|
||||
bnfIntrstInnb: $(this).find('img').data('interest-id'),
|
||||
selected: true
|
||||
};
|
||||
}).get();
|
||||
|
||||
// 최소 1개 이상의 관심분야 선택 확인
|
||||
if (selectedInterests.length === 0) {
|
||||
showToast('최소 1개 이상의 관심분야를 선택해주세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
const bnfInnb = $('#bnfInnb').val();
|
||||
|
||||
// 서버로 전송할 데이터 준비
|
||||
var data = {
|
||||
bnfInnb: bnfInnb,
|
||||
interestAreas: selectedInterests,
|
||||
agreementFlag: agreementChecked
|
||||
};
|
||||
|
||||
console.log(data);
|
||||
// AJAX 요청
|
||||
$.ajax({
|
||||
url: '/sopmal/bnft/saveUserInterests',
|
||||
method: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
showToast(response.message);
|
||||
if (response.mileageAccumulated) {
|
||||
showToast('마일리지가 적립되었습니다.');
|
||||
updateMileageStatus(); // 마일리지 상태 업데이트
|
||||
}
|
||||
getUserInterests(); // 사용자 관심분야 재조회
|
||||
} else {
|
||||
showToast('저장 중 오류가 발생했습니다: ' + response.message);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
showToast('서버와의 통신 중 오류가 발생했습니다.');
|
||||
console.error('Error:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 토스트 메시지 표시 함수
|
||||
function showToast(message) {
|
||||
var $toastPop = $('#toastPop');
|
||||
$toastPop.find('.txt').text(message);
|
||||
$toastPop.addClass('show');
|
||||
// 2초 후 토스트 메시지 숨김
|
||||
setTimeout(function() {
|
||||
$toastPop.removeClass('show');
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user