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 }} +
退伍军人
+ +
+ 更新时间:{{ houseData.updateTime }} +
@@ -67,13 +72,15 @@
- 性別:{{ getGender(item.credentialNo) }} + 性別:{{ filterCarId(item.credentialNo, "性别") }}
身份证号:
-
{{ item.credentialNo }}
+
+ {{ item.credentialNo || "-" }} +
户籍:
@@ -89,7 +96,7 @@
年龄:
- {{ calculateAge(item.credentialNo) }}岁 + {{ filterCarId(item.credentialNo, "年龄") }} 岁
@@ -111,7 +118,7 @@
出生年月:
- {{ extractBirthMonth(item.credentialNo) }} + {{ filterCarId(item.credentialNo, "出生年月") }}
@@ -129,6 +136,14 @@
+
+ {{ item.color == "NL" ? "租客" : "自住" }} +
- + + @@ -281,11 +297,19 @@ import { } from "@/api/taicangpop/person.js"; import { pxToVw, handleColor } from "@/utils/myFuntion.js"; import ColorCell from "@/components/ColorCell"; - +import { validateAndParseIDCard } from "@/utils/myFuntion.js"; export default { components: { ColorCell }, dicts: ["b_census_color_type", "b_flow_color_type"], data() { + var validateNumber = (rule, value, callback) => { + console.log("value:" + value); + if (!/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/.test(value)) { + callback(new Error("手机号只能为数字!")); + } else { + callback(); + } + }; return { houseData: {}, form: { @@ -309,14 +333,11 @@ export default { credentialNo: [ { required: true, message: "身份证不能为空", trigger: "blur" }, ], - phone: [{ required: true, message: "手机号不能为空", trigger: "blur" }], - workunit: [ - { - required: true, - message: "工作单位不能为空", - trigger: "change", - }, + phone: [ + { required: true, message: "手机号不能为空", trigger: "blur" }, + { validator: validateNumber, trigger: "blur" }, ], + color: [{ required: true, message: "分色不能为空", trigger: "change" }], }, multiple: [], @@ -362,6 +383,7 @@ export default { houseId: undefined, buildingId: undefined, deptId: undefined, + type: undefined, }; this.multiple = []; }, @@ -404,6 +426,12 @@ export default { this.form.isX = this.multiple.some((item) => item == "重点人群") ? 1 : 0; + + if (this.form.color == "HZ" || this.form.color == "HO") { + this.form.type = 1; + } else { + this.form.type = 2; + } if (this.form.id != null) { updatePerson(this.form).then((response) => { this.open = false; @@ -431,11 +459,11 @@ export default { }, filterIcon(credentialNo) { - let sex = this.getGender(credentialNo); - if (sex == "男") { - return require("@/assets/images/ui/img_man@2x.png"); - } else { + let sex = validateAndParseIDCard(credentialNo, "性别"); + if (sex == "女") { return require("@/assets/images/ui/img_woman@2x.png"); + } else { + return require("@/assets/images/ui/img_man@2x.png"); } }, @@ -456,109 +484,13 @@ export default { houseId: this.houseItem.id, deptId: this.houseItem.deptId, }); - this.list = handleColor(res.rows); this.total = res.total; this.show = true; }, - isValidID(id) { - // 校验长度和基本格式 - if (!/^\d{15}|\d{18}$/.test(id)) return false; - - // 将15位升级为18位 - if (id.length === 15) { - id = - id.substr(0, 6) + "19" + id.substr(6) + this.calculateCheckDigit(id); - } - - // 验证18位身份证的校验位 - return this.validateID18(id); - }, - - validateID18(id) { - if (!/^\d{17}[\dXx]$/.test(id)) return false; - - // 校验码计算 - const checkDigits = "10X98765432"; - const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; - let sum = 0; - - for (let i = 0; i < 17; i++) { - sum += id[i] * weights[i]; - } - - const checkDigit = checkDigits[sum % 11]; - return checkDigit.toUpperCase() === id[17].toUpperCase(); - }, - - calculateCheckDigit(id) { - const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; - const checkDigits = "10X98765432"; - let sum = 0; - - for (let i = 0; i < id.length; i++) { - sum += id[i] * weights[i]; - } - - return checkDigits[sum % 11]; - }, - - calculateAge(id) { - if (!this.isValidID(id)) return "Invalid ID"; - - let birthDate; - if (id.length === 18) { - // 从18位身份证中提取出生日期 - birthDate = id.substr(6, 8); - } else if (id.length === 15) { - // 从15位身份证中提取出生日期 - birthDate = "19" + id.substr(6, 6); - } else { - return "Invalid ID length"; - } - - // 格式化出生日期 - birthDate = birthDate.replace(/(.{4})(.{2})/, "$1-$2-"); - const birth = new Date(birthDate); - const today = new Date(); - let age = today.getFullYear() - birth.getFullYear(); - - // 计算是否已过生日 - if ( - today.getMonth() + 1 < birth.getMonth() + 1 || - (today.getMonth() + 1 === birth.getMonth() + 1 && - today.getDate() < birth.getDate()) - ) { - age--; - } - - return age; - }, - - extractBirthMonth(id) { - if (!this.isValidID(id)) return "Invalid ID"; - - let birthDate; - if (id.length === 18) { - // 从18位身份证中提取出生日期 - birthDate = id.substr(6, 8); - } else if (id.length === 15) { - // 从15位身份证中提取出生日期 - birthDate = "19" + id.substr(6, 6); - } else { - return "Invalid ID length"; - } - - // 格式化出生日期为 YYYY-MM - birthDate = birthDate.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2"); - return birthDate; - }, - - getGender(id) { - if (!this.isValidID(id)) return "Invalid ID"; - // 在18位身份证中,第17位为性别标识 - return parseInt(id[16]) % 2 === 0 ? "女" : "男"; + filterCarId(carId, type) { + return validateAndParseIDCard(carId, type); }, }, }; @@ -685,7 +617,8 @@ div { margin-right: 10px; } - .house-name { + .house-name, + .hose-update { font-size: 18px; color: #ffffff; }