修改自动计算证件开始日期以及截止日期的计算逻辑

This commit is contained in:
liu.xiaofeng@ebiz-digits.com
2023-09-20 11:38:41 +08:00
parent 85ff38ec6f
commit af041ddd0c
2 changed files with 78 additions and 158 deletions

View File

@@ -1,167 +1,88 @@
import utilsAge from '@/assets/js/utils/age'
export default { export default {
//计算身份证起始日期 //计算身份证起始日期
getStartDate: function(age, endDate) { getStartDate: function(birthday, endDate) {
let startDate = '' //证件起始日期 let startDate = '' //证件起始日期
let thisDate = new Date() //当年日期 let startage = ''
let thisyear = thisDate.getFullYear() //当前年份 let endage = utilsAge.getAge(birthday, new Date(endDate))
if (age < 16) {
/** /**
* @Author: LiuXiaoFeng * @Author: LiuXiaoFeng
* @Description: 16周岁以下的证件有效期为5年 * @Description: 未满16周岁的公民申领的居民身份证有效期为5年
* @Date: 2023/7/4 * @Date: 2023/7/4
**/ **/
startDate = String(Number(endDate.slice(0,4)) - 5) + endDate.slice(4,11) if (endage - 5 < 16) {
} else if (age >= 16 && age <= 21) { return startDate = String(Number(endDate.slice(0,4)) - 5) + endDate.slice(4,11)
}
/** /**
* @Author: LiuXiaoFeng * @Author: LiuXiaoFeng
* @Description: 16周岁~21周岁的证件有效期为10年或5年 * @Description: 年满16周岁至25周岁的公民申领的居民身份证有效期为10年
* @Date: 2023/7/4 * @Date: 2023/7/4
**/ **/
if (age - (10 - (endDate.slice(0,4) - thisyear)) < 16 ) { else if (endage - 5 >= 16 && endage - 10 <= 25) {
/**
* @Author: LiuXiaoFeng
* @Description: 如果证件有效期为10年 根据证件截止日期 判断10年前的年龄 如果小于16周岁 那么证件有效期就是5年
* @Date: 2023/7/5
**/
startDate = String(Number(endDate.slice(0,4)) - 5) + endDate.slice(4,11)
} else {
startDate = String(Number(endDate.slice(0,4)) - 10) + endDate.slice(4,11) startDate = String(Number(endDate.slice(0,4)) - 10) + endDate.slice(4,11)
} startage = utilsAge.getAge(birthday, new Date(startDate))
} else if(age >= 22 && age <= 25) { if(startage >= 16 && startage <= 25){
/**
* @Author: LiuXiaoFeng
* @Description: 22周岁~25周岁的证件有效期为10年
* @Date: 2023/7/4
**/
startDate = String(Number(endDate.slice(0,4)) - 10) + endDate.slice(4,11)
} else if (age >= 26 && age <= 35) {
/**
* @Author: LiuXiaoFeng
* @Description: 26周岁~35周岁的证件有效期为20年或10年
* @Date: 2023/7/4
**/
if (age - (20 - (endDate.slice(0,4) - thisyear)) < 26 ) {
/**
* @Author: LiuXiaoFeng
* @Description: 如果证件有效期为20年 根据证件截止日期 判断20年前的年龄 如果小于26周岁 那么证件有效期就是10年
* @Date: 2023/7/5
**/
startDate = String(Number(endDate.slice(0,4)) - 10) + endDate.slice(4,11)
} else {
startDate = String(Number(endDate.slice(0,4)) - 20) + endDate.slice(4,11)
}
} else if (age >= 36 && age <= 45) {
/**
* @Author: LiuXiaoFeng
* @Description: 36周岁~45周岁的证件有效期为20年
* @Date: 2023/7/4
**/
startDate = String(Number(endDate.slice(0,4)) + 20) + endDate.slice(4,11)
} else if (age >= 46 && age <= 65) {
/**
* @Author: LiuXiaoFeng
* @Description: 46周岁~65周岁的证件有效期为20年或长期
* @Date: 2023/7/4
**/
if (age - (20 - (endDate.slice(0,4) - thisyear)) < 46 ) {
/**
* @Author: LiuXiaoFeng
* @Description: 如果证件有效期为20年 根据证件截止日期 判断20年前的年龄 如果小于46周岁 那么证件有效期就是20年
* @Date: 2023/7/5
**/
startDate = String(Number(endDate.slice(0,4)) - 20) + endDate.slice(4,11)
}
} else if (age > 65) {
/**
* @Author: LiuXiaoFeng
* @Description: 65周岁以上的证件有效期为长期
* @Date: 2023/7/4
**/
}
return startDate return startDate
}
}
/**
* @Author: LiuXiaoFeng
* @Description: 年满26周岁至45周岁的公民申领的居民身份证有效期为20年
* @Date: 2023/7/4
**/
else if(endage - 10 >= 26 && endage - 20 <= 45) {
startDate = String(Number(endDate.slice(0,4)) - 20) + endDate.slice(4,11)
startage = utilsAge.getAge(birthday, new Date(startDate))
if(startage >= 26 && startage <= 45){
return startDate
}
}
/**
* @Author: LiuXiaoFeng
* @Description: 年满46周岁的公民申领居民身份证有效期为长期
* @Date: 2023/7/4
**/
else if (endage - 20 >= 46) {
return startDate
}
}, },
//计算身份证截止日期 //计算身份证截止日期
getEndDate: function(age, startDate) { getEndDate: function(birthday, startDate) {
let endDate = '' //证件截止日期 let endDate = '' //证件截止日期
let thisDate = new Date() //当年日期 let startage = utilsAge.getAge(birthday, new Date(startDate))
let thisyear = thisDate.getFullYear() //当前年份
if (age < 16) {
/** /**
* @Author: LiuXiaoFeng * @Author: LiuXiaoFeng
* @Description: 16周岁以下的证件有效期为5年 * @Description: 未满16周岁的公民申领的居民身份证有效期为5年
* @Date: 2023/7/4 * @Date: 2023/7/4
**/ **/
endDate = String(Number(startDate.slice(0,4)) + 5) + startDate.slice(4,11) if (startage < 16) {
} else if (age >= 16 && age <= 21) { return endDate = String(Number(startDate.slice(0, 4)) + 5) + startDate.slice(4, 11)
/**
* @Author: LiuXiaoFeng
* @Description: 16周岁~21周岁的证件有效期为10年或5年
* @Date: 2023/7/4
**/
if (age - (thisyear - startDate.slice(0,4)) < 16 ) {
/**
* @Author: LiuXiaoFeng
* @Description: 根据证件起始日期计算办证时年龄 如果办证时年龄小于16周岁 那么证件有效期就是5年
* @Date: 2023/7/5
**/
endDate = String(Number(startDate.slice(0,4)) + 5) + startDate.slice(4,11)
} else {
endDate = String(Number(startDate.slice(0,4)) + 10) + startDate.slice(4,11)
} }
} else if(age >= 22 && age <= 25) {
/** /**
* @Author: LiuXiaoFeng * @Author: LiuXiaoFeng
* @Description: 22周岁~25周岁的证有效期为10年 * @Description: 年满16周岁25周岁的公民申领的居民身份证有效期为10年
* @Date: 2023/7/4 * @Date: 2023/7/4
**/ **/
endDate = String(Number(startDate.slice(0,4)) + 10) + startDate.slice(4,11) else if (startage >= 16 && startage <= 25) {
} else if (age >= 26 && age <= 35) { return endDate = String(Number(startDate.slice(0, 4)) + 10) + startDate.slice(4, 11)
/**
* @Author: LiuXiaoFeng
* @Description: 26周岁~35周岁的证件有效期为20年或10年
* @Date: 2023/7/4
**/
if (age - (thisyear - startDate.slice(0,4)) < 26 ) {
/**
* @Author: LiuXiaoFeng
* @Description: 根据证件起始日期计算办证时年龄 如果办证时年龄小于26周岁 那么证件有效期就是10年
* @Date: 2023/7/5
**/
endDate = String(Number(startDate.slice(0,4)) + 10) + startDate.slice(4,11)
} else {
endDate = String(Number(startDate.slice(0,4)) + 20) + startDate.slice(4,11)
} }
} else if (age >= 36 && age <= 45) {
/** /**
* @Author: LiuXiaoFeng * @Author: LiuXiaoFeng
* @Description: 36周岁~45周岁的证有效期为20年 * @Description: 年满26周岁45周岁的公民申领的居民身份证有效期为20年
* @Date: 2023/7/4 * @Date: 2023/7/4
**/ **/
endDate = String(Number(startDate.slice(0,4)) + 20) + startDate.slice(4,11) else if (startage >= 26 && startage <= 45) {
} else if (age >= 46 && age <= 65) { return endDate = String(Number(startDate.slice(0, 4)) + 20) + startDate.slice(4, 11)
/**
* @Author: LiuXiaoFeng
* @Description: 46周岁~65周岁的证件有效期为20年或长期
* @Date: 2023/7/4
**/
if (age - (thisyear - startDate.slice(0,4)) < 46 ) {
/**
* @Author: LiuXiaoFeng
* @Description: 根据证件起始日期计算办证时年龄 如果办证时年龄小于46周岁 那么证件有效期就是20年
* @Date: 2023/7/5
**/
endDate = String(Number(startDate.slice(0,4)) + 20) + startDate.slice(4,11)
} }
} else if (age > 65) {
/** /**
* @Author: LiuXiaoFeng * @Author: LiuXiaoFeng
* @Description: 65周岁以上的证件有效期为长期 * @Description: 年满46周岁的公民申领居民身份证有效期为长期
* @Date: 2023/7/4 * @Date: 2023/7/4
**/ **/
} else if (startage > 65) {
return endDate return endDate
} }
}
} }

View File

@@ -860,7 +860,7 @@ export default {
// 长期按钮是否禁用 // 长期按钮是否禁用
this.effectiveDateTypeAble = age <= 45 this.effectiveDateTypeAble = age <= 45
if(this.userInfo.birthday){ if(this.userInfo.birthday){
this.userInfo.certiexpiredate = countCredentialValidity.getEndDate(age,val) this.userInfo.certiexpiredate = countCredentialValidity.getEndDate(this.userInfo.birthday,val)
} }
} }
} }
@@ -876,9 +876,8 @@ export default {
} }
//身份证证件类型的判断 //身份证证件类型的判断
if (this.userInfo.idType == '1') { if (this.userInfo.idType == '1') {
let age = utilsAge.getAge(this.userInfo.birthday, new Date())
if(this.userInfo.birthday){ if(this.userInfo.birthday){
this.userInfo.certificateValidate = countCredentialValidity.getStartDate(age,val) this.userInfo.certificateValidate = countCredentialValidity.getStartDate(this.userInfo.birthday,val)
} }
} }
} }