activityApply.vue 16 KB

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