|
|
@@ -137,6 +137,22 @@
|
|
|
|
|
|
const handleApply = async () => {
|
|
|
if(selectMemberList.value.length===0) return proxy.$showToast('请至少添加一位报名人员')
|
|
|
+
|
|
|
+ //判断人数和年龄符不符合限制
|
|
|
+ if(activity.value.recruitmentMax!==0){
|
|
|
+ const nextUserCount = activity.value.recruitmentMax-activity.value.recruitmentNow;
|
|
|
+ if(selectMemberList.value.length>nextUserCount){
|
|
|
+ return proxy.$showModal(`很抱歉,当前活动最大招募人数为${activity.value.recruitmentMax}人,剩余可招募人数为${nextUserCount}人,您的报名人数共${selectMemberList.value.length}人,超出人数限制,不可报名。`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(activity.value.userAgeMax!==0){
|
|
|
+ const limitUser = selectMemberList.value.filter(m=>getAgeFromIdCard(m.idCard)>activity.value.userAgeMax||getAgeFromIdCard(m.idCard)<activity.value.userAgeMin)
|
|
|
+ if(limitUser.length){
|
|
|
+ const limitUserText = limitUser.length>0&&limitUser.map(u=>`${u.name}[${getAgeFromIdCard(u.idCard)}岁]`)
|
|
|
+ return proxy.$showModal(`很抱歉,当前活动限制招募年龄为${activity.value.userAgeMin}至${activity.value.userAgeMax}岁,您的报名人员中:${limitUserText},超出了年龄限制,不可报名。`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(!submitDto.value.contact) return proxy.$showToast('请输入联系人姓名')
|
|
|
if(!proxy.$reg.mobile(submitDto.value.contactPhone)) return proxy.$showToast('请输入正确的联系电话')
|
|
|
submitDto.value.memberIds = selectMemberList.value.map(m=>m.id);
|
|
|
@@ -158,6 +174,66 @@
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ const getAgeFromIdCard = (idCardNumber) => {
|
|
|
+ // 1. 基本校验:检查输入是否为字符串且长度是否为18位
|
|
|
+ if (typeof idCardNumber !== 'string' || idCardNumber.length !== 18) {
|
|
|
+ console.error("无效的身份证号码格式,长度必须是18位字符串。");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 提取出生日期部分 (YYYYMMDD)
|
|
|
+ // 中国大陆18位身份证号码的出生日期信息位于第7位到第14位(索引6到13)
|
|
|
+ const birthDateStr = idCardNumber.substring(6, 14); // 例如 "19900101"
|
|
|
+
|
|
|
+ // 3. 解析年、月、日
|
|
|
+ const year = parseInt(birthDateStr.substring(0, 4), 10);
|
|
|
+ const month = parseInt(birthDateStr.substring(4, 6), 10);
|
|
|
+ const day = parseInt(birthDateStr.substring(6, 8), 10);
|
|
|
+
|
|
|
+ // 4. 校验日期有效性
|
|
|
+ // 简单校验年份、月份、日期范围
|
|
|
+ if (isNaN(year) || isNaN(month) || isNaN(day) ||
|
|
|
+ year < 1900 || year > new Date().getFullYear() || // 假设最小年份1900,最大为当前年
|
|
|
+ month < 1 || month > 12 ||
|
|
|
+ day < 1 || day > 31) {
|
|
|
+ console.error("身份证号码中包含无效的出生日期信息。", idCardNumber);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更严谨的日期校验:使用Date对象进行验证
|
|
|
+ // 注意:Date对象的月份是0-11,所以需要 month - 1
|
|
|
+ const birthDate = new Date(year, month - 1, day);
|
|
|
+ // 检查解析后的日期是否与输入匹配,以排除像 "20000230" 这样的无效日期(会自动转换为 2000-03-01)
|
|
|
+ if (birthDate.getFullYear() !== year ||
|
|
|
+ birthDate.getMonth() !== month - 1 ||
|
|
|
+ birthDate.getDate() !== day) {
|
|
|
+ console.error("身份证号码中的出生日期不是一个有效的日历日期。", idCardNumber);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 获取当前日期
|
|
|
+ const today = new Date();
|
|
|
+ const currentYear = today.getFullYear();
|
|
|
+ const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11,所以加1
|
|
|
+ const currentDay = today.getDate();
|
|
|
+
|
|
|
+ // 6. 计算年龄
|
|
|
+ let age = currentYear - year;
|
|
|
+
|
|
|
+ // 如果当前月份小于出生月份,或者当前月份等于出生月份但当前日期小于出生日期,则年龄减1
|
|
|
+ if (currentMonth < month || (currentMonth === month && currentDay < day)) {
|
|
|
+ age--;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确保年龄不为负数(如果身份证日期是未来日期,虽然前面有校验,但以防万一)
|
|
|
+ if (age < 0) {
|
|
|
+ console.warn("身份证号码中的出生日期晚于当前日期,返回年龄为0。", idCardNumber);
|
|
|
+ return 0; // 或者 null,取决于业务需求
|
|
|
+ }
|
|
|
+
|
|
|
+ return age;
|
|
|
+ }
|
|
|
+
|
|
|
const getUserLoveTicket = () => {
|
|
|
let userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
|
|
|
proxy.$api.get(`/core/activity/signup/userAsset/${userId}/${activity.value?.id}`).then(({data:res})=>{
|