diff --git a/src/assets/js/utils/countCredentialValidity.js b/src/assets/js/utils/countCredentialValidity.js index ed7128a9d..ce6843faa 100644 --- a/src/assets/js/utils/countCredentialValidity.js +++ b/src/assets/js/utils/countCredentialValidity.js @@ -1,167 +1,88 @@ +import utilsAge from '@/assets/js/utils/age' export default { //计算身份证起始日期 - getStartDate: function(age, endDate) { + getStartDate: function(birthday, endDate) { let startDate = '' //证件起始日期 - let thisDate = new Date() //当年日期 - let thisyear = thisDate.getFullYear() //当前年份 + let startage = '' + let endage = utilsAge.getAge(birthday, new Date(endDate)) - if (age < 16) { - /** - * @Author: LiuXiaoFeng - * @Description: 16周岁以下的证件有效期为5年 - * @Date: 2023/7/4 - **/ - startDate = String(Number(endDate.slice(0,4)) - 5) + endDate.slice(4,11) - } else if (age >= 16 && age <= 21) { - /** - * @Author: LiuXiaoFeng - * @Description: 16周岁~21周岁的证件有效期为10年或5年 - * @Date: 2023/7/4 - **/ - if (age - (10 - (endDate.slice(0,4) - thisyear)) < 16 ) { - /** - * @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) - } - } else if(age >= 22 && age <= 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 - **/ + /** + * @Author: LiuXiaoFeng + * @Description: 未满16周岁的公民申领的居民身份证有效期为5年 + * @Date: 2023/7/4 + **/ + if (endage - 5 < 16) { + return startDate = String(Number(endDate.slice(0,4)) - 5) + endDate.slice(4,11) + } + /** + * @Author: LiuXiaoFeng + * @Description: 年满16周岁至25周岁的公民申领的居民身份证有效期为10年 + * @Date: 2023/7/4 + **/ + else if (endage - 5 >= 16 && endage - 10 <= 25) { + startDate = String(Number(endDate.slice(0,4)) - 10) + endDate.slice(4,11) + startage = utilsAge.getAge(birthday, new Date(startDate)) + if(startage >= 16 && startage <= 25){ + 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 } - return startDate }, //计算身份证截止日期 - getEndDate: function(age, startDate) { + getEndDate: function(birthday, startDate) { let endDate = '' //证件截止日期 - let thisDate = new Date() //当年日期 - let thisyear = thisDate.getFullYear() //当前年份 - - if (age < 16) { - /** - * @Author: LiuXiaoFeng - * @Description: 16周岁以下的证件有效期为5年 - * @Date: 2023/7/4 - **/ - endDate = String(Number(startDate.slice(0,4)) + 5) + startDate.slice(4,11) - } else if (age >= 16 && age <= 21) { - /** - * @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 - * @Description: 22周岁~25周岁的证件有效期为10年 - * @Date: 2023/7/4 - **/ - endDate = String(Number(startDate.slice(0,4)) + 10) + startDate.slice(4,11) - } else if (age >= 26 && age <= 35) { - /** - * @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 - * @Description: 36周岁~45周岁的证件有效期为20年 - * @Date: 2023/7/4 - **/ - endDate = String(Number(startDate.slice(0,4)) + 20) + startDate.slice(4,11) - } else if (age >= 46 && age <= 65) { - /** - * @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 - * @Description: 65周岁以上的证件有效期为长期 - * @Date: 2023/7/4 - **/ + let startage = utilsAge.getAge(birthday, new Date(startDate)) + /** + * @Author: LiuXiaoFeng + * @Description: 未满16周岁的公民申领的居民身份证有效期为5年 + * @Date: 2023/7/4 + **/ + if (startage < 16) { + return endDate = String(Number(startDate.slice(0, 4)) + 5) + startDate.slice(4, 11) + } + /** + * @Author: LiuXiaoFeng + * @Description: 年满16周岁至25周岁的公民申领的居民身份证有效期为10年 + * @Date: 2023/7/4 + **/ + else if (startage >= 16 && startage <= 25) { + return endDate = String(Number(startDate.slice(0, 4)) + 10) + startDate.slice(4, 11) + } + /** + * @Author: LiuXiaoFeng + * @Description: 年满26周岁至45周岁的公民申领的居民身份证有效期为20年 + * @Date: 2023/7/4 + **/ + else if (startage >= 26 && startage <= 45) { + return endDate = String(Number(startDate.slice(0, 4)) + 20) + startDate.slice(4, 11) + } + /** + * @Author: LiuXiaoFeng + * @Description: 年满46周岁的公民申领居民身份证有效期为长期 + * @Date: 2023/7/4 + **/ + else if (startage > 65) { + return endDate } - return endDate } } diff --git a/src/views/ebiz/sale/InsuredInfo.vue b/src/views/ebiz/sale/InsuredInfo.vue index bd383aa62..52db575eb 100644 --- a/src/views/ebiz/sale/InsuredInfo.vue +++ b/src/views/ebiz/sale/InsuredInfo.vue @@ -860,7 +860,7 @@ export default { // 长期按钮是否禁用 this.effectiveDateTypeAble = age <= 45 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') { - let age = utilsAge.getAge(this.userInfo.birthday, new Date()) if(this.userInfo.birthday){ - this.userInfo.certificateValidate = countCredentialValidity.getStartDate(age,val) + this.userInfo.certificateValidate = countCredentialValidity.getStartDate(this.userInfo.birthday,val) } } }