class CustomInquiryList extends ShopbySkin.modules.InquiryList {
setup() {
super.setup()
}
setProps() {
super.setProps();
this.propsAsString.startYmd;
this.propsAsString.endYmd;
this.propsParam.startYmd;
this.propsParam.endYmd;
const params = new URLSearchParams(location.search);
const dateType = params.get('dateType')
const keyword = params.get('keyword');
if (dateType) {
let today = new Date();
let targetDate = new Date(today); // 오늘 날짜 복사
switch (dateType) {
case 'td':
// 오늘 날짜 그대로 사용
break;
case '7d':
targetDate.setDate(today.getDate() - 7); // 7일 전
break;
case '1m':
targetDate.setMonth(today.getMonth() - 1); // 1개월 전
break;
case '3m':
targetDate.setMonth(today.getMonth() - 3); // 3개월 전
break;
case '1y':
targetDate.setFullYear(today.getFullYear() - 1); // 1년 전
break;
default:
targetDate = '';
today = '';
//throw new Error('지원하지 않는 기간 형식입니다.');
}
this.propsParam.startYmd = this.formatDate(targetDate);
this.propsParam.endYmd = this.formatDate(today);
this.propsParam.keyword = keyword || '';
}
}
formatDate(date) {
if (date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 월은 0부터 시작하므로 +1
const day = String(date.getDate()).padStart(2, '0'); // 일자를 2자리로 맞추기
return `${year}-${month}-${day}`;
}
}
fetchPersonalInquiries(type) {
if (type == 'dateChange') {
this.pageNumber = 1;
}
super.fetchPersonalInquiries();
}
}
customElements.define('custom-inquiry-list', CustomInquiryList);
class CustomDateTypeSelector extends ShopbySkin.modules.DateTypeSelector {
setEvent() {
const clickEventMap = new Map();
clickEventMap.set("SEARCH", this.searchInquiryDate);
this.addEvent({
eventType: "change",
eventMap: clickEventMap
});
}
searchInquiryDate = ({target}) => {
const val = target.value;
let today = new Date();
let targetDate = new Date(today); // 오늘 날짜 복사
switch (val) {
case 'td':
// 오늘 날짜 그대로 사용
break;
case '7d':
targetDate.setDate(today.getDate() - 7); // 7일 전
break;
case '1m':
targetDate.setMonth(today.getMonth() - 1); // 1개월 전
break;
case '3m':
targetDate.setMonth(today.getMonth() - 3); // 3개월 전
break;
case '1y':
targetDate.setFullYear(today.getFullYear() - 1); // 1년 전
break;
default:
targetDate = '';
today = '';
//throw new Error('지원하지 않는 기간 형식입니다.');
}
function formatDate(date) {
if (date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 월은 0부터 시작하므로 +1
const day = String(date.getDate()).padStart(2, '0'); // 일자를 2자리로 맞추기
return `${year}-${month}-${day}`;
}
}
const url = new URL(window.location);
const params = new URLSearchParams(url.search);
params.set('dateType', val);
params.set('pageNumber', '1');
params.set('startYmd', formatDate(targetDate));
params.set('endYmd', formatDate(today));
url.search = params.toString();
window.history.pushState({}, '', url);
//window.location.reload();
document.querySelector('custom-inquiry-list').propsParam.startYmd = formatDate(targetDate);
document.querySelector('custom-inquiry-list').propsParam.endYmd = formatDate(today);
document.querySelector('custom-inquiry-list').propsAsString.pageNumber = 1;
document.querySelector('custom-inquiry-list').propsParam.pageNumber = 1;
document.querySelector('custom-inquiry-list').pageNumber = 1;
document.querySelector('custom-inquiry-list').fetchPersonalInquiries('dateChange');
}
}
customElements.define('custom-date-type-selector', CustomDateTypeSelector);
(async () => {
const { EventManager, pageHelper, actions, utils } = ShopbySkin;
const myInquiryListHelper = pageHelper.myInquiryListHelper();
if (!utils.isSignIn()) {
ShopbySkin.EventManager.fire('MODAL_CONFIRM_OPEN', {
noticeType: 'CAUTION',
message: '로그인하셔야 본 서비스를 이용하실 수 있습니다.',
onConfirm: redirectLoginPage,
});
return;
}
$('body').hide();
const moduleActionHandler = {
REGISTER: ({ name = '', usesAttachment }) => {
EventManager.fire('OPEN_LAYER_MODAL', {
name: 'personal-inquiry-form',
title: `${name ?? '1:1문의'} 등록`,
data: {
isModify: false,
usesAttachment,
commonData: myInquiryListHelper.commonData,
},
onClose: ({ reason }) => {
if (reason === 'DID_SUBMIT') {
EventManager.fire('MODAL_ALERT_OPEN', {
noticeType: 'SUCCESS',
message: '게시글이 저장되었습니다.',
onClose: () => {
location.reload();
},
});
}
},
});
},
};
const inquiryFormModuleEl = document.querySelector('inquiry-register');
inquiryFormModuleEl?.addEventListener('click', ({ target }) => {
const action = target.getAttribute('shopby-action');
const name = target.closest('[shopby-inquiry-board-name]')?.getAttribute('shopby-inquiry-board-name');
const usesAttachment = target.closest('[shopby-uses-attachment]')?.getAttribute('shopby-uses-attachment');
moduleActionHandler[action]?.({ name, usesAttachment });
});
const inquiryListModuleEl = document.querySelector('custom-inquiry-list');
inquiryListModuleEl?.addEventListener('click', ({ target }) => {
const action = target.getAttribute('shopby-action');
const inquiryNo = target.closest('[shopby-inquiry-no]')?.getAttribute('shopby-inquiry-no');
const name = target.closest('[shopby-inquiry-board-name]')?.getAttribute('shopby-inquiry-board-name');
moduleActionHandler[action]?.({ inquiryNo, name });
});
EventManager.on('QUERY_INQUIRIES', async (data) => {
const state = await document.querySelector('custom-inquiry-list').store.getState();
setTimeout(function () {
const params = document.querySelector('custom-inquiry-list').propsParam;
const queryString = new URLSearchParams(location.search);
const dateType = queryString.get('dateType')
const pagination = state.pagination;
for (const key in pagination) {
const addquery = "&startYmd=" + params.startYmd + "&endYmd=" + params.endYmd + "&dateType=" + dateType + "&keyword=" + (params.keyword || '');
if (key != 'pages' && key != 'totalPages') {
pagination[key] += addquery;
}
if (key == 'pages') {
for (const key1 in pagination[key]) {
pagination[key][key1]['param'] += addquery;
}
}
}
document.querySelector('custom-inquiry-list').store.setState({
pagination: pagination,
})
$('body').show();
}, 1)
});
})();