修复人type问题

master
许宏杰 6 months ago
parent c7c0516f64
commit 784004751d

@ -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参数";
}
}

@ -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;

@ -15,6 +15,7 @@
{{ houseData.color }}</span
></ColorCell
>
<div
class="house-is"
style="border: 1px solid #81204e; color: #e73388"
@ -43,6 +44,10 @@
>
退伍军人
</div>
<div class="hose-update">
更新时间{{ houseData.updateTime }}
</div>
</div>
<div class="btn-group">
<div class="btn-gather" v-show="houseData.color == 'NO'">
@ -67,13 +72,15 @@
<div class="data-row">
<div class="row-item">
<div class="row-item-lable">
性別{{ getGender(item.credentialNo) }}
性別{{ filterCarId(item.credentialNo, "性别") }}
</div>
<div class="row-item-value"></div>
</div>
<div class="row-item">
<div class="row-item-lable">身份证号</div>
<div class="row-item-value">{{ item.credentialNo }}</div>
<div class="row-item-value">
{{ item.credentialNo || "-" }}
</div>
</div>
<div class="row-item">
<div class="row-item-lable">户籍</div>
@ -89,7 +96,7 @@
<div class="row-item">
<div class="row-item-lable">年龄</div>
<div class="row-item-value">
{{ calculateAge(item.credentialNo) }}
{{ filterCarId(item.credentialNo, "年龄") }}
</div>
</div>
<div class="row-item">
@ -111,7 +118,7 @@
<div class="row-item">
<div class="row-item-lable">出生年月</div>
<div class="row-item-value">
{{ extractBirthMonth(item.credentialNo) }}
{{ filterCarId(item.credentialNo, "出生年月") }}
</div>
</div>
<div class="row-item">
@ -129,6 +136,14 @@
</div>
<div class="data-row last-row">
<div class="is-list">
<div
class="row-item-value"
:style="{
color: item.color == 'NL' ? '#E73388' : '#00C185',
}"
>
{{ item.color == "NL" ? "租客" : "自住" }}
</div>
<div
class="house-is"
style="border: 1px solid #81204e; color: #e73388"
@ -206,7 +221,8 @@
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="身份证" prop="credentialNo">
<!-- prop="credentialNo" -->
<el-form-item label="身份证">
<el-input v-model="form.credentialNo"></el-input>
</el-form-item>
</el-col>
@ -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;
// 1518
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";
// 1817
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;
}

Loading…
Cancel
Save