activityApply.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <template>
  2. <view class="common_page adffc" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title="报名信息填写" bgColor="transparent"></cus-header>
  4. <image src="https://oss.familydaf.cn/sxsnfile/20251218/ff31a76e0e1148378a318382b998a51f.png" class="top_bg_img" mode="widthFix"></image>
  5. <view class="box box1">
  6. <view class="box1-top">
  7. <view class="title">{{activity?.activityName||''}}</view>
  8. <view class="tip">活动时间:{{activity?.activityStartTime||''}} 到 {{activity?.activityEndTime||''}}</view>
  9. <view class="tip">活动地点:{{activity?.provinceName||''}}{{activity?.cityName||''}}{{activity?.address||''}}</view>
  10. </view>
  11. <view class="box1-bottom adfac">
  12. <image src="https://oss.familydaf.cn/sxsnfile/20251218/0a68f263fc1b464cba97b7a8fe130ccc.png"></image>
  13. <text>报名时间截止前可取消并返还{{activityLimitCfg[activity?.activityLimit]}},截止后不可取消。</text>
  14. </view>
  15. </view>
  16. <view class="box box2">
  17. <view class="box2-title">报名信息</view>
  18. <view class="box2-members" v-if="selectMemberList.length">
  19. <view class="box2-members-pre adfacjb" v-for="(item,index) in selectMemberList" :key="index">
  20. <view class="box2-members-pre-left">
  21. <view class="ltop adfac">
  22. <view class="name">{{item.name}}</view>
  23. <image class="sex" v-if="item.gender==1" src="https://oss.familydaf.cn/sxsnfile/20251218/473d5677fbdb4106acdb9a163377d27f.png"></image>
  24. <image class="sex" v-else-if="item.gender==0" src="https://oss.familydaf.cn/sxsnfile/20251218/02bc40a1c47b40f1a36b55cd0553211c.png"></image>
  25. <view class="age" :class="{'women':item.gender==1,'man':item.gender==0}">{{item.age}}岁</view>
  26. </view>
  27. <view class="lbottom">
  28. 身份证 {{item.idCardCopy}}
  29. </view>
  30. </view>
  31. <view class="box2-members-pre-right" @click="deleteMember(item,index)">
  32. <image src="https://oss.familydaf.cn/sxsnfile/20251218/f94c1d060eca4506a7e645919d158288.png"></image>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="box2-add adfacjc" @click="handleAdd">
  37. <image src="https://oss.familydaf.cn/sxsnfile/20251218/5ae3736e1ca74d739b54578af5c7a56d.png"></image>
  38. <text>添加</text>
  39. </view>
  40. </view>
  41. <view class="box box3">
  42. <view class="box3-pre adfacjb">
  43. <view class="box3-pre-left">联系人姓名</view>
  44. <view class="box3-pre-right">
  45. <up-input v-model="submitDto.contact" border="none" style="font-size: 30rpx;color: #151B29;text-align: right;" placeholder="请输入联系人姓名"></up-input>
  46. </view>
  47. </view>
  48. <view class="box3-pre adfacjb">
  49. <view class="box3-pre-left">联系人电话</view>
  50. <view class="box3-pre-right">
  51. <up-input v-model="submitDto.contactPhone" border="none" style="font-size: 30rpx;color: #151B29;text-align: right;" placeholder="请输入联系人电话"></up-input>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="box box4 adfacjb" v-if="activity?.activityLimit==2" @click="handleSelectTicket">
  56. <view class="box4-left">专享券抵扣</view>
  57. <view class="box4-right adfac">
  58. <text>{{ticketText}}</text>
  59. <image src="https://oss.familydaf.cn/sxsnfile/20251218/48d65d353fd748ccb33c0fa29c1cecb0.png"></image>
  60. </view>
  61. </view>
  62. <view class="cbottom">
  63. <view class="cbottom-top adfac" @click="changeAgree">
  64. <image v-if="agree" src="https://oss.familydaf.cn/sxsnfile/20251218/c11b9a1b56f34e1189621f4270f0349a.png"></image>
  65. <image v-else src="https://oss.familydaf.cn/sxsnfile/20251218/2a2f7bdefb474a3e93faa00aef6d0e1f.png"></image>
  66. <text>我已知晓并同意活动组织方获取以上我所提交的报名信息。</text>
  67. </view>
  68. <view class="cbottom-btn adfacjb">
  69. <view class="cbottom-btn-left adffcac">
  70. <template v-if="activity?.activityLimit<3">
  71. <view class="heart adfac">
  72. <image src="https://oss.familydaf.cn/sxsnfile/20251218/8ee2fca2eb514e8fb10507ef3a0ed7d3.png"></image>
  73. <text>{{payValue}}</text>
  74. </view>
  75. <view class="text">{{activityLimitCfg[activity?.activityLimit]||''}}</view>
  76. </template>
  77. <template v-else>
  78. <view class="free">免费</view>
  79. </template>
  80. </view>
  81. <view class="cbottom-btn-right" @click="handleApply">确定报名</view>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script setup name="">
  87. import CusHeader from '@/components/CusHeader/index.vue'
  88. import { ref, getCurrentInstance, onMounted } from 'vue'
  89. import { onLoad } from '@dcloudio/uni-app'
  90. const { proxy } = getCurrentInstance()
  91. const activity = ref(null)
  92. const activityLimitCfg = ref({
  93. 1:'爱心值',
  94. 2:'专享券',
  95. 3:'免费'
  96. })
  97. const selectMemberList = ref([])
  98. const submitDto = ref({
  99. activityId:'',
  100. contact:'',
  101. contactPhone:'',
  102. couponIds:[],
  103. memberIds:[],
  104. userId:''
  105. })
  106. const agree = ref(false)
  107. const payValue = ref(0)
  108. const userLoveTicket = ref(null)
  109. const selectCouponIds = ref([])
  110. const ticketText = ref('暂无可用专享券')
  111. const handleAdd = () => {
  112. uni.navigateTo({
  113. url:'/pagesHome/applyMember',
  114. events:{
  115. 'selectMembers': data => {
  116. selectMemberList.value = data;
  117. payValue.value = selectMemberList.value.length*activity.value?.valueLimit;
  118. }
  119. }
  120. })
  121. }
  122. const handleSelectTicket = () => {
  123. uni.navigateTo({
  124. url:'/pagesMy/exclusiveScroll?activityId='+activity.value?.id,
  125. events:{
  126. 'selectTickets': data => {
  127. selectCouponIds.value = data;
  128. ticketText.value = `已选${data?.length||0}张,剩余${userLoveTicket.value?.couponIds?.length-data?.length}张可用`;
  129. }
  130. }
  131. })
  132. }
  133. const handleApply = async () => {
  134. if(selectMemberList.value.length===0) return proxy.$showToast('请至少添加一位报名人员')
  135. //判断人数和年龄符不符合限制
  136. if(activity.value.recruitmentMax!==0){
  137. const nextUserCount = activity.value.recruitmentMax-activity.value.recruitmentNow;
  138. if(selectMemberList.value.length>nextUserCount){
  139. return proxy.$showModal(`很抱歉,当前活动最大招募人数为${activity.value.recruitmentMax}人,剩余可招募人数为${nextUserCount}人,您的报名人数共${selectMemberList.value.length}人,超出人数限制,不可报名。`)
  140. }
  141. }
  142. if(activity.value.userAgeMax!==0){
  143. const limitUser = selectMemberList.value.filter(m=>getAgeFromIdCard(m.idCard)>activity.value.userAgeMax||getAgeFromIdCard(m.idCard)<activity.value.userAgeMin)
  144. if(limitUser.length){
  145. const limitUserText = limitUser.length>0&&limitUser.map(u=>`${u.name}[${getAgeFromIdCard(u.idCard)}岁]`)
  146. return proxy.$showModal(`很抱歉,当前活动限制招募年龄为${activity.value.userAgeMin}至${activity.value.userAgeMax}岁,您的报名人员中:${limitUserText},超出了年龄限制,不可报名。`)
  147. }
  148. }
  149. if(!submitDto.value.contact) return proxy.$showToast('请输入联系人姓名')
  150. if(!proxy.$reg.mobile(submitDto.value.contactPhone)) return proxy.$showToast('请输入正确的联系电话')
  151. submitDto.value.memberIds = selectMemberList.value.map(m=>m.id);
  152. submitDto.value.activityId = activity.value.id;
  153. submitDto.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  154. if(activity.value?.activityLimit==2){
  155. let smnum = selectMemberList.value.length;
  156. let stnum = selectCouponIds.value.length;
  157. if(stnum<smnum) return proxy.$showToast(`请选择${smnum}张专享券`)
  158. }
  159. submitDto.value.couponIds = selectCouponIds.value;
  160. if(!agree.value) return proxy.$showToast('请勾选已知晓并同意')
  161. proxy.$api.post('/core/activity/signup/signup',submitDto.value).then(({data:res})=>{
  162. if(res.code!==0) return proxy.$showToast(res.msg)
  163. uni.redirectTo({
  164. url:'/pagesHome/applyResult'
  165. })
  166. })
  167. }
  168. const getAgeFromIdCard = (idCardNumber) => {
  169. // 1. 基本校验:检查输入是否为字符串且长度是否为18位
  170. if (typeof idCardNumber !== 'string' || idCardNumber.length !== 18) {
  171. console.error("无效的身份证号码格式,长度必须是18位字符串。");
  172. return null;
  173. }
  174. // 2. 提取出生日期部分 (YYYYMMDD)
  175. // 中国大陆18位身份证号码的出生日期信息位于第7位到第14位(索引6到13)
  176. const birthDateStr = idCardNumber.substring(6, 14); // 例如 "19900101"
  177. // 3. 解析年、月、日
  178. const year = parseInt(birthDateStr.substring(0, 4), 10);
  179. const month = parseInt(birthDateStr.substring(4, 6), 10);
  180. const day = parseInt(birthDateStr.substring(6, 8), 10);
  181. // 4. 校验日期有效性
  182. // 简单校验年份、月份、日期范围
  183. if (isNaN(year) || isNaN(month) || isNaN(day) ||
  184. year < 1900 || year > new Date().getFullYear() || // 假设最小年份1900,最大为当前年
  185. month < 1 || month > 12 ||
  186. day < 1 || day > 31) {
  187. console.error("身份证号码中包含无效的出生日期信息。", idCardNumber);
  188. return null;
  189. }
  190. // 更严谨的日期校验:使用Date对象进行验证
  191. // 注意:Date对象的月份是0-11,所以需要 month - 1
  192. const birthDate = new Date(year, month - 1, day);
  193. // 检查解析后的日期是否与输入匹配,以排除像 "20000230" 这样的无效日期(会自动转换为 2000-03-01)
  194. if (birthDate.getFullYear() !== year ||
  195. birthDate.getMonth() !== month - 1 ||
  196. birthDate.getDate() !== day) {
  197. console.error("身份证号码中的出生日期不是一个有效的日历日期。", idCardNumber);
  198. return null;
  199. }
  200. // 5. 获取当前日期
  201. const today = new Date();
  202. const currentYear = today.getFullYear();
  203. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11,所以加1
  204. const currentDay = today.getDate();
  205. // 6. 计算年龄
  206. let age = currentYear - year;
  207. // 如果当前月份小于出生月份,或者当前月份等于出生月份但当前日期小于出生日期,则年龄减1
  208. if (currentMonth < month || (currentMonth === month && currentDay < day)) {
  209. age--;
  210. }
  211. // 确保年龄不为负数(如果身份证日期是未来日期,虽然前面有校验,但以防万一)
  212. if (age < 0) {
  213. console.warn("身份证号码中的出生日期晚于当前日期,返回年龄为0。", idCardNumber);
  214. return 0; // 或者 null,取决于业务需求
  215. }
  216. return age;
  217. }
  218. const getUserLoveTicket = () => {
  219. let userId = JSON.parse(uni.getStorageSync('userInfo'))?.id;
  220. proxy.$api.get(`/core/activity/signup/userAsset/${userId}/${activity.value?.id}`).then(({data:res})=>{
  221. if(res.code!==0) return proxy.$showToast(res.msg)
  222. userLoveTicket.value = res.data;
  223. ticketText.value = `剩余${res.data?.couponIds?.length||0}张可用`;
  224. })
  225. }
  226. const changeAgree = () => {
  227. agree.value = !agree.value;
  228. }
  229. const deleteMember = (item,index) => {
  230. selectMemberList.value.splice(index,1);
  231. payValue.value = selectMemberList.value.length*activity.value?.valueLimit;
  232. }
  233. onLoad(options=>{
  234. activity.value = options.activity&&JSON.parse(decodeURIComponent(options.activity))
  235. })
  236. onMounted(()=>{
  237. getUserLoveTicket()
  238. })
  239. </script>
  240. <style scoped lang="scss">
  241. ::v-deep .u-input__content input{
  242. caret-color: #252525;
  243. }
  244. ::v-deep .u-input__content__field-wrapper__field{
  245. text-align: right !important;
  246. }
  247. .common_page{
  248. padding-bottom: 248rpx;
  249. .box{
  250. margin-top: 20rpx;
  251. background: #FFFFFF;
  252. border-radius: 20rpx;
  253. position: relative;
  254. }
  255. .box1{
  256. &-top{
  257. padding: 36rpx 24rpx 24rpx;
  258. border-bottom: 1rpx solid #E5E7EB;
  259. &>.title{
  260. font-family: PingFang-SC, PingFang-SC;
  261. font-weight: bold;
  262. font-size: 32rpx;
  263. color: #151B29;
  264. line-height: 32rpx;
  265. }
  266. &>.tip{
  267. font-family: PingFangSC, PingFang SC;
  268. font-weight: 400;
  269. font-size: 24rpx;
  270. color: #666666;
  271. line-height: 24rpx;
  272. margin-top: 30rpx;
  273. }
  274. }
  275. &-bottom{
  276. padding: 26rpx 24rpx;
  277. image{
  278. width: 20rpx;
  279. height: 20rpx;
  280. }
  281. text{
  282. font-family: PingFangSC, PingFang SC;
  283. font-weight: 400;
  284. font-size: 24rpx;
  285. color: #C9A771;
  286. line-height: 24rpx;
  287. margin-left: 10rpx;
  288. }
  289. }
  290. }
  291. .box2{
  292. padding: 40rpx 24rpx 48rpx;
  293. &-title{
  294. font-family: PingFang-SC, PingFang-SC;
  295. font-weight: bold;
  296. font-size: 36rpx;
  297. color: #151B29;
  298. line-height: 36rpx;
  299. margin-bottom: 26rpx;
  300. display: inline-block;
  301. }
  302. &-members{
  303. &-pre{
  304. padding: 36rpx 0;
  305. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #F2F2F2;
  306. &-left{
  307. .ltop{
  308. .name{
  309. font-family: PingFang-SC, PingFang-SC;
  310. font-weight: bold;
  311. font-size: 32rpx;
  312. color: #151B29;
  313. line-height: 32rpx;
  314. }
  315. .sex{
  316. width: 44rpx;
  317. height: 32rpx;
  318. margin-left: 20rpx;
  319. }
  320. .age{
  321. border-radius: 13rpx;
  322. font-family: PingFangSC, PingFang SC;
  323. font-weight: 400;
  324. font-size: 20rpx;
  325. line-height: 24rpx;
  326. padding: 4rpx 10rpx;
  327. margin-left: 13rpx;
  328. &.women{
  329. background: rgba(244,101,122,0.14);
  330. color: #F4657A;
  331. }
  332. &.man{
  333. background: rgba(5,169,254,0.12);
  334. color: #05A9FE;
  335. }
  336. }
  337. }
  338. .lbottom{
  339. font-family: PingFangSC, PingFang SC;
  340. font-weight: 400;
  341. font-size: 24rpx;
  342. color: #989998;
  343. line-height: 24rpx;
  344. margin-top: 24rpx;
  345. }
  346. }
  347. &-right{
  348. width: 36rpx;
  349. height: 36rpx;
  350. image{
  351. width: 100%;
  352. height: 100%;
  353. }
  354. }
  355. }
  356. }
  357. &-add{
  358. width: 100%;
  359. height: 78rpx;
  360. background: rgba(112,207,82,0.08);
  361. border-radius: 24rpx;
  362. border: 1rpx dotted #70CF52;
  363. margin-top: 40rpx;
  364. image{
  365. width: 36rpx;
  366. height: 36rpx;
  367. }
  368. text{
  369. font-family: PingFang-SC, PingFang-SC;
  370. font-weight: bold;
  371. font-size: 28rpx;
  372. color: #70CF52;
  373. line-height: 40rpx;
  374. margin-left: 10rpx;
  375. }
  376. }
  377. }
  378. .box3{
  379. &-pre{
  380. padding: 36rpx 24rpx;
  381. &:first-child{
  382. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECEEF5;
  383. }
  384. &-left{
  385. font-family: PingFangSC, PingFang SC;
  386. font-weight: 400;
  387. font-size: 30rpx;
  388. color: #151B29;
  389. line-height: 36rpx;
  390. }
  391. }
  392. }
  393. .box4{
  394. padding: 36rpx 24rpx;
  395. &-left{
  396. font-family: PingFangSC, PingFang SC;
  397. font-weight: 400;
  398. font-size: 30rpx;
  399. color: #151B29;
  400. line-height: 36rpx;
  401. }
  402. &-right{
  403. text{
  404. font-family: PingFangSC, PingFang SC;
  405. font-weight: 400;
  406. font-size: 24rpx;
  407. color: #989998;
  408. line-height: 33rpx;
  409. }
  410. image{
  411. width: 32rpx;
  412. height: 32rpx;
  413. margin-left: 20rpx;
  414. }
  415. }
  416. }
  417. .cbottom{
  418. width: 100%;
  419. position: fixed;
  420. left: 0;
  421. right: 0;
  422. bottom: 0;
  423. &-top{
  424. padding: 0 30rpx;
  425. image{
  426. width: 36rpx;
  427. height: 36rpx;
  428. }
  429. text{
  430. font-family: PingFangSC, PingFang SC;
  431. font-weight: 400;
  432. font-size: 24rpx;
  433. color: #989998;
  434. line-height: 33rpx;
  435. margin-left: 16rpx;
  436. }
  437. }
  438. &-btn{
  439. background: #FFFFFF;
  440. padding: 20rpx 30rpx 44rpx 36rpx;
  441. margin-top: 40rpx;
  442. &-left{
  443. .heart{
  444. image{
  445. width: 30rpx;
  446. height: 30rpx;
  447. }
  448. text{
  449. font-family: PingFang-SC, PingFang-SC;
  450. font-weight: bold;
  451. font-size: 36rpx;
  452. color: #F4657A;
  453. line-height: 36rpx;
  454. margin-left: 2rpx;
  455. }
  456. }
  457. .text{
  458. font-family: PingFangSC, PingFang SC;
  459. font-weight: 400;
  460. font-size: 24rpx;
  461. color: #252525;
  462. line-height: 24rpx;
  463. margin-top: 11rpx;
  464. }
  465. .free{
  466. font-family: PingFangSC, PingFang SC;
  467. font-weight: 400;
  468. font-size: 32rpx;
  469. color: #252525;
  470. line-height: 32rpx;
  471. }
  472. }
  473. &-right{
  474. width: 528rpx;
  475. height: 90rpx;
  476. background: #B7F358;
  477. border-radius: 45rpx;
  478. font-family: PingFang-SC, PingFang-SC;
  479. font-weight: bold;
  480. font-size: 32rpx;
  481. color: #151B29;
  482. line-height: 90rpx;
  483. text-align: center;
  484. letter-spacing: 2rpx;
  485. }
  486. }
  487. }
  488. }
  489. </style>