diff --git a/openhis-ui-vue3/src/views/charge/outpatientregistration/components/patientAddDialog.vue b/openhis-ui-vue3/src/views/charge/outpatientregistration/components/patientAddDialog.vue index 1ef037d7..ff0780ec 100644 --- a/openhis-ui-vue3/src/views/charge/outpatientregistration/components/patientAddDialog.vue +++ b/openhis-ui-vue3/src/views/charge/outpatientregistration/components/patientAddDialog.vue @@ -10,58 +10,8 @@ - - - - - {{ item.info }} - - - - - - - - - {{ dict.label }} - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - @@ -135,7 +145,8 @@ - + + @@ -262,7 +273,7 @@ - + { // 监护人信息条件验证函数 const validateGuardianInfo = (rule, value, callback) => { - // 只有当年龄小于规定年龄时才验证监护人信息 - if (form.value.age) { - // 提取年龄数字部分 - const ageMatch = form.value.age.toString().match(/\d+/); - if (ageMatch) { - const age = parseInt(ageMatch[0]); - const guardianAgeValue = parseInt(props.guardianAge) || 16; - // 如果年龄小于规定年龄,监护人信息必须填写 - if (age < guardianAgeValue && !value) { - return callback(new Error(`年龄小于${guardianAgeValue}岁的患者必须填写监护人信息`)); + // 从系统配置获取监护人规定年龄 + getConfigKey('guardianAge').then(res => { + if (res.code === 200) { + const guardianAgeValue = parseInt(res.data) || 16; // 默认值为16 + + // 提取年龄数字部分 + const ageMatch = form.value.age.toString().match(/\d+/); + if (ageMatch) { + const age = parseInt(ageMatch[0]); + // 如果年龄小于规定年龄,监护人信息必须填写 + if (age < guardianAgeValue && !value) { + return callback(new Error(`年龄小于${guardianAgeValue}岁的患者必须填写监护人信息`)); + } } } - } - callback(); + callback(); // 如果获取不到配置或出现错误,仍然通过验证 + }).catch(error => { + console.error('获取监护人规定年龄配置失败:', error); + callback(); // 获取配置失败时也通过验证 + }); } const data = reactive({ isViewMode: false, form: { - typeCode: '01', - tempFlag: '1', - // genderEnum: 0, + typeCode: '08', // 证件类别,默认为'08'(就诊卡) + birthDate: undefined, + age: undefined, + hukouAddressSelect: undefined, + hukouAddress: undefined, + postalCode: undefined, + companyAddress: undefined, + patientDerived: undefined, }, rules: { name: [{ required: true, message: '姓名不能为空', trigger: 'change' }, @@ -616,7 +639,18 @@ const data = reactive({ genderEnum: [{ required: true, message: '请选择性别', trigger: 'change' }], age: [{ required: true, message: '年龄不能为空', trigger: 'change' }], phone: [{ required: true, message: '联系方式不能为空', trigger: 'change' }], - idCard: [{ required: true, message: '证件号不能为空', trigger: 'change' }], + identifierNo: [{ required: true, message: '就诊卡号不能为空', trigger: 'change' }], + idCard: [ + { required: false, message: '证件号码不能为空', trigger: 'change' }, + { validator: validateIdCard, trigger: 'blur' }, + { validator: validateUniquePatient, trigger: 'blur' } + ], + birthDate: [{ required: false, message: '请选择出生日期', trigger: 'change' }], + // 监护人信息条件验证规则 + guardianName: [{ validator: validateGuardianInfo, trigger: 'blur' }], + guardianRelation: [{ validator: validateGuardianInfo, trigger: 'blur' }], + guardianPhone: [{ validator: validateGuardianInfo, trigger: 'blur' }], + guardianIdNo: [{ validator: validateGuardianInfo, trigger: 'blur' }], }, }); @@ -1271,22 +1305,74 @@ function cancel() { visible.value = false; reset(); } -// 身份证号失去焦点获取年龄和性别 -const onBlur = () => { - if (form.value.typeCode === '01') { - const info = getGenderAndAge(form.value.idCard || ''); - form.value.age = info.age; - form.value.genderEnum = info.gender; +// 处理出生日期变化,自动计算年龄 +function handleBirthDateChange() { + if (form.value.birthDate) { + const birthDate = new Date(form.value.birthDate); + const today = new Date(); + + let age = today.getFullYear() - birthDate.getFullYear(); + const monthDiff = today.getMonth() - birthDate.getMonth(); + + // 计算精确年龄 + if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) { + age--; + } + + form.value.age = age; } -}; -//切换证件类型 -const typeChange = () => { - if (form.value.typeCode === '01') { - const info = getGenderAndAge(form.value.idCard || ''); - form.value.age = info.age; - form.value.genderEnum = info.gender; +} + +// 处理年龄输入,自动计算出生日期 +function handleAgeInput() { + // 提取数字部分 + const ageMatch = form.value.age.match(/\d+/); + if (ageMatch) { + const age = parseInt(ageMatch[0]); + // 移除非数字字符,保留数字和可能的单位 + form.value.age = age ; + + // 计算出生日期 + const today = new Date(); + const birthYear = today.getFullYear() - age; + const birthMonth = today.getMonth(); + const birthDay = today.getDate(); + + const birthDate = new Date(birthYear, birthMonth, birthDay); + + // 格式化为YYYY-MM-DD + const formattedBirthDate = birthDate.toISOString().split('T')[0]; + form.value.birthDate = formattedBirthDate; } -}; +} +watch( + () => form.value.idCard, + (newIdCard) => { + if (newIdCard && newIdCard.length === 18) { + const birthYear = parseInt(newIdCard.substring(6, 10)); + const birthMonth = parseInt(newIdCard.substring(10, 12)); + const birthDay = parseInt(newIdCard.substring(12, 14)); + // 设置出生日期 + form.value.birthDate = `${birthYear}-${birthMonth.toString().padStart(2, '0')}-${birthDay.toString().padStart(2, '0')}`; + const today = new Date(); + const currentYear = today.getFullYear(); + const currentMonth = today.getMonth() + 1; + const currentDay = today.getDate(); + + let age = currentYear - birthYear; + + // 如果当前月份小于出生月份,或者月份相同但当前日期小于出生日期,则年龄减1 + if ( + currentMonth < birthMonth || + (currentMonth === birthMonth && currentDay < birthDay) + ) { + age--; + } + + form.value.age = age ; + } + } +); // 设置查看模式 function setViewMode(isView) { isViewMode.value = isView;