nonprofit.vue 5.3 KB

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