nonprofit.vue 5.2 KB

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