archives.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title="我的档案" bgColor="#FFFFFF"></cus-header>
  4. <view class="member">
  5. <scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation="true" :scroll-left="scrollLeft">
  6. <view class="scroll-view-item_H" :id="'svih_'+index" v-for="(item,index) in memberList" :key="index" @click="changeMember(item,index)">
  7. <view class="cl_item" :class="{'active':midx===index}">
  8. <text>{{item.name}}</text>
  9. </view>
  10. </view>
  11. </scroll-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. <ArchivesBox :item="item" @handleReviewFile="handleReview"></ArchivesBox>
  17. </up-list-item>
  18. </up-list>
  19. <ArchivesBox v-for="(item,index) in list" :key="index"></ArchivesBox>
  20. </view>
  21. <view class="dataEmpty" v-else>
  22. <page-empty text="暂无档案记录"></page-empty>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup name="">
  27. import CusHeader from '@/components/CusHeader/index.vue'
  28. import ArchivesBox from '@/components/pages/archivesBox/index.vue'
  29. import PageEmpty from '@/components/pageEmpty/index.vue'
  30. import { ref, getCurrentInstance, onMounted } from 'vue'
  31. const { proxy } = getCurrentInstance()
  32. const midx = ref('')
  33. const scrollLeft = ref(0)
  34. const memberList = ref([])
  35. const isOver = ref(false)
  36. const queryParams = ref({
  37. page:1,
  38. limit:10,
  39. memberId:'',
  40. userId:''
  41. })
  42. const list = ref([])
  43. const initList = () => {
  44. queryParams.value.page = 1;
  45. isOver.value = false;
  46. list.value = [];
  47. }
  48. const changeMember = (item,index) => {
  49. midx.value = index;
  50. queryParams.value.memberId = item.id;
  51. initList()
  52. getList()
  53. }
  54. const getMemberList = () => {
  55. proxy.$api.get('/core/family/member/page',{page:1,limit:-1}).then(({data:res})=>{
  56. if(res.code!==0) return proxy.$showToast(res.msg)
  57. memberList.value = res.data.list||[];
  58. })
  59. }
  60. const getList = () => {
  61. proxy.$api.get('/core/activity/signup/memberProfileList',queryParams.value).then(({data:res})=>{
  62. if(res.code!==0) return proxy.$showToast(res.msg)
  63. list.value = [...list.value,...res.data.list];
  64. list.value.forEach(l=>{
  65. l.age = getAge(l.idCard)
  66. })
  67. queryParams.value.page++;
  68. if(res.data.list.length===0) isOver.value = true;
  69. })
  70. }
  71. const isValid = (idCard) => {
  72. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  73. 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]$/;
  74. return typeof idCard === 'string' && regex.test(idCard);
  75. }
  76. const getAge = (idCard) => {
  77. if (!isValid(idCard)) return 0
  78. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  79. const birthDateStr = idCard.substring(6, 14);
  80. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  81. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  82. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  83. const today = new Date();
  84. const currentYear = today.getFullYear();
  85. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  86. const currentDay = today.getDate();
  87. // 计算周岁
  88. let age = currentYear - birthYear;
  89. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  90. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  91. age--;
  92. }
  93. return age < 0 ? 0 : age;
  94. }
  95. const scrolltolower = () => {
  96. if(isOver.value) return
  97. getList()
  98. }
  99. const handleReview = (data) => {
  100. uni.navigateTo({
  101. url:'/pagesMy/archivesDetail?activityId='+data?.activityId+'&memberId='+data?.memberId
  102. })
  103. }
  104. onMounted(()=>{
  105. queryParams.value.userId = uni.getStorageSync('userInfo')&&JSON.parse(uni.getStorageSync('userInfo')).id;
  106. getMemberList()
  107. getList()
  108. })
  109. </script>
  110. <style scoped lang="scss">
  111. .scroll-view_H {
  112. white-space: nowrap;
  113. width: 100%;
  114. }
  115. .scroll-view-item_H {
  116. display: inline-block;
  117. height: 100%;
  118. margin-left: 30rpx;
  119. &:first-child{
  120. margin-left: 0;
  121. }
  122. }
  123. .common_page{
  124. padding: 0 0 40rpx;
  125. box-sizing: border-box;
  126. .member{
  127. width: 100%;
  128. height: 56rpx;
  129. padding: 0 30rpx;
  130. margin-top: 20rpx;
  131. box-sizing: border-box;
  132. .cl_item{
  133. padding: 0 26rpx;
  134. height: 56rpx;
  135. background: #FFFFFF;
  136. border-radius: 10rpx;
  137. font-family: PingFangSC, PingFang SC;
  138. font-weight: 400;
  139. font-size: 26rpx;
  140. color: #252525;
  141. line-height: 56rpx;
  142. text-align: center;
  143. &.active{
  144. background: #B7F358;
  145. }
  146. }
  147. }
  148. .list{
  149. padding: 0 24rpx;
  150. flex: 1;
  151. overflow-y: auto;
  152. margin-top: 4rpx;
  153. }
  154. }
  155. </style>