
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
export default {
data() {
return {
searchDate: {
startDt: this.startDt(),
endDt: this.endDt()
},
}
},
methods: {
// 날짜 포맷 변경
dateFormat(date) {
return (
date.getFullYear() +
"-" +
(date.getMonth() + 1 < 10
? "0" + (date.getMonth() + 1)
: date.getMonth() + 1) +
"-" +
(date.getDate() < 10 ? "0" + date.getDate() : date.getDate())
);
},
// 기본 시작일 (현재로부터 30일 이전)
startDt() {
let today = new Date();
let date = new Date(today);
date.setDate(today.getDate() - 30);
return this.dateFormat(date);
},
// 기본 종료일 (현재)
endDt() {
let today = new Date();
return this.dateFormat(today);
},
// 조회기간 유효성 검사
// validateDate(event, cate) {
// const val = event.target.value; // 변경된 날짜 값
// // 시작일 변경 시
// if (cate === "startDt") {
// if (this.searchDate.endDt !== null && this.searchDate.endDt < val) {
// alert("시작일은 종료일보다 클 수 없습니다.");
// this.searchDate.startDt = null; // 유효하지 않은 경우, 시작일을 초기화
// } else {
// this.searchDate.startDt = val;
// }
// }
// // 종료일 변경 시
// else if (cate === "endDt") {
// if (this.searchDate.startDt !== null && this.searchDate.startDt > val) {
// alert("종료일은 시작일보다 작을 수 없습니다.");
// this.searchDate.endDt = null; // 유효하지 않은 경우, 종료일을 초기화
// } else {
// this.searchDate.endDt = val;
// }
// }
// },
validateDate(event, cate) {
let val;
// 값이 Date 객체인지 확인
if (event instanceof Date) {
const year = event.getFullYear();
const month = ('00' + (event.getMonth() + 1)).slice(-2);
const day = ('00' + event.getDate()).slice(-2);
val = `${year}-${month}-${day}`;
}
// 값이 Event 객체인지 확인
else if (event instanceof Event) {
val = event.target.value; // input에서 직접 입력된 값
}
// 그 외의 경우 처리 불필요 (예외 처리)
else {
console.error("Invalid date input:", event);
return;
}
// 시작일 검증
if (cate === "startDt") {
if (this.searchDate.endDt && this.searchDate.endDt < val) {
alert("시작일은 종료일보다 클 수 없습니다.");
this.searchDate.startDt = null;
} else {
this.searchDate.startDt = val;
}
}
// 종료일 검증
else if (cate === "endDt") {
if (this.searchDate.startDt && this.searchDate.startDt > val) {
alert("종료일은 시작일보다 작을 수 없습니다.");
this.searchDate.endDt = null;
} else {
this.searchDate.endDt = val;
}
}
}
}
}