nonprofit.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="tab_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <up-navbar title="我的公益" bgColor="#FFFFFF">
  4. <template #left></template>
  5. </up-navbar>
  6. <view class="tab adf">
  7. <view class="tab-pre" :class="{'active':tidx===1}" @click="changeTab(1)">未开始</view>
  8. <view class="tab-pre" :class="{'active':tidx===2}" @click="changeTab(2)">进行中</view>
  9. <view class="tab-pre" :class="{'active':tidx===3}" @click="changeTab(3)">已结束</view>
  10. </view>
  11. <view class="list" v-if="list.length">
  12. <up-list @scrolltolower="scrolltolower" style="height: 100%;">
  13. <up-list-item v-for="(item, index) in list" :key="index">
  14. <NonprofitItem :item="item" @click="toDetail(item)"></NonprofitItem>
  15. </up-list-item>
  16. </up-list>
  17. </view>
  18. <view class="dataEmpty" v-else>
  19. <page-empty :text="text"></page-empty>
  20. </view>
  21. <CusTabbar :tabbarIndex="1"></CusTabbar>
  22. </view>
  23. </template>
  24. <script setup name="">
  25. import CusTabbar from '@/components/CusTabbar/index.vue'
  26. import NonprofitItem from '@/components/pages/nonprofitItem/index.vue'
  27. import pageEmpty from '@/components/pageEmpty/index.vue'
  28. import { ref, getCurrentInstance, watch } from 'vue'
  29. import { onLoad, onShow } from '@dcloudio/uni-app'
  30. const { proxy } = getCurrentInstance()
  31. const tidx = ref(1)
  32. const text = ref('暂无进行中活动')
  33. const queryParams = ref({
  34. page: 1,
  35. limit: 10,
  36. activeState: 1, //0待开始 1报名中 2进行中 3已结束
  37. userId:''
  38. })
  39. const statusCfg = ref({
  40. 1:'未开始',
  41. 2:'进行中',
  42. 3:'已结束'
  43. })
  44. const isOver = ref(false)
  45. const list = ref([])
  46. const changeTab = index => {
  47. tidx.value = index;
  48. queryParams.value.activeState = index;
  49. initList();
  50. getList();
  51. }
  52. const scrolltolower = () => {
  53. if(isOver.value) return
  54. getList();
  55. }
  56. const toDetail = item => {
  57. uni.navigateTo({
  58. url:'/pagesNonprofit/nonprofitDetail?memberSignupId='+item?.memberSignupId
  59. })
  60. }
  61. const initList = () => {
  62. queryParams.value.page = 1;
  63. isOver.value = false;
  64. list.value = [];
  65. }
  66. const getList = () => {
  67. proxy.$api.get('/core/activity/signup/myActivityList',queryParams.value).then(({data:res})=>{
  68. if(res.code!==0) return proxy.$showToast(res.msg)
  69. list.value = [...list.value,...res.data.list];
  70. list.value.forEach(l=>{
  71. l.activityStartTime = new Date(l.activityStartTime).Format('yyyy-MM-dd')
  72. l.activityEndTime = new Date(l.activityEndTime).Format('yyyy-MM-dd')
  73. l.age = getAge(l.idCard)
  74. })
  75. queryParams.value.page++;
  76. if(res.data.list.length) isOver.value = true;
  77. })
  78. }
  79. const isValid = (idCard) => {
  80. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  81. const regex = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  82. return typeof idCard === 'string' && regex.test(idCard);
  83. }
  84. const getAge = (idCard) => {
  85. if (!isValid(idCard)) return 0
  86. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  87. const birthDateStr = idCard.substring(6, 14);
  88. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  89. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  90. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  91. const today = new Date();
  92. const currentYear = today.getFullYear();
  93. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  94. const currentDay = today.getDate();
  95. // 计算周岁
  96. let age = currentYear - birthYear;
  97. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  98. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  99. age--;
  100. }
  101. return age < 0 ? 0 : age;
  102. }
  103. watch(()=>tidx.value,(newVal)=>{
  104. text.value = `暂无${statusCfg.value[newVal]}活动`;
  105. })
  106. onShow(()=>{
  107. let pages = getCurrentPages();
  108. let options = pages[pages.length-1]?.options;
  109. queryParams.value.userId = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
  110. if(+options?.type) tidx.value = +options.type;
  111. queryParams.value.activeState = tidx.value;
  112. initList()
  113. getList()
  114. })
  115. </script>
  116. <style scoped lang="scss">
  117. .dataEmpty{
  118. padding-bottom: 184rpx;
  119. }
  120. .tab_page{
  121. padding: 0;
  122. .tab{
  123. height: 110rpx;
  124. padding: 40rpx 24rpx 0;
  125. box-sizing: border-box;
  126. background: #FFFFFF;
  127. &-pre{
  128. width: calc(100% / 3);
  129. position: relative;
  130. font-family: PingFangSC, PingFang SC;
  131. font-weight: 400;
  132. font-size: 30rpx;
  133. color: #676775;
  134. line-height: 30rpx;
  135. text-align: center;
  136. &.active{
  137. font-weight: bold;
  138. font-size: 32rpx;
  139. color: #151B29;
  140. &::after{
  141. content: '';
  142. width: 100%;
  143. height: 6rpx;
  144. background: #252525;
  145. position: absolute;
  146. left: 0;
  147. bottom: 0;
  148. }
  149. }
  150. }
  151. }
  152. .list{
  153. flex: 1;
  154. overflow-y: auto;
  155. padding: 0 24rpx 184rpx;
  156. box-sizing: border-box;
  157. }
  158. }
  159. </style>