hookehuyr

fix(Welcome): 修复年龄计算逻辑并添加创建家庭条件检查

修正生日到年龄的转换逻辑,考虑月份和日期差异
添加满60岁才能创建家庭的检查
......@@ -209,11 +209,29 @@ useDidShow(async () => {
wheelchair_text: null,
phone: null,
};
// userInfo.birthday 是年月日的形式需要转成年龄
userInfo.value.birthday = new Date().getFullYear() - new Date(userInfo.value.birth_date).getFullYear();
// 计算用户年龄
if (userInfo.value.birth_date) {
const birthDate = new Date(userInfo.value.birth_date);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
// 如果还没到生日,年龄减1
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
userAge.value = age;
// 检查是否满60岁,可以创建家庭
canCreateFamily.value = age >= 60;
} else {
userAge.value = null;
canCreateFamily.value = false;
}
// 检查用户是否完善了个人信息
hasProfile.value = userInfo.value.nickname && userInfo.value.birth_date && userInfo.value.wheelchair_needed !== null;
userAge.value = userInfo.value.birthday;
}
});
......