diff --git a/src/utils/myFuntion.js b/src/utils/myFuntion.js index 74b076c..05ccebb 100644 --- a/src/utils/myFuntion.js +++ b/src/utils/myFuntion.js @@ -54,3 +54,51 @@ function checkType(value) { return "neither"; } } + +export function validateAndParseIDCard(idCard, type) { + // 验证身份证号格式 + const idCardPattern = + /^[1-9]\d{5}(18|19|20)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}([0-9Xx])$/; + if (!idCardPattern.test(idCard)) { + return "-"; + } + + // 提取出生年月 + const birthYear = + idCard.length === 18 + ? idCard.substring(6, 10) + : `19${idCard.substring(6, 8)}`; + const birthMonth = + idCard.length === 18 ? idCard.substring(10, 12) : idCard.substring(8, 10); + const birthDay = + idCard.length === 18 ? idCard.substring(12, 14) : idCard.substring(10, 12); + + // 计算年龄 + const today = new Date(); + const birthDate = new Date(`${birthYear}-${birthMonth}-${birthDay}`); + let age = today.getFullYear() - birthDate.getFullYear(); + if ( + today.getMonth() < birthDate.getMonth() || + (today.getMonth() === birthDate.getMonth() && + today.getDate() < birthDate.getDate()) + ) { + age--; + } + + // 提取性别(第17位,奇数为男,偶数为女) + const genderCode = + idCard.length === 18 ? idCard.substring(16, 17) : idCard.substring(14, 15); + const gender = genderCode % 2 === 0 ? "女" : "男"; + + // 根据type返回对应的信息 + switch (type) { + case "年龄": + return age; + case "性别": + return gender; + case "出生年月": + return `${birthYear}-${birthMonth}-${birthDay}`; + default: + return "无效的type参数"; + } +} diff --git a/src/views/components/xiaoqu/building.vue b/src/views/components/xiaoqu/building.vue index f43ed7b..4a4aaa6 100644 --- a/src/views/components/xiaoqu/building.vue +++ b/src/views/components/xiaoqu/building.vue @@ -94,10 +94,10 @@ export default { watch: { "queryParamsXiaoqu.buildingId"(newValue, oldValue) { if (newValue) { - this.reset(); this.getBuildingInfo(); this.getBuildingList(); } else { + this.reset(); this.show = false; } }, @@ -108,7 +108,7 @@ export default { created() {}, methods: { reset() { - this.show = false; + // this.show = false; this.info = {}; this.list = []; this.currentIndex = 0; @@ -137,7 +137,6 @@ export default { async getBuildingInfo() { let info = await getBuilding(this.queryParamsXiaoqu.buildingId); this.info = info.data; - this.show = true; }, async getBuildingList() { let res = await getNum({ @@ -145,6 +144,8 @@ export default { }); this.list = res.data; + this.show = true; + // this.list = this.groupedRooms(res.data); // let num = 0; // this.list.forEach((item) => { @@ -209,7 +210,7 @@ export default { .building-house-container { padding-top: 85px; position: relative; - min-width: 135px; + //min-width: 135px; // max-width: 700px; // overflow-x: auto; // overflow-y: hidden; diff --git a/src/views/components/xiaoqu/house.vue b/src/views/components/xiaoqu/house.vue index 36ebfac..220cdd8 100644 --- a/src/views/components/xiaoqu/house.vue +++ b/src/views/components/xiaoqu/house.vue @@ -15,6 +15,7 @@ {{ houseData.color }} +