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 961cea09..04ed8d17 100644 --- a/openhis-ui-vue3/src/views/charge/outpatientregistration/components/patientAddDialog.vue +++ b/openhis-ui-vue3/src/views/charge/outpatientregistration/components/patientAddDialog.vue @@ -286,6 +286,36 @@ const title = ref('新增患者'); const visible = ref(false); const emits = defineEmits(['submit']); // 声明自定义事件 + +// 身份证号码校验函数 +const validateIdCard = (rule, value, callback) => { + if (!value) { + callback(); + return; + } + + // 18位身份证正则 + const reg = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/; + if (!reg.test(value)) { + return callback(new Error('请输入正确的18位身份证号码')); + } + + // 校验码验证(第18位) + const factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; + const parity = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; + let sum = 0; + for (let i = 0; i < 17; i++) { + sum += parseInt(value.charAt(i)) * factor[i]; + } + const last = parity[sum % 11]; + if (last !== value.charAt(17).toUpperCase()) { + return callback(new Error('身份证校验码错误')); + } + + callback(); // 校验通过 +} + + const data = reactive({ isViewMode: false, form: { @@ -296,9 +326,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' }, + { validator: validateIdCard, trigger: 'blur' } + ], }, }); + + + + + const { queryParams, form, rules, isViewMode } = toRefs(data); const props = defineProps({ @@ -485,7 +524,7 @@ defineExpose({ margin-right: 10px !important; } -/* 使用深度选择器 */ +/* 使用深度选择器 */ .custom-label-spacing :deep(.el-form-item__label) { line-height: 1.2; /* 调整行间距 */ margin-bottom: 4px; /* 调整 label 和输入框之间的间距 */