This commit is contained in:
Paidax
2025-05-21 18:12:08 +08:00
parent dd5aae6b9f
commit 4818e5bcfe
8 changed files with 658 additions and 195 deletions
@@ -122,7 +122,7 @@ layout("/mobile/platform.html"){
<div id="app" v-cloak>
<van-sticky>
<van-nav-bar title="体检套餐选择" left-arrow @click-left="pjaxReplace('/mobile/index')"></van-nav-bar>
<van-nav-bar title="体检套餐选择" left-arrow @click-left="pjaxReplace('/mobile/healthCheckup/list')"></van-nav-bar>
</van-sticky>
<div class="join_content">
@@ -163,6 +163,7 @@ layout("/mobile/platform.html"){
<van-field
@click="campusVisible = true"
readonly
required
is-link
label="院区"
name="campus"
@@ -170,6 +171,55 @@ layout("/mobile/platform.html"){
v-model="formData.campusName"
:rules="[{ required: true }]"
></van-field>
<van-field
label="姓名"
name="username"
required
placeholder="请填写姓名"
v-model="formData.username"
:rules="[{ required: true }]"
></van-field>
<van-field
required
readonly
label="性别"
name="sex"
placeholder="输入身份证后自动匹配"
:rules="[{ required: true }]"
v-model="formData.sex"
></van-field>
<van-field
label="年龄"
name="age"
required
readonly
placeholder="输入身份证后自动计算"
type="digit"
:rules="[{ required: true }]"
v-model="formData.age"
></van-field>
<span style="font-size: 13px; margin-left: 1.4vh; color: #bc2a25">输入身份证后自动匹配性别和年龄</span>
<van-field
label="联系方式"
name="mobile"
required
placeholder="请填写联系方式"
type="digit"
maxlength="11"
:rules="[{ required: true }]"
v-model="formData.mobile"
></van-field>
<van-field
label="身份证号"
name="idcard"
required
maxlength="18"
placeholder="请填写身份证号"
@input="getAgeAndSex"
:rules="[{ required: true }]"
v-model="formData.idcard"
></van-field>
<!-- <van-field :rules="[{ required: true, message: '请选择家属是否体检' }]" label="家属体检" name="validator">
<template #input>
<van-radio-group direction="horizontal" v-model="formData.isFamily" disabled>
@@ -270,6 +320,13 @@ layout("/mobile/platform.html"){
<van-popup position="bottom" round v-model="descVisible" :style="{ height: '60%' }">
<div v-html="desc" class="pre_text"></div>
</van-popup>
<div>
<van-tabbar v-model="tarBarActive">
<van-tabbar-item icon="home-o" replace url="/mobile/healthCheckup/list">体检选择</van-tabbar-item>
<van-tabbar-item icon="manager-o" replace url="/mobile/healthCheckup/mine">我的体检</van-tabbar-item>
</van-tabbar>
</div>
</div>
<script>
const vue = new Vue({
@@ -277,6 +334,7 @@ layout("/mobile/platform.html"){
mixins: [mobileMixins],
data() {
return {
tarBarActive: 0,
id: "",
selectId: "",
active: 0,
@@ -292,6 +350,82 @@ layout("/mobile/platform.html"){
}
},
methods: {
getAgeAndSex(value) {
try {
const age = this.calculateAgeFromIdCard(value)
this.$set(this.formData, "age", age)
const sex = this.getGenderFromIdCard(value)
this.$set(this.formData, "sex", sex)
} catch (error) {
console.log(error)
}
},
calculateAgeFromIdCard(idCard) {
// 检查身份证号码是否合法
if (!idCard) {
throw new Error("Invalid ID card format")
}
let birthDateStr
let birthYear, birthMonth, birthDay
// 处理18位身份证号码
if (idCard.length === 18) {
birthDateStr = idCard.substring(6, 14)
birthYear = parseInt(birthDateStr.substring(0, 4), 10)
birthMonth = parseInt(birthDateStr.substring(4, 6), 10) - 1 // 月份从0开始
birthDay = parseInt(birthDateStr.substring(6, 8), 10)
}
// 处理15位身份证号码
else if (idCard.length === 15) {
birthDateStr = idCard.substring(6, 12)
birthYear = parseInt("19" + birthDateStr.substring(0, 2), 10) // 使用字符串拼接
birthMonth = parseInt(birthDateStr.substring(2, 4), 10) - 1 // 月份从0开始
birthDay = parseInt(birthDateStr.substring(4, 6), 10)
} else {
throw new Error("Invalid ID card format. Only 15 or 18 digits are supported.")
}
// 获取当前日期
const currentDate = new Date()
// 计算年龄
let age = currentDate.getFullYear() - birthYear
// 如果当前日期还没过生日,则年龄减1
if (currentDate.getMonth() < birthMonth || (currentDate.getMonth() === birthMonth && currentDate.getDate() < birthDay)) {
age -= 1
}
return age
},
getGenderFromIdCard(idCard) {
// 检查身份证号码是否合法
if (!idCard) {
throw new Error("Invalid ID card format")
}
let genderDigit
// 处理18位身份证号码
if (idCard.length === 18) {
genderDigit = parseInt(idCard.charAt(16), 10) // 第17位
}
// 处理15位身份证号码
else if (idCard.length === 15) {
genderDigit = parseInt(idCard.charAt(14), 10) // 第15位
} else {
throw new Error("Invalid ID card format. Only 15 or 18 digits are supported.")
}
// 判断性别
if (genderDigit % 2 === 0) {
return "女"
} else {
return "男"
}
},
viewDesc(o) {
if (o.description) {
this.desc = o.description
@@ -305,6 +439,16 @@ layout("/mobile/platform.html"){
vant.Toast("请选择体检套餐")
return
}
if (!this.validatePhoneNumber(this.formData.mobile)) {
vant.Toast("请填写正确的手机号")
return
}
if (!this.validateIdCard(this.formData.idcard)) {
vant.Toast("请填写正确的身份证号")
return
}
//如果等于家属
if (this.project.healthCheckupType === "js" && this.formData.companionList && this.formData.companionList.length === 0) {
vant.Toast("当前体检项目需要填写家属信息,请填写家属信息。")
@@ -389,6 +533,57 @@ layout("/mobile/platform.html"){
this.formData = resp.data
const o = this.campusList.find((o) => o.id === this.formData.campus)
this.formData.campusName = o.campusName
},
async getUserInfo() {
const resp = await $.post("/mobile/healthCheckup/getUserInfo")
if (resp.code === 0) {
this.$set(this.formData, "username", resp.data.username)
this.$set(this.formData, "sex", resp.data.sex)
this.$set(this.formData, "mobile", resp.data.mobile)
this.$set(this.formData, "idcard", resp.data.idcard)
this.$set(this.formData, "age", resp.data.age)
}
},
validateIdCard(idCard) {
if (!idCard) {
return false
}
// 18位身份证号码校验
if (idCard.length === 18) {
const idCardRegex = /^[1-9]\d{5}(18|19|20)?\d{2}((0[1-9])|(10|11|12))(([0|1|2][0-9])|10|20|30|31)\d{3}(\d|[Xx])$/
if (!idCardRegex.test(idCard)) {
return false
}
// 校验码计算
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
const checksums = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]
let sum = 0
for (let i = 0; i < 17; i++) {
sum += idCard[i] * weights[i]
}
const checksum = checksums[sum % 11]
return checksum === idCard[17].toUpperCase()
}
// 15位身份证号码校验
else if (idCard.length === 15) {
const idCardRegex = /^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0|1|2][0-9])|10|20|30|31)\d{3}$/
return idCardRegex.test(idCard)
}
// 外国人或其他情况
else {
return false
}
},
validatePhoneNumber(phoneNumber) {
if (!phoneNumber) {
return false
}
const phoneRegex = /^1[3-9]\d{9}$/
return phoneRegex.test(phoneNumber)
}
},
async created() {
@@ -397,6 +592,8 @@ layout("/mobile/platform.html"){
await this.getCampus()
if (GetQueryString("selectId")) {
await this.getSelectInfo()
} else {
this.getUserInfo()
}
await this.findSubject()
}