diff --git a/src/views/dataTransfer/voyageReg.vue b/src/views/dataTransfer/voyageReg.vue index af3d4e7..f70ff6b 100644 --- a/src/views/dataTransfer/voyageReg.vue +++ b/src/views/dataTransfer/voyageReg.vue @@ -320,7 +320,7 @@ @@ -719,20 +719,38 @@ export default { this.paramsPeople.limit = val this.getPeopleList() }, - formatAge(birthDateString) { - if (birthDateString) { - const today = new Date() - const birthDate = new Date(birthDateString) - let age = today.getFullYear() - birthDate.getFullYear() - // 检查是否已过今年的生日 - const m = today.getMonth() - birthDate.getMonth() - if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { - age-- - } - return age - } else { + /** + * 格式化出生日期显示 + * @param {string|null|undefined} birthDateString - 出生日期 + * @returns {string} + */ + formatBirthday(birthDateString) { + if (!birthDateString || !String(birthDateString).trim()) { return '' } + return String(birthDateString).slice(0, 10) + }, + /** + * 根据出生日期计算年龄,出生信息为空时不计算 + * @param {string|null|undefined} birthDateString - 出生日期 + * @returns {string|number} + */ + formatAge(birthDateString) { + if (!birthDateString || !String(birthDateString).trim()) { + return '' + } + const birthDate = new Date(birthDateString) + if (isNaN(birthDate.getTime())) { + return '' + } + const today = new Date() + let age = today.getFullYear() - birthDate.getFullYear() + // 检查是否已过今年的生日 + const m = today.getMonth() - birthDate.getMonth() + if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { + age-- + } + return age }, cancelPeople() { this.openPeople = false