Commit 25bc000b authored by wangxl's avatar wangxl

3333

parent f49f987c
...@@ -97,9 +97,9 @@ export const routes = [ ...@@ -97,9 +97,9 @@ export const routes = [
}, },
{ {
path: '/unitInfo', path: '/unitInfo',
name: 'personInfo', name: 'unitInfo',
component: Layout, component: Layout,
meta: { title: '个人设置', icon: 'el-icon-user' }, meta: { title: '单位设置', icon: 'el-icon-user' },
hidden: false, hidden: false,
children: [ children: [
{ path: '/unit/info', name: '单位基础信息设置', component: () => import('@/views/basicSetting/unit/index.vue'), meta: { title: '个人设置', icon: '', noCache: true } }, { path: '/unit/info', name: '单位基础信息设置', component: () => import('@/views/basicSetting/unit/index.vue'), meta: { title: '个人设置', icon: '', noCache: true } },
...@@ -113,8 +113,8 @@ export const routes = [ ...@@ -113,8 +113,8 @@ export const routes = [
hidden: false, hidden: false,
children: [ children: [
{ path: '/report/project', name: '项目申报', component: () => import('@/views/report/project/Index.vue'), meta: { title: '项目申报', icon: '', noCache: true } }, { path: '/report/project', name: '项目申报', component: () => import('@/views/report/project/Index.vue'), meta: { title: '项目申报', icon: '', noCache: true } },
{ path: '/report/task', name: '任务书填报', component: () => import('@/views/report/task/Index.vue'), meta: { title: '任务书填报', icon: '', noCache: true } }, { path: '/report/task', name: '任务书填报1', component: () => import('@/views/report/task/Index.vue'), meta: { title: '任务书填报1', icon: '', noCache: true } },
{ path: '/report/projectTask', name: '任务书填报', component: () => import('@/views/report/task/projectTask.vue'), meta: { title: '项目任务书', icon: '', noCache: true } }, { path: '/report/projectTask', name: '任务书填报2', component: () => import('@/views/report/task/projectTask.vue'), meta: { title: '任务书填报2', icon: '', noCache: true } },
{ path: '/report/check', name: '中期考核填报', component: () => import('@/views/report/check/Index.vue'), meta: { title: '中期考核填报', icon: '', noCache: true } }, { path: '/report/check', name: '中期考核填报', component: () => import('@/views/report/check/Index.vue'), meta: { title: '中期考核填报', icon: '', noCache: true } },
{ path: '/report/conclusion', name: '项目结题', component: () => import('@/views/conclusion/index.vue'), meta: { title: '项目结题', icon: '', noCache: true } }, { path: '/report/conclusion', name: '项目结题', component: () => import('@/views/conclusion/index.vue'), meta: { title: '项目结题', icon: '', noCache: true } },
{ path: '/project/create', name: '项目创建', component: () => import('@/views/report/project/components/projectCreate'), meta: { title: '项目创建', icon: '', noCache: true } }, { path: '/project/create', name: '项目创建', component: () => import('@/views/report/project/components/projectCreate'), meta: { title: '项目创建', icon: '', noCache: true } },
......
...@@ -8,7 +8,12 @@ ...@@ -8,7 +8,12 @@
<up-load @beforeUpload="beforeUpload" /> <up-load @beforeUpload="beforeUpload" />
</div> </div>
<div style="width:100%;height: calc(100% - 72px);overflow: auto;"> <div style="width:100%;height: calc(100% - 72px);overflow: auto;">
<a-table :dataSource="tableData" :columns="columns" rowKey="index" :pagination="false" :loading="loading" bordered size="small"> <a-table :dataSource="tableData" :columns="columns" :pagination="false" :loading="loading" bordered size="small">
<template slot="msg" slot-scope="record">
<span v-if="!!record.msg " style="color: red;">
{{ record.msg }}
</span>
</template>
</a-table> </a-table>
</div> </div>
<div style="text-align:center;width:100%; height: 36px;"> <div style="text-align:center;width:100%; height: 36px;">
...@@ -19,6 +24,8 @@ ...@@ -19,6 +24,8 @@
</template> </template>
<script> <script>
import { isEmptyParams, readExcelFile, personGender, personBirthday, checkIdentitytionId, checkEmail, checkPhone } from "@/views/utils/common" import { isEmptyParams, readExcelFile, personGender, personBirthday, checkIdentitytionId, checkEmail, checkPhone } from "@/views/utils/common"
import { checkCertId } from "@/views/utils/validate"
import { getTitle, getDegree } from "@/views/report/project/config"
import moment from "moment" import moment from "moment"
export default { export default {
...@@ -32,14 +39,16 @@ export default { ...@@ -32,14 +39,16 @@ export default {
{ title: "职称", dataIndex: "titleName", align: 'center' }, { title: "职称", dataIndex: "titleName", align: 'center' },
{ title: "学位", dataIndex: "degreeName", align: 'center' }, { title: "学位", dataIndex: "degreeName", align: 'center' },
{ title: '工作单位', dataIndex: 'workUnit', align: 'center' }, { title: '工作单位', dataIndex: 'workUnit', align: 'center' },
{ title: '电话', dataIndex: 'mobile', align: 'center' }, { title: '手机号', dataIndex: 'mobile', align: 'center' },
{ title: '电子邮箱', dataIndex: 'email', align: 'center' }, { title: '电子邮箱', dataIndex: 'email', align: 'center' },
{ title: '证件号码', dataIndex: 'certId', align: 'center' }, { title: '证件号码', dataIndex: 'certId', align: 'center' },
{ title: '项目分工', dataIndex: 'projWork', align: 'center' }, { title: '项目分工', dataIndex: 'projWork', align: 'center' },
{ title: '每年工作(月)', dataIndex: 'forMonths', align: 'center' }, { title: '每年工作(月)', dataIndex: 'forMonths', align: 'center' },
{ title: '验证结果', scopedSlots: { customRender: 'msg' }, align: 'center' },
], ],
tableData: [], tableData: [],
disabled: true, disabled: true,
errorState: false,
loading: false, loading: false,
url: '/downloadFile/memberInfo.xlsx', url: '/downloadFile/memberInfo.xlsx',
}; };
...@@ -48,57 +57,83 @@ export default { ...@@ -48,57 +57,83 @@ export default {
}, },
methods: { methods: {
moment,
beforeUpload (file) { beforeUpload (file) {
this.errorState = false
this.tableData = [] this.tableData = []
let list = readExcelFile(file, 0) let list = readExcelFile(file, 0)
let certList = [] let memberList = []
let mobileList = []
let exportList = []
list.then((d) => { list.then((d) => {
//读取文件数据 //读取文件数据
d.forEach(e => { d.forEach(e => {
let gender = personGender(e.证件号) let msg = ''
let birthday = personBirthday(e.证件号) + ' 00:00:00' let certId = e.证件号码
let expert = { personName: e.姓名, certId: e.证件号, sex: gender, birthday: moment(birthday).format('YYYY-MM-DD HH:mm:ss'), mobile: e.手机号, email: e.邮箱, specName: e.专业, titleName: e.职称, unitName: e.单位 } let gender = e.性别
exportList.push(expert) let birthday = moment(e.出生日期).format('YYYY-MM-DD HH:mm:ss')
certList.push(e.证件号) let title = null
mobileList.push(e.手机号) let degree = null
if (!!!e.姓名) {
msg = ';姓名不能为空!'
}
if (!!!e.出生日期) {
msg += ';出生日期不能为空!'
}
if (!!!e.性别) {
msg += ';性别不能为空!'
}
if (!!!e.职称) {
msg += ';职称不能为空!'
} else {
title = getTitle(e.职称)
}
if (!!!e.学位) {
msg += ';学位不能为空!'
} else {
degree = getDegree(e.学位)
}
if (!!!e.工作单位) {
msg += ';工作单位不能为空!'
}
if (!!!e.手机号) {
msg += ';手机号不能为空!'
}
if (!!!e.电子邮箱) {
msg += ';电子邮箱不能为空!'
}
if (!!!e.证件号码) {
msg += ';证件号码不能为空!'
}
if (!!!e.项目分工) {
msg += ';项目分工不能为空!'
}
if (!!!e.每年工作) {
msg += ';每年工作不能为空!'
}
// if (checkCertId(certId)) {
// gender = personGender(certId)
// birthday = personBirthday(certId) + ' 00:00:00'
// }
if (!!msg) {
this.errorState = true
}
let member = {
name: e.姓名, birthday: birthday, sex: gender, title: title, titleName: e.职称, degree: degree, degreeName: e.学位, workUnit: e.工作单位, mobile: e.手机号, email: e.电子邮箱, certId: certId, projWork: e.项目分工, forMonths: e.每年工作, msg: msg, fileId: null, downloadId: null, fileName: null, downloadUrl: null
}
memberList.push(member)
}) })
if (memberList.length > 0) {
let uniqueMobileList = [...new Set(mobileList)] this.tableData = memberList
if (uniqueMobileList.length != exportList.length) { this.disabled = this.errorState ? true : false
this.$message.error('手机号出现重复!')
return false
}
let uniqueCertList = [...new Set(certList)]
if (uniqueCertList.length != exportList.length) {
this.$message.error('证件号出现重复!')
return false
}
if (exportList.length > 0) {
this.tableData = exportList
this.disabled = false
} }
}) })
return false return false
}, },
dataImport () { dataImport () {
if (this.tableData.length == 0) { if (this.tableData.length == 0) {
this.$message.error('请选择Excel!') this.$message.error('请选择加载Excel!')
return return
} }
let pars = isEmptyParams(this.tableData) this.$emit('import', this.tableData)
let par = { ...pars }
this.$api.expert.expertImport(this.tableData).then(({ data = {} }) => {
if (data) {
this.$message.info(data)
this.tableData = []
}
})
} }
}, },
}; };
......
...@@ -460,7 +460,6 @@ ...@@ -460,7 +460,6 @@
</a-col> </a-col>
</a-row> </a-row>
<a-row type="flex"> <a-row type="flex">
<a-col :span="4" class="bg-gray"> <a-col :span="4" class="bg-gray">
<div class="special-middle"> <div class="special-middle">
...@@ -531,7 +530,7 @@ ...@@ -531,7 +530,7 @@
<unit-payment-edit :unitPayment.sync="formData.unitPayment" /> <unit-payment-edit :unitPayment.sync="formData.unitPayment" />
<!-- 项目绩效指标 --> <!-- 项目绩效指标 -->
<project-kpi-edit :projectKPI.sync="formData.projectKPI" /> <project-kpi-edit :projectKPI.sync="formData.projectKPI" />
<!-- 附件 --> <!-- 附件 -->
<file-edit :fileList.sync="formData.fileList" /> <file-edit :fileList.sync="formData.fileList" />
</a-form-model> </a-form-model>
...@@ -561,7 +560,7 @@ const ManagementRule = { policyName: null, releaseDate: null, documentNumber: nu ...@@ -561,7 +560,7 @@ const ManagementRule = { policyName: null, releaseDate: null, documentNumber: nu
const ProjectSub = { projName: null, undertakingUnit: null, address: null, director: null, totalBudget: null, govBudget: null, selfBudget: null, cooperativeUnits: null, fileId: null, downloadId: null, fileName: null, downloadUrl: null } const ProjectSub = { projName: null, undertakingUnit: null, address: null, director: null, totalBudget: null, govBudget: null, selfBudget: null, cooperativeUnits: null, fileId: null, downloadId: null, fileName: null, downloadUrl: null }
const Cooperative = { id: null, unitName: null } const Cooperative = { id: null, unitName: null }
const ParticipateUnit = { id: null, unitName: null, unitCountry: null, unitAddress: null, organizationCode: null, projectWork: null } const ParticipateUnit = { id: null, unitName: null, unitCountry: null, unitAddress: null, organizationCode: null, projectWork: null }
const Members = { name: null, sex: null, birthday: null, certificateType: null, certId: null, nation: null, country: null, workUnit: null, title: null, degree: null, email: null, mobile: null, telephone: null, fax: null, projWork: null, forMonths: null, spec: null, fileId: null, downloadId: null, fileName: null, downloadUrl: null }
const Equipment = { id: "", objectId: "", name: "", functionTarget: "", specificationType: "", quantity: 1, totalBudget: 0.00, useFrom: "", buyUnit: "", storageLocation: "", equipmentType: "", manufacturer: "", sharedScope: "", unitPrice: 0.00, } const Equipment = { id: "", objectId: "", name: "", functionTarget: "", specificationType: "", quantity: 1, totalBudget: 0.00, useFrom: "", buyUnit: "", storageLocation: "", equipmentType: "", manufacturer: "", sharedScope: "", unitPrice: 0.00, }
const File = { fileName: '', downloadUrl: '', fileExplain: '', downloadId: '' } const File = { fileName: '', downloadUrl: '', fileExplain: '', downloadId: '' }
...@@ -768,13 +767,15 @@ export default { ...@@ -768,13 +767,15 @@ export default {
if (!!!this.formData.projectResearchList || this.formData.projectResearchList.length == 0) if (!!!this.formData.projectResearchList || this.formData.projectResearchList.length == 0)
this.formData.projectResearchList = [{ ...ProjResearch }] this.formData.projectResearchList = [{ ...ProjResearch }]
if (!!!this.formData.managementRuleList || this.formData.managementRuleList.length == 0) if (!!!this.formData.managementRuleList || this.formData.managementRuleList.length == 0)
this.formData.managementRuleList = [{ ...ManagementRule }] this.formData.managementRuleList = [{ ...ManagementRule }]
if (!!!this.formData.projectSubList || this.formData.projectSubList.length == 0) if (!!!this.formData.projectSubList || this.formData.projectSubList.length == 0)
this.formData.projectSubList = [{ ...ProjectSub }] this.formData.projectSubList = [{ ...ProjectSub }]
if (!!!this.formData.members || this.formData.members.length == 0) if (!!!this.formData.members || this.formData.members.length == 0)
this.formData.members = [{ ...Members }] this.formData.members = []
if (!!!this.formData.equipments || !this.formData.equipments.length || this.formData.equipments.length == 0) { if (!!!this.formData.equipments || !this.formData.equipments.length || this.formData.equipments.length == 0) {
this.formData.equipments = [] this.formData.equipments = []
......
...@@ -196,7 +196,7 @@ ...@@ -196,7 +196,7 @@
<member-edit :memObject.sync="memObject" @close="closeWindow" /> <member-edit :memObject.sync="memObject" @close="closeWindow" />
</a-modal> </a-modal>
<a-modal v-model="visibleImport" v-if="visibleImport" title="项目组成员导入" width="90%" :footer="null" :dialog-style="{ top: '12%' }" destroyOnClose> <a-modal v-model="visibleImport" v-if="visibleImport" title="项目组成员导入" width="90%" :footer="null" :dialog-style="{ top: '12%' }" destroyOnClose>
<member-import /> <member-import @import="importList" />
</a-modal> </a-modal>
</div> </div>
</template> </template>
...@@ -208,12 +208,14 @@ import memberImport from '@/views/report/project/components/memberImport'; ...@@ -208,12 +208,14 @@ import memberImport from '@/views/report/project/components/memberImport';
import memberEdit from '@/views/report/project/components/memberEdit' import memberEdit from '@/views/report/project/components/memberEdit'
import moment from 'moment' import moment from 'moment'
const Member = { name: null, sex: null, birthday: null, certificateType: null, certId: null, nation: null, country: null, workUnit: null, title: null, degree: null, email: null, mobile: null, telephone: null, fax: null, projWork: null, forMonths: null, spec: null, fileId: null, downloadId: null, fileName: null, downloadUrl: null } const Member = {
name: null, birthday: null, sex: null, title: null, titleName: null, degree: null, degreeName: null, workUnit: null, mobile: null, email: null, certId: null, projWork: null, forMonths: null, fileId: null, downloadId: null, fileName: null, downloadUrl: null
}
export default { export default {
name: 'projectMemberEdit', name: 'projectMemberEdit',
components: { components: {
memberImport,memberEdit memberImport, memberEdit
}, },
data () { data () {
return { return {
...@@ -236,6 +238,13 @@ export default { ...@@ -236,6 +238,13 @@ export default {
}, },
methods: { methods: {
moment, moment,
importList (value) {
value.forEach(e => {
this.dataList.push(e)
})
this.$message.success('成功!')
this.visibleImport = false;
},
importExcel () { importExcel () {
this.visibleImport = true; this.visibleImport = true;
}, },
......
...@@ -9,7 +9,7 @@ const budgetList = () => { ...@@ -9,7 +9,7 @@ const budgetList = () => {
unitBudget: 0.00, unitBudget: 0.00,
remark: '', remark: '',
// 数据总和来源 // 数据总和来源
source: [1,2], source: [1, 2],
disabled: '' disabled: ''
}, { }, {
type: 'ins', type: 'ins',
...@@ -71,9 +71,9 @@ const budgetList = () => { ...@@ -71,9 +71,9 @@ const budgetList = () => {
// 数据总和来源 // 数据总和来源
source: [], source: [],
disabled: '' disabled: ''
}, { }, {
type: 'ins', type: 'ins',
id: '', id: '',
budgetId: '', budgetId: '',
...@@ -86,7 +86,7 @@ const budgetList = () => { ...@@ -86,7 +86,7 @@ const budgetList = () => {
source: [], source: [],
disabled: '' disabled: ''
}, { }, {
type: 'ins', type: 'ins',
id: '', id: '',
budgetId: '', budgetId: '',
...@@ -99,7 +99,7 @@ const budgetList = () => { ...@@ -99,7 +99,7 @@ const budgetList = () => {
source: [], source: [],
disabled: '' disabled: ''
}, { }, {
type: 'ins', type: 'ins',
id: '', id: '',
budgetId: '', budgetId: '',
...@@ -172,7 +172,95 @@ const budgetList = () => { ...@@ -172,7 +172,95 @@ const budgetList = () => {
source: [], source: [],
disabled: '' disabled: ''
}] }]
} }
const titleList = [{ title: '主任医师', key: '0caa997f-e1d9-4412-9589-acc8ff7f5fb8' },
{ title: '主任技师', key: 'bc904c24-d2a1-4393-b693-047bd4f958ce' },
{ title: '主任护师', key: '43073c81-f400-43e1-aecf-8b43012363ad' },
{ title: '主任药师', key: '06fccdef-bde3-4970-bab4-5bd456c58290' },
{ title: '公共卫生主任医师', key: 'bf66daa3-b5dc-4a91-a8c3-e62b3179753a' },
{ title: '口腔主任医师', key: 'e1aaf661-3832-4c5a-8ad4-ebbb0e744c06' },
{ title: '教授', key: '6d880a2a-5c2f-4270-86cb-866b2c0f3bc0' },
{ title: '研究员', key: '82c361ed-8e8e-4b59-8721-ca8f446a1b91' },
{ title: '研究员级高级工程师', key: '03c070c9-ed2f-48b1-8046-bb2bac0b71fa' },
{ title: '高级会计师', key: '9696eeee-8c1c-4ed9-97b3-78f3800644a3' },
{ title: '公共卫生副主任医师', key: '9696eeee-8c1c-4ed9-97b3-5b63800644a3' },
{ title: '副主任医师', key: 'f7c96a3b-3487-4d1e-98fa-9f4a8e2ee135' },
{ title: '副主任技师', key: '2e21cc25-9215-434f-a28a-674e58c03fc5' },
{ title: '副主任护师', key: '48a76732-6c37-46ff-bf5c-2abf97b5bf2d' },
{ title: '副主任药师', key: '2871fbc8-2d82-48c3-821b-e290fcc1bdb4' },
{ title: '副教授', key: 'd0cf8dbf-276e-4bc9-be15-f54310928c51' },
{ title: '副研究员', key: '70457c26-8d12-45ed-ba4b-94f719a74aef' },
{ title: '口腔副主任医师', key: '89c7745f-95f9-4db0-82d6-8c0c759686c9' },
{ title: '高级工程师', key: 'e566d0a7-b7e1-47f0-a3ca-cc4b80561a94' },
{ title: '主治医师', key: '083c8875-4f0d-4234-b29a-28918462d0c8' },
{ title: '主管技师', key: '22deacea-78f5-4587-8f5d-96ea7463dde6' },
{ title: '主管护师', key: '5f728a1b-ec20-4f94-ae30-6d38d2aaa5e7' },
{ title: '主管药师', key: 'bbdef542-ba8d-4323-82c5-536ac8548b55' },
{ title: '会计师', key: '5f728a1b-ec30-4f94-ae30-6d38d2aaa5e7' },
{ title: '公共卫生主治医师', key: '5edacfe8-948e-473e-895d-b08bbb017298' },
{ title: '助理研究员', key: '11e1329f-86e8-4022-9f43-42ed50018042' },
{ title: '口腔主治医师', key: '3be16465-4fb0-4677-a18c-0d6e1670cde0' },
{ title: '工程师', key: '9b8c6af4-8d85-435c-a741-9fbb4c194a0b' },
{ title: '统计师', key: '8d79030b-254d-11ee-a6b6-0c42a1e82e90' },
{ title: '讲师', key: '8d52d54d-2eb8-4e74-b042-79c294911cd8' },
{ title: '公共卫生医士', key: 'fb994954-aa68-48e0-b1a6-6ea493baf8ca' },
{ title: '公共卫生医师', key: 'acc3de78-e389-46c3-bc9c-05f0768f0e11' },
{ title: '助教', key: '75af699f-66f9-49e2-84b9-452dcee98e64' },
{ title: '助理工程师', key: 'b9be97ac-f6e3-4984-8c76-0f15c7e69231' },
{ title: '医士', key: '97c4266c-34f9-457b-8689-65e4ce98d23e' },
{ title: '医师', key: 'f6e3c4df-1442-41d7-b37e-9642a9bb280f' },
{ title: '口腔医士', key: 'bae73c8a-3459-4535-a033-3c9be806573d' },
{ title: '口腔医师', key: 'a7f0122b-fe05-4a3b-ae69-a7326061cfc9' },
{ title: '实习研究员', key: '4392d33a-d186-4378-977d-583461f7c958' },
{ title: '技士', key: 'fd22d793-eb61-4dca-89d2-4dc6b95d3b9d' },
{ title: '技师', key: '7877c786-c506-4e11-a309-ce717dc006a7' },
{ title: '技术员', key: 'dd6cfca2-70b1-4266-a8c4-503dfd6a06b1' },
{ title: '护士', key: '01dad6a5-75fb-4eac-861e-c5c996435896' },
{ title: '护师', key: '2bd407f1-acdc-4162-9142-f1f2ce2b85d3' },
{ title: '药士', key: 'bf11c145-54c6-4c2c-8c7e-273e1529cb36' },
{ title: '药师', key: 'c265a7ba-ecd1-4937-86fe-6a8b1b8d448b' },
{ title: '见习医士', key: '878ef114-f7d1-4548-a485-19dfa02b7a8a' },
{ title: '见习医师', key: '6671f8be-a8ed-46e2-827f-0e1461aae330' },
{ title: '见习技师', key: '4858ba5b-d3e6-4a86-9bff-cde5cb24011e' },
{ title: '见习护士', key: 'ade9cfcc-a8b2-4f4a-ac47-5c701e7666a8' },
{ title: '见习护师', key: '62cc9f96-6483-4cd9-aaba-ff64d15dc4dc' },
{ title: '见习药士', key: 'c37000f3-7e17-4faf-83c3-fc62853c0ab8' },
{ title: '见习药师', key: '8a7b700c-82cb-49ff-a022-9049eadd07d5' },
{ title: '见习药师', key: 'a8b51dbf-88b9-4a5b-a8c7-21a91f30494b' },
{ title: '讲师', key: '1b5e0c69-335e-4d05-b285-e34ffd76b23c' },
{ title: '无职称', key: '24bf7a5b-78e8-425f-b3c2-a65d9c42b247' },]
const degreeList = [{ key: 'c6c21d5d-8c0b-4f6c-a8a7-c508673d1617', title: '博士后' },
{ key: 'f6c21d5d-8c0b-4f6c-a8a7-c508673d1615', title: '博士' },
{ key: 'fe111771-dac8-42c7-806a-4dd2ef73f3a8', title: '硕士' },
{ key: '13c4f337-6f7a-4a9b-adc2-b61c3b233fac', title: '学士' },
{ key: '150caf77-a928-46da-b069-ae5a979703fc', title: '无' },]
export function getTitle (name) {
let newArray = titleList.filter(
function (el) {
return el.title == name
}
);
if (!!newArray && newArray.length > 0)
return newArray[0].key
else
return null
}
export function getDegree (name) {
let newArray = degreeList.filter(
function (el) {
return el.title == name
}
);
if (!!newArray && newArray.length > 0)
return newArray[0].key
else
return null
}
export { export {
budgetList budgetList, titleList, degreeList
} }
...@@ -75,4 +75,87 @@ export function isIdentityId(identityId) { ...@@ -75,4 +75,87 @@ export function isIdentityId(identityId) {
errorMsg = "您输入的身份证号非法" errorMsg = "您输入的身份证号非法"
} }
return errorMsg; return errorMsg;
} }
\ No newline at end of file /**
* @description : 校验身份证号是否合规(18位、15位)
* @param {String|Number} value
* @return {Boolean} true-合规 false-不合规
*/
export function checkCertId(value) {
const psidno = String(value)
// 1.校验身份证号格式和长度
const regPsidno = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[X])$)$/
if (!regPsidno.test(psidno)) {
return false
}
// 2.校验前两位的省份编码是否正确
const province = { 11: '北京', 12: '天津', 13: '河北', 14: '山西', 15: '内蒙古', 21: '辽宁', 22: '吉林', 23: '黑龙江 ', 31: '上海', 32: '江苏', 33: '浙江', 34: '安徽', 35: '福建', 36: '江西', 37: '山东', 41: '河南', 42: '湖北 ', 43: '湖南', 44: '广东', 45: '广西', 46: '海南', 50: '重庆', 51: '四川', 52: '贵州', 53: '云南', 54: '西藏 ', 61: '陕西', 62: '甘肃', 63: '青海', 64: '宁夏', 65: '新疆', 71: '台湾', 81: '香港', 82: '澳门', 91: '国外' }
if (!province[Number(psidno.slice(0, 2))]) {
return false
}
// 3.校验出生日期
if (psidno.length === 15) {
// 15位号码 省(2位)市(2位)县(2位)年(2位)月(2位)日(2位)校验码(3位)
const reg = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/)
const arrSplit = psidno.match(reg)
// 15位号码在年份前补 19 或 20
const year = Number(arrSplit[2].charAt(0)) > 0 ? '19' + arrSplit[2] : '20' + arrSplit[2]
const month = arrSplit[3]
const day = arrSplit[4]
if (!validateBirthday(year, month, day)) {
return false
}
} else if (psidno.length === 18) {
// 18位号码 省(2位)市(2位)县(2位)年(4位)月(2位)日(2位)校验码(4位)
const reg = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/)
const arrSplit = psidno.match(reg)
const year = arrSplit[2]
const month = arrSplit[3]
const day = arrSplit[4]
if (!validateBirthday(year, month, day)) {
return false
}
} else {
return false
}
// 校验出生日期是否合理
function validateBirthday(year, month, day) {
year = Number(year) // 年
month = Number(month) // 月
day = Number(day) // 日
const nowTime = new Date().getTime() // 当前时间戳
const birthTime = new Date(`${year}-${month}-${day}`).getTime() // 获取出生日期的时间戳
// 不能是明天出生的吧
if (birthTime > nowTime) {
return false
}
// 一般人活不到150岁吧
const nowYear = new Date().getFullYear()
if ((nowYear - year) > 150) {
return false
}
// 不能是13月出生的吧
if (month < 1 || month > 12) {
return false
}
// 不能是2月30号、4月31号、5月32号出生的吧
const date = new Date(year, month, 0) // 获取当月的最后一天
if (day < 1 || day > date.getDate()) {
return false
}
return true
}
// 4.18位号码校验生成的校验码
if (psidno.length === 18) {
const Wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] // 加权因子
const parity = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'] // 校验码
let sum = 0
for (let i = 0; i < 17; i++) {
sum += Number(psidno.charAt(i)) * Wi[i]
}
if (parity[sum % 11] !== psidno[17]) {
return false
}
}
return true
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment