(() => { const { pageHelper, EventManager, utils, actions, constants } = ShopbySkin; const eventDetailHelper = pageHelper.eventDetailHelper(); const { replaceHistory, isSignIn, moveTo } = utils; const containerEl = document.querySelector('[shopby-helper-key="event-detail-helper-key"]'); const { event: eventNoOrId, pageSize, pageNumber, sectionNo } = utils.getQueryParams(location); const eventDetailRequest = { eventKey: eventNoOrId }; const eventDetailProductRequest = { sortType: 'ADMIN_SETTING', soldOut: true, includeStopProduct: true, }; const searchParams = new URLSearchParams(location.search); const eventDetailProductRequestParamType = [ 'event', 'sectionNo', 'pageNumber', 'pageSize', 'sortType', 'direction', 'soldOut', 'includeStopProduct', ]; const redirectLoginPage = () => { moveTo({ url: `${constants.PAGE.SIGN_IN}?from=${encodeURIComponent(location.href)}` }); }; const convertEventDetailRequestParam = (params, filterTypes) => Object.fromEntries(params?.filter(([key]) => !filterTypes.includes(key))); eventDetailHelper.initialize({ helperKey: 'event-detail-helper-key' }); // --------------------------------------------------------- // 1. 할인율 반올림 처리 로직 (통합) // --------------------------------------------------------- const removeDecimalPointWithRounding = () => { const discountElements = document.querySelectorAll('.rate em.highlight'); discountElements.forEach((el) => { const currentText = el.textContent.trim(); if (currentText.includes('.')) { const roundedValue = Math.round(parseFloat(currentText)); if (!isNaN(roundedValue)) { el.textContent = roundedValue + '%'; } } }); }; const likeHelper = { toggleClassName: (likeEl) => likeEl.classList.toggle('is-active'), toggleLikeStatus: async (likeEl) => { const productNo = likeEl.getAttribute('shopby-product-no') ?? 0; await actions.toggleLikeStatus({ productNo: Number(productNo) }); }, }; const CLICK_EVENT_HANDLER_MAP = { HANDLE_COUPON_BTN_CLICK: () => { if (!isSignIn()) { ShopbySkin.EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'CAUTION', message: '로그인하셔야 본 서비스를 이용하실 수 있습니다.', onConfirm: redirectLoginPage, }); return; } const { coupon, eventNo } = document.querySelector('event-detail-product-list-v2').store.state ?? {}; ShopbySkin.EventManager.fire('OPEN_LAYER_MODAL', { title: '쿠폰받기', name: 'coupon-download', data: { coupons: coupon?.coupons?.filter(({ downloadable }) => downloadable) ?? [], eventNo }, isFull: true, onClose: () => null, }); }, HANDLE_SECTION_ID_CLICK: ({ target, helper }) => { const tabId = target.getAttribute('shopby-tab-id'); const currentSectionNo = target.getAttribute('shopby-section-no'); const { eventNo } = document.querySelector('event-detail-product-list-v2').store.state ?? {}; helper.eventAction.selectEventCategoryV2({ tabId, sectionNo: currentSectionNo }); searchParams.set('sectionNo', currentSectionNo); searchParams.set('pageNumber', 1); const param = Object.fromEntries(searchParams); replaceHistory({ query: param }); const { event, ...rest } = param; eventDetailHelper.eventAction.fetchEventDetailProducts({ ...eventDetailProductRequest, ...rest, eventNo, sectionNo: currentSectionNo, pageSize, pageNumber: 1, }); scrollTo({ top: 0, behavior: 'smooth' }); }, LIKE_PRODUCT: ({ target }) => { if (!isSignIn()) { ShopbySkin.EventManager.fire('MODAL_CONFIRM_OPEN', { noticeType: 'CAUTION', message: '로그인하셔야 본 서비스를 이용하실 수 있습니다.', onConfirm: redirectLoginPage, }); return; } const likeEl = target.closest('[shopby-product-no]'); likeHelper.toggleClassName(likeEl); likeHelper.toggleLikeStatus(likeEl); }, }; const CHANGE_EVENT_HANDLER_MAP = { HANDLE_SORT_CHANGE: ({ target, helper }) => { const paramArray = Array.from(searchParams.entries()); const eventDetailRequestParam = convertEventDetailRequestParam(paramArray, eventDetailProductRequestParamType); helper.eventAction.fetchEventDetailV2({ ...eventDetailRequestParam, ...eventDetailRequest, sortType: target.value, }); }, }; EventManager.fire('INIT_EVENT_PRODUCT_SECTION_SLIDER', { spaceBetween: 12, direction: 'horizontal', effect: 'slide', slidesPerView: 'auto', }); // --------------------------------------------------------- // 2. 페이지 로드 시 및 데이터 변경 시 실행 로직 // --------------------------------------------------------- EventManager.on('PAGE_LOAD_COMPLETED', () => { const paramArray = Array.from(searchParams.entries()); const eventDetailRequestParam = convertEventDetailRequestParam(paramArray, eventDetailProductRequestParamType); eventDetailHelper.eventAction.fetchEventDetailV2({ ...eventDetailRequestParam, ...eventDetailRequest }); EventManager.on('QUERY_DISPLAY_EVENTS_EVENT_NO', (data) => { EventManager.fire('CHANGE_SUB_TITLE', { subTitle: data?.label }); const currentSectionNo = sectionNo ?? data.listOfExhibition[0]?.sectionNo; if (!currentSectionNo) return; searchParams.set('sectionNo', currentSectionNo); const param = Object.fromEntries(searchParams); replaceHistory({ query: param }); const { event, ...rest } = param; eventDetailHelper.eventAction.fetchEventDetailProducts({ ...eventDetailProductRequest, ...rest, eventNo: data.eventNo, sectionNo: currentSectionNo, pageSize, pageNumber, }); }); // 로고 변경 및 할인율 반올림 초기 실행 setTimeout(() => { updateHeaderLogo(); removeDecimalPointWithRounding(); }, 500); // 상품 목록 업데이트 감시 (할인율 반올림 다시 적용) const observer = new MutationObserver(removeDecimalPointWithRounding); const targetNode = document.querySelector('.event-detail') || document.body; observer.observe(targetNode, { childList: true, subtree: true }); }); // 헤더 로고 변경 함수 function updateHeaderLogo() { var headers = document.querySelectorAll('shopby-header-v2'); var title = headers[0] ? headers[0].querySelector('.header__title') : null; var back = headers[0] ? headers[0].querySelector('.header__back') : null; if (title) { title.innerHTML = '메인 로고'; title.style.cssText = 'visibility: visible !important; display: flex !important; align-items: center !important; justify-content: center !important;'; if (back) back.style.cssText = 'display: none !important'; title.querySelector('img').onclick = () => { window.location.href = '/'; }; } } // --------------------------------------------------------- // 3. 기타 이벤트 바인딩 및 탭 처리 // --------------------------------------------------------- const clickEventListener = ({ target }) => { const actionType = target.getAttribute('shopby-action') ?? target.closest('button')?.getAttribute('shopby-action'); CLICK_EVENT_HANDLER_MAP[actionType]?.({ helper: eventDetailHelper, target }); }; const changeEventListener = ({ target }) => { const actionType = target.getAttribute('shopby-action'); CHANGE_EVENT_HANDLER_MAP[actionType]?.({ helper: eventDetailHelper, target }); }; containerEl.addEventListener('click', clickEventListener); containerEl.addEventListener('change', changeEventListener); // 탭 클릭 및 스크롤 복원 const tabUrls = [ '/pages/event/event-detail.html?event=80477&pageSize=20&pageNumber=1&sortType=ADMIN_SETTING&soldOut=true&includeStopProduct=true§ionNo=1354060', '/pages/event/event-detail.html?event=73820&pageSize=20&pageNumber=1&sortType=ADMIN_SETTING&soldOut=true&includeStopProduct=true§ionNo=1329505' ]; document.querySelectorAll('.tab-menu .tab-btn').forEach((btn, index) => { if (!tabUrls[index]) return; btn.addEventListener('click', (e) => { e.preventDefault(); sessionStorage.setItem('tabScrollY', window.scrollY); setTimeout(() => { location.href = tabUrls[index]; }, 50); }); }); window.addEventListener('load', () => { const savedScrollY = sessionStorage.getItem('tabScrollY'); if (savedScrollY) { window.scrollTo(0, parseInt(savedScrollY)); sessionStorage.removeItem('tabScrollY'); } // 탭 활성화 표시 const TAB_INDEX_BY_EVENT = { '80477': 0, '73820': 1 }; const eventNo = new URLSearchParams(window.location.search).get('event'); const targetIndex = TAB_INDEX_BY_EVENT[eventNo]; document.querySelectorAll('.tab-btn').forEach((tab, i) => { tab.classList.toggle('active', i === targetIndex); }); }); // 개수 숨기기 로직 const hideTotalCount = () => { const el = document.querySelector('.total-sort__count'); if (el) el.style.display = 'none'; }; const countObserver = new MutationObserver(hideTotalCount); countObserver.observe(document.body, { childList: true, subtree: true }); setInterval(hideTotalCount, 500); })();