| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <template>
- <view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px', 'padding-bottom':pb+'rpx'}">
- <cus-header title="申领社会实践记录" bgColor="#FFFFFF"></cus-header>
- <view class="tab adf">
- <view class="tab-pre adfacjc" :class="{'active':tidx===1}" @click="changeTab(1)">可申领</view>
- <view class="tab-pre adfacjc" :class="{'active':tidx===2}" @click="changeTab(2)">已申领</view>
- </view>
- <view class="member">
- <scroll-view class="scroll-view_H" scroll-x="true" scroll-with-animation="true" :scroll-left="scrollLeft">
- <view class="scroll-view-item_H" :id="'svih_'+index" v-for="(item,index) in memberList" :key="index" @click="changeMember(item,index)">
- <view class="cl_item" :class="{'active':midx===index}">
- <text>{{item.name}}</text>
- </view>
- </view>
- </scroll-view>
- </view>
- <template v-if="tidx===1">
- <view class="list" v-if="list.length">
- <up-list @scrolltolower="scrolltolower" style="height: 100%;">
- <up-list-item v-for="(item, index) in list" :key="index">
- <practice-box :item="item" @itemCheck="handleCheck"></practice-box>
- </up-list-item>
- </up-list>
- </view>
- <view class="dataEmpty" v-else>
- <page-empty text="暂无已申领记录"></page-empty>
- </view>
- <view class="btn" @click="handleApply">申领社会实践记录</view>
- </template>
- <template v-else-if="tidx===2">
- <view class="list" v-if="yslList.length">
- <up-list @scrolltolower="scrolltolower" style="height: 100%;">
- <up-list-item v-for="(item, index) in yslList" :key="index">
- <view class="ysl-box">
- <view class="ysl-box-title">证书编号:{{item?.certificateNumber||''}}</view>
- <view class="ysl-box-tip">申领时间:{{item?.createDate||''}}</view>
- <view class="ysl-box-tip">申 领 人:{{item?.memberName||''}}</view>
- <view class="ysl-box-btn" @click="handleDetail(item)">查看</view>
- </view>
- </up-list-item>
- </up-list>
- </view>
- <view class="dataEmpty" v-else>
- <page-empty text="暂无已申领记录"></page-empty>
- </view>
- </template>
- </view>
- </template>
- <script setup name="">
- import CusHeader from '@/components/CusHeader/index.vue'
- import PageEmpty from '@/components/pageEmpty/index.vue'
- import PracticeBox from '@/components/pages/practiceBox/index.vue'
- import { ref, getCurrentInstance, onMounted } from 'vue'
- const { proxy } = getCurrentInstance()
-
- const pb = ref(184)
- const tidx = ref(1)
- const midx = ref(0)
- const scrollLeft = ref(0)
- const queryParams = ref({
- page:1,
- limit:10,
- userId:'',
- memberId:''
- })
- const isOver = ref(false)
- const memberList = ref([])
- const list = ref([])
- const yslList = ref([])
- const changeTab = index => {
- tidx.value = index;
- pb.value = index===1?184:40;
- getDataByTab()
- }
-
- const changeMember = (item,index) => {
- midx.value = index;
- queryParams.value.memberId = item.id;
- getDataByTab()
- }
-
- const getDataByTab = () => {
- queryParams.value.page = 1;
- isOver.value = false;
- list.value = [];
- yslList.value = [];
- if(!queryParams.value.memberId) queryParams.value.memberId = memberList.value[0]?.id;
- if(tidx.value===1){
- getKslList()
- }else if(tidx.value===2){
- getYslList()
- }
- }
-
- const handleDetail = item => {
- uni.navigateTo({
- url:'/pagesMy/practiceRecord?id='+item.id
- })
- }
-
- const scrolltolower = () => {
- if(isOver.value) return
- getDataByTab()
- }
-
- const getKslList = () => {
- proxy.$api.get('/core/social/practice/record/claimPage',queryParams.value).then(({data:res})=>{
- if(res.code!==0) return proxy.$showToast(res.msg)
- list.value = [...list.value,...res.data.list]
- list.value.forEach(l=>{
- l.activityStartTime = new Date(l.activityStartTime).Format('yyyy-MM-dd');
- l.activityEndTime = new Date(l.activityEndTime).Format('yyyy-MM-dd');
- l.check = false;
- l.age = getAge(l.idCard);
- })
- queryParams.value.page++;
- if(res.data.list.length===0) isOver.value = true
- })
- }
-
- const getYslList = () => {
- proxy.$api.get('/core/social/practice/record/claimedPage',queryParams.value).then(({data:res})=>{
- if(res.code!==0) return proxy.$showToast(res.msg)
- yslList.value = [...yslList.value,...res.data.list]
- queryParams.value.page++;
- if(res.data.list.length===0) isOver.value = true
- })
- }
-
- const getMemberList = () => {
- proxy.$api.get('/core/family/member/page',{page:1,limit:-1}).then(({data:res})=>{
- if(res.code!==0) return proxy.$showToast(res.msg)
- memberList.value = res.data.list;
- getDataByTab()
- })
- }
-
- const isValid = (idCard) => {
- // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
- 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]$/;
- return typeof idCard === 'string' && regex.test(idCard);
- }
-
- const getAge = (idCard) => {
- if (!isValid(idCard)) return 0
-
- // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
- const birthDateStr = idCard.substring(6, 14);
- const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
- const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
- const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
-
- const today = new Date();
- const currentYear = today.getFullYear();
- const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
- const currentDay = today.getDate();
-
- // 计算周岁
- let age = currentYear - birthYear;
-
- // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
- if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
- age--;
- }
-
- return age < 0 ? 0 : age;
- }
-
- const handleCheck = (item) => {
- item.check = !item.check;
- }
-
- const handleApply = () => {
- let activityIds = list.value.filter(l=>l.check).map(l=>l.activityId);
- if(activityIds.length===0) return proxy.$showToast('请至少选择一条记录')
-
- proxy.$api.post('/core/social/practice/record',{
- activityIds,
- memberId:queryParams.value.memberId
- }).then(({data:res})=>{
- if(res.code!==0) return proxy.$showToast(res.msg)
- tidx.value = 2;
- getDataByTab()
- proxy.$showToast('申领成功')
- })
- }
-
- onMounted(()=>{
- queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
- getMemberList();
- })
- </script>
- <style scoped lang="scss">
- .scroll-view_H {
- white-space: nowrap;
- width: 100%;
- }
-
- .scroll-view-item_H {
- display: inline-block;
- height: 100%;
- margin-left: 30rpx;
- &:first-child{
- margin-left: 0;
- }
- }
-
- .common_page{
- padding: 0;
- box-sizing: border-box;
- .tab{
- width: 100%;
- height: 102rpx;
- background: #FFFFFF;
- &-pre{
- width: 50%;
- height: 102rpx;
- position: relative;
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 32rpx;
- color: #676775;
- line-height: 48rpx;
- &.active{
- font-weight: bold;
- font-size: 36rpx;
- color: #252525;
- &::after{
- content: '';
- width: 42rpx;
- height: 6rpx;
- background: #B7F358;
- border-radius: 3rpx;
- position: absolute;
- left: 50%;
- margin-left: -21rpx;
- bottom: 6rpx;
- }
- }
- }
- }
-
- .member{
- width: 100%;
- height: 56rpx;
- padding: 0 30rpx;
- margin-top: 20rpx;
- box-sizing: border-box;
- .cl_item{
- padding: 0 26rpx;
- height: 56rpx;
- background: #FFFFFF;
- border-radius: 10rpx;
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 26rpx;
- color: #252525;
- line-height: 56rpx;
- text-align: center;
- &.active{
- background: #B7F358;
- }
- }
- }
- .list{
- padding: 0 24rpx;
- flex: 1;
- overflow-y: auto;
- margin-top: 4rpx;
-
- .ysl-box{
- margin-top: 20rpx;
- padding: 36rpx 24rpx;
- position: relative;
- background: linear-gradient(45deg, #FFFFFF 80%, #F2FFE8 100%);
- &-title{
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 32rpx;
- color: #151B29;
- line-height: 40rpx;
- }
- &-tip{
- font-family: PingFangSC, PingFang SC;
- font-weight: 400;
- font-size: 24rpx;
- color: #676775;
- line-height: 24rpx;
- margin-top: 30rpx;
- }
- &-btn{
- width: 118rpx;
- height: 64rpx;
- background: #B7F358;
- border-radius: 45rpx;
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 26rpx;
- color: #151B29;
- line-height: 64rpx;
- text-align: center;
- letter-spacing: 2rpx;
- position: absolute;
- right: 24rpx;
- bottom: 40rpx;
- }
- }
- }
-
- .btn{
- width: calc(100% - 210rpx);
- height: 90rpx;
- background: #B7F358;
- border-radius: 45rpx;
- font-family: PingFang-SC, PingFang-SC;
- font-weight: bold;
- font-size: 32rpx;
- color: #151B29;
- line-height: 90rpx;
- text-align: center;
- letter-spacing: 2rpx;
- position: fixed;
- left: 105rpx;
- bottom: 64rpx;
- }
- }
- </style>
|