practice.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px', 'padding-bottom':pb+'rpx'}">
  3. <cus-header title="申领社会实践记录" bgColor="#FFFFFF"></cus-header>
  4. <div class="tab adf">
  5. <div class="tab-pre adfacjc" :class="{'active':tidx===1}" @tap="changeTab(1)">可申领</div>
  6. <div class="tab-pre adfacjc" :class="{'active':tidx===2}" @tap="changeTab(2)">已申领</div>
  7. </div>
  8. <div class="member">
  9. <scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation="true" :scroll-left="scrollLeft">
  10. <view class="scroll-view-item_H" :id="'svih_'+index" v-for="(item,index) in memberList" :key="index" @tap="changeMember(item,index)">
  11. <view class="cl_item" :class="{'active':midx===index}">
  12. <text>{{item.name}}</text>
  13. </view>
  14. </view>
  15. </scroll-view>
  16. </div>
  17. <template v-if="tidx===1">
  18. <div class="list" v-if="list.length">
  19. <up-list @scrolltolower="scrolltolower" style="height: 100%;">
  20. <up-list-item v-for="(item, index) in list" :key="index">
  21. <practice-box :item="item" @itemCheck="handleCheck"></practice-box>
  22. </up-list-item>
  23. </up-list>
  24. </div>
  25. <div class="dataEmpty" v-else>
  26. <page-empty text="暂无已申领记录"></page-empty>
  27. </div>
  28. <div class="btn" @click="handleApply">申领社会实践记录</div>
  29. </template>
  30. <template v-else-if="tidx===2">
  31. <div class="list" v-if="yslList.length">
  32. <up-list @scrolltolower="scrolltolower" style="height: 100%;">
  33. <up-list-item v-for="(item, index) in yslList" :key="index">
  34. <div class="ysl-box">
  35. <div class="ysl-box-title">{{'感恩有你 温暖前行'}}</div>
  36. <div class="ysl-box-tip">申领时间:{{'2025-06-01 ~ 2025-07-01'}}</div>
  37. <div class="ysl-box-tip">申 领 人:{{'张琳琳'}}</div>
  38. <div class="ysl-box-btn" @tap="handleDetail(item)">查看</div>
  39. </div>
  40. </up-list-item>
  41. </up-list>
  42. </div>
  43. <div class="dataEmpty" v-else>
  44. <page-empty text="暂无已申领记录"></page-empty>
  45. </div>
  46. </template>
  47. </view>
  48. </template>
  49. <script setup name="">
  50. import CusHeader from '@/components/CusHeader/index.vue'
  51. import PageEmpty from '@/components/pageEmpty/index.vue'
  52. import PracticeBox from '@/components/pages/practiceBox/index.vue'
  53. import { ref, getCurrentInstance, onMounted } from 'vue'
  54. const { proxy } = getCurrentInstance()
  55. const pb = ref(184)
  56. const tidx = ref(1)
  57. const midx = ref(0)
  58. const scrollLeft = ref(0)
  59. const queryParams = ref({
  60. page:1,
  61. limit:10,
  62. userId:'',
  63. memberId:''
  64. })
  65. const isOver = ref(false)
  66. const memberList = ref([])
  67. const list = ref([])
  68. const yslList = ref([])
  69. const changeTab = index => {
  70. tidx.value = index;
  71. pb.value = index===1?184:40;
  72. getDataByTab()
  73. }
  74. const changeMember = (item,index) => {
  75. midx.value = index;
  76. queryParams.value.memberId = item.id;
  77. getDataByTab()
  78. }
  79. const getDataByTab = () => {
  80. queryParams.value.page = 1;
  81. isOver.value = false;
  82. list.value = [];
  83. yslList.value = [1];
  84. if(!queryParams.value.memberId) queryParams.value.memberId = memberList.value[0]?.id;
  85. if(tidx.value===1){
  86. getKslList()
  87. }else if(tidx.value===2){
  88. getYslList()
  89. }
  90. }
  91. const handleDetail = item => {
  92. uni.navigateTo({
  93. url:'/pagesMy/practiceRecord'
  94. })
  95. }
  96. const scrolltolower = () => {
  97. if(isOver.value) return
  98. getDataByTab()
  99. }
  100. const getKslList = () => {
  101. proxy.$api.get('/core/social/practice/record/claimPage',queryParams.value).then(({data:res})=>{
  102. if(res.code!==0) return proxy.$showToast(res.msg)
  103. list.value = [...list.value,...res.data.list]
  104. list.value.forEach(l=>{
  105. l.activityStartTime = new Date(l.activityStartTime).Format('yyyy-MM-dd');
  106. l.activityEndTime = new Date(l.activityEndTime).Format('yyyy-MM-dd');
  107. l.check = false;
  108. l.age = getAge(l.idCard);
  109. })
  110. queryParams.value.page++;
  111. if(res.data.list.length===0) isOver.value = true
  112. })
  113. }
  114. const getYslList = () => {
  115. proxy.$api.get('/core/social/practice/record/claimedPage',queryParams.value).then(({data:res})=>{
  116. if(res.code!==0) return proxy.$showToast(res.msg)
  117. // yslList.value = [...yslList.value,...res.data.list]
  118. // queryParams.value.page++;
  119. // if(res.data.list.length===0) isOver.value = true
  120. })
  121. }
  122. const getMemberList = () => {
  123. proxy.$api.get('/core/family/member/page',{page:1,limit:-1}).then(({data:res})=>{
  124. if(res.code!==0) return proxy.$showToast(res.msg)
  125. memberList.value = res.data.list;
  126. getDataByTab()
  127. })
  128. }
  129. const isValid = (idCard) => {
  130. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  131. 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]$/;
  132. return typeof idCard === 'string' && regex.test(idCard);
  133. }
  134. const getAge = (idCard) => {
  135. if (!isValid(idCard)) return 0
  136. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  137. const birthDateStr = idCard.substring(6, 14);
  138. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  139. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  140. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  141. const today = new Date();
  142. const currentYear = today.getFullYear();
  143. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  144. const currentDay = today.getDate();
  145. // 计算周岁
  146. let age = currentYear - birthYear;
  147. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  148. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  149. age--;
  150. }
  151. return age < 0 ? 0 : age;
  152. }
  153. const handleCheck = (item) => {
  154. item.check = !item.check;
  155. }
  156. const handleApply = () => {
  157. }
  158. onMounted(()=>{
  159. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  160. getMemberList();
  161. })
  162. </script>
  163. <style scoped lang="scss">
  164. .scroll-view_H {
  165. white-space: nowrap;
  166. width: 100%;
  167. }
  168. .scroll-view-item_H {
  169. display: inline-block;
  170. height: 100%;
  171. margin-left: 30rpx;
  172. &:first-child{
  173. margin-left: 0;
  174. }
  175. }
  176. .common_page{
  177. padding: 0;
  178. box-sizing: border-box;
  179. .tab{
  180. width: 100%;
  181. height: 102rpx;
  182. background: #FFFFFF;
  183. &-pre{
  184. width: 50%;
  185. height: 102rpx;
  186. position: relative;
  187. font-family: PingFangSC, PingFang SC;
  188. font-weight: 400;
  189. font-size: 32rpx;
  190. color: #676775;
  191. line-height: 48rpx;
  192. &.active{
  193. font-weight: bold;
  194. font-size: 36rpx;
  195. color: #252525;
  196. &::after{
  197. content: '';
  198. width: 42rpx;
  199. height: 6rpx;
  200. background: #B7F358;
  201. border-radius: 3rpx;
  202. position: absolute;
  203. left: 50%;
  204. margin-left: -21rpx;
  205. bottom: 6rpx;
  206. }
  207. }
  208. }
  209. }
  210. .member{
  211. width: 100%;
  212. height: 56rpx;
  213. padding: 0 30rpx;
  214. margin-top: 20rpx;
  215. box-sizing: border-box;
  216. .cl_item{
  217. padding: 0 26rpx;
  218. height: 56rpx;
  219. background: #FFFFFF;
  220. border-radius: 10rpx;
  221. font-family: PingFangSC, PingFang SC;
  222. font-weight: 400;
  223. font-size: 26rpx;
  224. color: #252525;
  225. line-height: 56rpx;
  226. text-align: center;
  227. &.active{
  228. background: #B7F358;
  229. }
  230. }
  231. }
  232. .list{
  233. padding: 0 24rpx;
  234. flex: 1;
  235. overflow-y: auto;
  236. margin-top: 4rpx;
  237. .ysl-box{
  238. margin-top: 20rpx;
  239. padding: 36rpx 24rpx;
  240. position: relative;
  241. background: linear-gradient(45deg, #FFFFFF 80%, #F2FFE8 100%);
  242. &-title{
  243. font-family: PingFang-SC, PingFang-SC;
  244. font-weight: bold;
  245. font-size: 32rpx;
  246. color: #151B29;
  247. line-height: 40rpx;
  248. }
  249. &-tip{
  250. font-family: PingFangSC, PingFang SC;
  251. font-weight: 400;
  252. font-size: 24rpx;
  253. color: #676775;
  254. line-height: 24rpx;
  255. margin-top: 30rpx;
  256. }
  257. &-btn{
  258. width: 118rpx;
  259. height: 64rpx;
  260. background: #B7F358;
  261. border-radius: 45rpx;
  262. font-family: PingFang-SC, PingFang-SC;
  263. font-weight: bold;
  264. font-size: 26rpx;
  265. color: #151B29;
  266. line-height: 64rpx;
  267. text-align: center;
  268. letter-spacing: 2rpx;
  269. position: absolute;
  270. right: 24rpx;
  271. bottom: 40rpx;
  272. }
  273. }
  274. }
  275. .btn{
  276. width: calc(100% - 210rpx);
  277. height: 90rpx;
  278. background: #B7F358;
  279. border-radius: 45rpx;
  280. font-family: PingFang-SC, PingFang-SC;
  281. font-weight: bold;
  282. font-size: 32rpx;
  283. color: #151B29;
  284. line-height: 90rpx;
  285. text-align: center;
  286. letter-spacing: 2rpx;
  287. position: fixed;
  288. left: 105rpx;
  289. bottom: 64rpx;
  290. }
  291. }
  292. </style>