nonprofit.vue 5.0 KB

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