nonprofit.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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"></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 initList = () => {
  57. queryParams.value.page = 1;
  58. isOver.value = false;
  59. list.value = [];
  60. }
  61. const getList = () => {
  62. proxy.$api.get('/core/activity/signup/myActivityList',queryParams.value).then(({data:res})=>{
  63. if(res.code!==0) return proxy.$showToast(res.msg)
  64. list.value = [...list.value,...res.data.list];
  65. list.value.forEach(l=>{
  66. l.activityStartTime = new Date(l.activityStartTime).Format('yyyy-MM-dd')
  67. l.activityEndTime = new Date(l.activityEndTime).Format('yyyy-MM-dd')
  68. l.age = getAge(l.idCard)
  69. })
  70. queryParams.value.page++;
  71. if(res.data.list.length) isOver.value = true;
  72. })
  73. }
  74. const isValid = (idCard) => {
  75. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  76. 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]$/;
  77. return typeof idCard === 'string' && regex.test(idCard);
  78. }
  79. const getAge = (idCard) => {
  80. if (!isValid(idCard)) return 0
  81. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  82. const birthDateStr = idCard.substring(6, 14);
  83. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  84. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  85. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  86. const today = new Date();
  87. const currentYear = today.getFullYear();
  88. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  89. const currentDay = today.getDate();
  90. // 计算周岁
  91. let age = currentYear - birthYear;
  92. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  93. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  94. age--;
  95. }
  96. return age < 0 ? 0 : age;
  97. }
  98. watch(()=>tidx.value,(newVal)=>{
  99. text.value = `暂无${statusCfg.value[newVal]}活动`;
  100. })
  101. onShow(()=>{
  102. let pages = getCurrentPages();
  103. let options = pages[pages.length-1]?.options;
  104. queryParams.value.userId = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
  105. if(+options?.type) tidx.value = +options.type;
  106. queryParams.value.activeState = tidx.value;
  107. initList()
  108. getList()
  109. })
  110. </script>
  111. <style scoped lang="scss">
  112. .dataEmpty{
  113. padding-bottom: 184rpx;
  114. }
  115. .tab_page{
  116. padding: 0;
  117. .tab{
  118. height: 110rpx;
  119. padding: 40rpx 24rpx 0;
  120. box-sizing: border-box;
  121. background: #FFFFFF;
  122. &-pre{
  123. width: calc(100% / 3);
  124. position: relative;
  125. font-family: PingFangSC, PingFang SC;
  126. font-weight: 400;
  127. font-size: 30rpx;
  128. color: #676775;
  129. line-height: 30rpx;
  130. text-align: center;
  131. &.active{
  132. font-weight: bold;
  133. font-size: 32rpx;
  134. color: #151B29;
  135. &::after{
  136. content: '';
  137. width: 100%;
  138. height: 6rpx;
  139. background: #252525;
  140. position: absolute;
  141. left: 0;
  142. bottom: 0;
  143. }
  144. }
  145. }
  146. }
  147. .list{
  148. flex: 1;
  149. overflow-y: auto;
  150. padding: 0 24rpx 184rpx;
  151. box-sizing: border-box;
  152. }
  153. }
  154. </style>