diff --git a/src/utils/index.js b/src/utils/index.js index fe742c9a..c2232ac7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -115,3 +115,33 @@ export function dateFormats(fmt, date) { } return fmt } +// 根据身份证计算出生日期,性别,年龄 +export function computedCard(idCard) { + let sex = null; + let birth = null; + let myDate = new Date(); + let month = myDate.getMonth() + 1; + let day = myDate.getDate(); + let age = 0; + + if(idCard.length===18){ + age = myDate.getFullYear() - idCard.substring(6, 10) - 1; + sex = idCard.substring(16,17); + birth = idCard.substring(6,10)+"-"+idCard.substring(10,12)+"-"+idCard.substring(12,14); + if (idCard.substring(10, 12) < month || idCard.substring(10, 12) === month && idCard.substring(12, 14) <= day) age++; + + } + if(idCard.length===15){ + age = myDate.getFullYear() - idCard.substring(6, 8) - 1901; + sex = idCard.substring(13,14); + birth = "19"+idCard.substring(6,8)+"-"+idCard.substring(8,10)+"-"+idCard.substring(10,12); + if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day) age++; + } + + if(sex%2 === 0) + sex = '0'; // 性别代码 1代表男,0代表女,暂时不涉及其他类型性别 + else + sex = '1'; + return {age , sex, birth} +} + diff --git a/src/views/components/editResi.vue b/src/views/components/editResi.vue index d7afc877..fba7172b 100644 --- a/src/views/components/editResi.vue +++ b/src/views/components/editResi.vue @@ -33,7 +33,7 @@ - +
diff --git a/src/views/components/resiForm.vue b/src/views/components/resiForm.vue index 506c2265..6ed432b4 100644 --- a/src/views/components/resiForm.vue +++ b/src/views/components/resiForm.vue @@ -32,7 +32,7 @@ - +
@@ -99,48 +99,7 @@
- + @@ -158,6 +117,7 @@ size="small" clearable placeholder="请输入内容" + @blur="handleValidBlur(n)" > import { isCard, isMobile } from '@/utils/validate' +import { computedCard } from '@/utils/index' export default { name: 'resiForm', @@ -525,6 +486,14 @@ export default { // } }) }, + handleValidBlur(n) { + console.log('n---', n) + if (n.columnName !== 'ID_CARD') return + if (!isCard(this.form.ID_CARD)) return + const { sex, birth } = computedCard(this.form.ID_CARD) + this.form.BIRTHDAY = birth + this.form.GENDER = sex == 1 ? '1' : '2' + }, handleOpenSearch () { this.openSearch = !this.openSearch }, diff --git a/src/views/components/resiSearch.vue b/src/views/components/resiSearch.vue index 1c2cd549..6cc4a41a 100644 --- a/src/views/components/resiSearch.vue +++ b/src/views/components/resiSearch.vue @@ -28,7 +28,7 @@
-
所属小区
+
所属房屋