hookehuyr

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

修正生日到年龄的转换逻辑,考虑月份和日期差异
添加满60岁才能创建家庭的检查
...@@ -209,11 +209,29 @@ useDidShow(async () => { ...@@ -209,11 +209,29 @@ useDidShow(async () => {
209 wheelchair_text: null, 209 wheelchair_text: null,
210 phone: null, 210 phone: null,
211 }; 211 };
212 - // userInfo.birthday 是年月日的形式需要转成年龄 212 +
213 - userInfo.value.birthday = new Date().getFullYear() - new Date(userInfo.value.birth_date).getFullYear(); 213 + // 计算用户年龄
214 + if (userInfo.value.birth_date) {
215 + const birthDate = new Date(userInfo.value.birth_date);
216 + const today = new Date();
217 + let age = today.getFullYear() - birthDate.getFullYear();
218 + const monthDiff = today.getMonth() - birthDate.getMonth();
219 +
220 + // 如果还没到生日,年龄减1
221 + if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
222 + age--;
223 + }
224 +
225 + userAge.value = age;
226 + // 检查是否满60岁,可以创建家庭
227 + canCreateFamily.value = age >= 60;
228 + } else {
229 + userAge.value = null;
230 + canCreateFamily.value = false;
231 + }
232 +
214 // 检查用户是否完善了个人信息 233 // 检查用户是否完善了个人信息
215 hasProfile.value = userInfo.value.nickname && userInfo.value.birth_date && userInfo.value.wheelchair_needed !== null; 234 hasProfile.value = userInfo.value.nickname && userInfo.value.birth_date && userInfo.value.wheelchair_needed !== null;
216 - userAge.value = userInfo.value.birthday;
217 } 235 }
218 }); 236 });
219 237
......