activityApply.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. <input v-model="submitDto.contact" style="font-size: 30rpx;color: #151B29;text-align: right;" placeholder="请输入联系人姓名"></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. <input v-model="submitDto.contactPhone" style="font-size: 30rpx;color: #151B29;text-align: right;" placeholder="请输入联系人电话"></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. try{
  239. submitDto.value.contact = JSON.parse(uni.getStorageSync('userInfo')).realName;
  240. submitDto.value.contactPhone = JSON.parse(uni.getStorageSync('userInfo')).phone;
  241. }catch(e){
  242. //TODO handle the exception
  243. }
  244. })
  245. </script>
  246. <style scoped lang="scss">
  247. ::v-deep .u-input__content__field-wrapper__field{
  248. text-align: right !important;
  249. }
  250. .common_page{
  251. padding-bottom: 248rpx;
  252. .box{
  253. margin-top: 20rpx;
  254. background: #FFFFFF;
  255. border-radius: 20rpx;
  256. position: relative;
  257. }
  258. .box1{
  259. &-top{
  260. padding: 36rpx 24rpx 24rpx;
  261. border-bottom: 1rpx solid #E5E7EB;
  262. &>.title{
  263. font-family: PingFang-SC, PingFang-SC;
  264. font-weight: bold;
  265. font-size: 32rpx;
  266. color: #151B29;
  267. line-height: 32rpx;
  268. }
  269. &>.tip{
  270. font-family: PingFangSC, PingFang SC;
  271. font-weight: 400;
  272. font-size: 24rpx;
  273. color: #666666;
  274. line-height: 24rpx;
  275. margin-top: 30rpx;
  276. }
  277. }
  278. &-bottom{
  279. padding: 26rpx 24rpx;
  280. image{
  281. width: 20rpx;
  282. height: 20rpx;
  283. }
  284. text{
  285. font-family: PingFangSC, PingFang SC;
  286. font-weight: 400;
  287. font-size: 24rpx;
  288. color: #C9A771;
  289. line-height: 24rpx;
  290. margin-left: 10rpx;
  291. }
  292. }
  293. }
  294. .box2{
  295. padding: 40rpx 24rpx 48rpx;
  296. &-title{
  297. font-family: PingFang-SC, PingFang-SC;
  298. font-weight: bold;
  299. font-size: 36rpx;
  300. color: #151B29;
  301. line-height: 36rpx;
  302. margin-bottom: 26rpx;
  303. display: inline-block;
  304. }
  305. &-members{
  306. &-pre{
  307. padding: 36rpx 0;
  308. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #F2F2F2;
  309. &-left{
  310. .ltop{
  311. .name{
  312. font-family: PingFang-SC, PingFang-SC;
  313. font-weight: bold;
  314. font-size: 32rpx;
  315. color: #151B29;
  316. line-height: 32rpx;
  317. }
  318. .sex{
  319. width: 44rpx;
  320. height: 32rpx;
  321. margin-left: 20rpx;
  322. }
  323. .age{
  324. border-radius: 13rpx;
  325. font-family: PingFangSC, PingFang SC;
  326. font-weight: 400;
  327. font-size: 20rpx;
  328. line-height: 24rpx;
  329. padding: 4rpx 10rpx;
  330. margin-left: 13rpx;
  331. &.women{
  332. background: rgba(244,101,122,0.14);
  333. color: #F4657A;
  334. }
  335. &.man{
  336. background: rgba(5,169,254,0.12);
  337. color: #05A9FE;
  338. }
  339. }
  340. }
  341. .lbottom{
  342. font-family: PingFangSC, PingFang SC;
  343. font-weight: 400;
  344. font-size: 24rpx;
  345. color: #989998;
  346. line-height: 24rpx;
  347. margin-top: 24rpx;
  348. }
  349. }
  350. &-right{
  351. width: 36rpx;
  352. height: 36rpx;
  353. image{
  354. width: 100%;
  355. height: 100%;
  356. }
  357. }
  358. }
  359. }
  360. &-add{
  361. width: 100%;
  362. height: 78rpx;
  363. background: rgba(112,207,82,0.08);
  364. border-radius: 24rpx;
  365. border: 1rpx dotted #70CF52;
  366. margin-top: 40rpx;
  367. image{
  368. width: 36rpx;
  369. height: 36rpx;
  370. }
  371. text{
  372. font-family: PingFang-SC, PingFang-SC;
  373. font-weight: bold;
  374. font-size: 28rpx;
  375. color: #70CF52;
  376. line-height: 40rpx;
  377. margin-left: 10rpx;
  378. }
  379. }
  380. }
  381. .box3{
  382. &-pre{
  383. padding: 36rpx 24rpx;
  384. &:first-child{
  385. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECEEF5;
  386. }
  387. &-left{
  388. font-family: PingFangSC, PingFang SC;
  389. font-weight: 400;
  390. font-size: 30rpx;
  391. color: #151B29;
  392. line-height: 36rpx;
  393. }
  394. }
  395. }
  396. .box4{
  397. padding: 36rpx 24rpx;
  398. &-left{
  399. font-family: PingFangSC, PingFang SC;
  400. font-weight: 400;
  401. font-size: 30rpx;
  402. color: #151B29;
  403. line-height: 36rpx;
  404. }
  405. &-right{
  406. text{
  407. font-family: PingFangSC, PingFang SC;
  408. font-weight: 400;
  409. font-size: 24rpx;
  410. color: #989998;
  411. line-height: 33rpx;
  412. }
  413. image{
  414. width: 32rpx;
  415. height: 32rpx;
  416. margin-left: 20rpx;
  417. }
  418. }
  419. }
  420. .cbottom{
  421. width: 100%;
  422. position: fixed;
  423. left: 0;
  424. right: 0;
  425. bottom: 0;
  426. &-top{
  427. padding: 0 30rpx;
  428. image{
  429. width: 36rpx;
  430. height: 36rpx;
  431. }
  432. text{
  433. font-family: PingFangSC, PingFang SC;
  434. font-weight: 400;
  435. font-size: 24rpx;
  436. color: #989998;
  437. line-height: 33rpx;
  438. margin-left: 16rpx;
  439. }
  440. }
  441. &-btn{
  442. background: #FFFFFF;
  443. padding: 20rpx 30rpx 44rpx 36rpx;
  444. margin-top: 40rpx;
  445. &-left{
  446. .heart{
  447. image{
  448. width: 30rpx;
  449. height: 30rpx;
  450. }
  451. text{
  452. font-family: PingFang-SC, PingFang-SC;
  453. font-weight: bold;
  454. font-size: 36rpx;
  455. color: #F4657A;
  456. line-height: 36rpx;
  457. margin-left: 2rpx;
  458. }
  459. }
  460. .text{
  461. font-family: PingFangSC, PingFang SC;
  462. font-weight: 400;
  463. font-size: 24rpx;
  464. color: #252525;
  465. line-height: 24rpx;
  466. margin-top: 11rpx;
  467. }
  468. .free{
  469. font-family: PingFangSC, PingFang SC;
  470. font-weight: 400;
  471. font-size: 32rpx;
  472. color: #252525;
  473. line-height: 32rpx;
  474. }
  475. }
  476. &-right{
  477. width: 528rpx;
  478. height: 90rpx;
  479. background: #B7F358;
  480. border-radius: 45rpx;
  481. font-family: PingFang-SC, PingFang-SC;
  482. font-weight: bold;
  483. font-size: 32rpx;
  484. color: #151B29;
  485. line-height: 90rpx;
  486. text-align: center;
  487. letter-spacing: 2rpx;
  488. }
  489. }
  490. }
  491. }
  492. </style>