浏览代码

花名册-身份证验证,绑定生日和性别

lizhenhao 2 年之前
父节点
当前提交
1ca8ddef8f
共有 3 个文件被更改,包括 49 次插入1 次删除
  1. 2 0
      src/main.js
  2. 31 0
      src/utils/common.js
  3. 16 1
      src/views/modules/roster/RosterForm.vue

+ 2 - 0
src/main.js

@@ -14,6 +14,7 @@ import '@/utils/filter'
 import validator from '@/utils/validator'
 import validator from '@/utils/validator'
 import validatorXG from '@/utils/validatorXG'
 import validatorXG from '@/utils/validatorXG'
 import validateXG from '@/utils/validateXG'
 import validateXG from '@/utils/validateXG'
+import commonJS from '@/utils/common'
 import cloneDeep from 'lodash/cloneDeep'
 import cloneDeep from 'lodash/cloneDeep'
 import lodash from 'lodash/object'
 import lodash from 'lodash/object'
 import axios from 'axios'
 import axios from 'axios'
@@ -153,6 +154,7 @@ Vue.prototype.$axios = axios
 Vue.prototype.validator = validator
 Vue.prototype.validator = validator
 Vue.prototype.validatorXG = validatorXG
 Vue.prototype.validatorXG = validatorXG
 Vue.prototype.validateXG = validateXG
 Vue.prototype.validateXG = validateXG
+Vue.prototype.commonJS = commonJS
 Vue.prototype.lodash = lodash
 Vue.prototype.lodash = lodash
 Vue.prototype.moment = moment
 Vue.prototype.moment = moment
 Vue.prototype.deepClone = utils.deepClone
 Vue.prototype.deepClone = utils.deepClone

+ 31 - 0
src/utils/common.js

@@ -174,6 +174,37 @@ export default {
     } else {
     } else {
       return true;
       return true;
     }
     }
+  },
+  decomposeIdCard(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)
+      // eslint-disable-next-line no-mixed-operators
+      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)
+      // eslint-disable-next-line no-mixed-operators
+      if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day) age++
+    }
+
+    if (sex % 2 === 0) {
+      sex = '2'  // 性别代码 1代表男,2代表女,暂时不涉及其他类型性别
+    } else {
+      sex = '1'
+    }
+    return {age, sex, birth}
   }
   }
 
 
 }
 }

+ 16 - 1
src/views/modules/roster/RosterForm.vue

@@ -129,7 +129,7 @@
             <el-form-item label="证件号" prop="idCard"
             <el-form-item label="证件号" prop="idCard"
                           :rules="[{required: true, message: '证件号不能为空', trigger: 'blur'}
                           :rules="[{required: true, message: '证件号不能为空', trigger: 'blur'}
                  ]">
                  ]">
-              <el-input v-model="inputForm.idCard" placeholder="请填写证件号"     clearable></el-input>
+              <el-input v-model="inputForm.idCard" placeholder="请填写证件号"   @blur="blurIdCard"  clearable></el-input>
             </el-form-item>
             </el-form-item>
           </el-col>
           </el-col>
           <el-col :span="12">
           <el-col :span="12">
@@ -1515,6 +1515,21 @@
             item.expireDate = this.moment(item.expireDate).format('YYYY-MM-DD HH:mm:ss')
             item.expireDate = this.moment(item.expireDate).format('YYYY-MM-DD HH:mm:ss')
           }
           }
         })
         })
+      },
+      blurIdCard () {
+        if (!this.commonJS.isEmpty(this.inputForm.certificatesType)) {
+          if (this.inputForm.certificatesType === '1') {
+            if (!this.commonJS.isEmpty(this.inputForm.idCard)) {
+              if (!this.commonJS.isIDCardNo(this.inputForm.idCard)) {
+                this.$message.error('居民身份证填写格式不正确')
+                return
+              }
+              const info = this.commonJS.decomposeIdCard(this.inputForm.idCard)
+              this.inputForm.birthDate = info.birth
+              this.inputForm.sex = info.sex
+            }
+          }
+        }
       }
       }
     }
     }
   }
   }