practice.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. <view class="tab adf">
  5. <view class="tab-pre adfacjc" :class="{'active':tidx===1}" @click="changeTab(1)">可申领</view>
  6. <view class="tab-pre adfacjc" :class="{'active':tidx===2}" @click="changeTab(2)">已申领</view>
  7. </view>
  8. <view 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" @click="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. </view>
  17. <template v-if="tidx===1">
  18. <view 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. </view>
  25. <view class="dataEmpty" v-else>
  26. <page-empty text="暂无已申领记录"></page-empty>
  27. </view>
  28. <view class="btn" @click="handleApply">申领社会实践记录</view>
  29. </template>
  30. <template v-else-if="tidx===2">
  31. <view 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. <view class="ysl-box">
  35. <view class="ysl-box-title">证书编号:{{item?.certificateNumber||''}}</view>
  36. <view class="ysl-box-tip">申领时间:{{item?.createDate||''}}</view>
  37. <view class="ysl-box-tip">申 领 人:{{item?.memberName||''}}</view>
  38. <view class="ysl-box-btn" @click="handleDetail(item)">查看</view>
  39. </view>
  40. </up-list-item>
  41. </up-list>
  42. </view>
  43. <view class="dataEmpty" v-else>
  44. <page-empty text="暂无已申领记录"></page-empty>
  45. </view>
  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 = [];
  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?id='+item.id
  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. yslList.value.forEach(l=>{
  119. l.createDate = new Date(l.createDate).Format('yyyy.MM.dd hh:mm:ss');
  120. })
  121. queryParams.value.page++;
  122. if(res.data.list.length===0) isOver.value = true
  123. })
  124. }
  125. const getMemberList = () => {
  126. proxy.$api.get('/core/family/member/page',queryParams.value).then(({data:res})=>{
  127. if(res.code!==0) return proxy.$showToast(res.msg)
  128. memberList.value = res.data.list;
  129. getDataByTab()
  130. })
  131. }
  132. const isValid = (idCard) => {
  133. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  134. 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]$/;
  135. return typeof idCard === 'string' && regex.test(idCard);
  136. }
  137. const getAge = (idCard) => {
  138. if (!isValid(idCard)) return 0
  139. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  140. const birthDateStr = idCard.substring(6, 14);
  141. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  142. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  143. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  144. const today = new Date();
  145. const currentYear = today.getFullYear();
  146. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  147. const currentDay = today.getDate();
  148. // 计算周岁
  149. let age = currentYear - birthYear;
  150. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  151. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  152. age--;
  153. }
  154. return age < 0 ? 0 : age;
  155. }
  156. const handleCheck = (item) => {
  157. item.check = !item.check;
  158. }
  159. const handleApply = () => {
  160. let activityIds = list.value.filter(l=>l.check).map(l=>l.activityId);
  161. if(activityIds.length===0) return proxy.$showToast('请至少选择一条记录')
  162. proxy.$api.post('/core/social/practice/record',{
  163. activityIds,
  164. memberId:queryParams.value.memberId
  165. }).then(({data:res})=>{
  166. if(res.code!==0) return proxy.$showToast(res.msg)
  167. tidx.value = 2;
  168. getDataByTab()
  169. proxy.$showToast('申领成功')
  170. })
  171. }
  172. onMounted(()=>{
  173. try{
  174. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  175. getMemberList();
  176. }catch(e){
  177. //TODO handle the exception
  178. }
  179. })
  180. </script>
  181. <style scoped lang="scss">
  182. .scroll-view_H {
  183. white-space: nowrap;
  184. width: 100%;
  185. }
  186. .scroll-view-item_H {
  187. display: inline-block;
  188. height: 100%;
  189. margin-left: 30rpx;
  190. &:first-child{
  191. margin-left: 0;
  192. }
  193. }
  194. .common_page{
  195. padding: 0;
  196. box-sizing: border-box;
  197. .tab{
  198. width: 100%;
  199. height: 102rpx;
  200. background: #FFFFFF;
  201. &-pre{
  202. width: 50%;
  203. height: 102rpx;
  204. position: relative;
  205. font-family: PingFangSC, PingFang SC;
  206. font-weight: 400;
  207. font-size: 32rpx;
  208. color: #676775;
  209. line-height: 48rpx;
  210. &.active{
  211. font-weight: bold;
  212. font-size: 36rpx;
  213. color: #252525;
  214. &::after{
  215. content: '';
  216. width: 42rpx;
  217. height: 6rpx;
  218. background: #B7F358;
  219. border-radius: 3rpx;
  220. position: absolute;
  221. left: 50%;
  222. margin-left: -21rpx;
  223. bottom: 6rpx;
  224. }
  225. }
  226. }
  227. }
  228. .member{
  229. width: 100%;
  230. height: 56rpx;
  231. padding: 0 30rpx;
  232. margin-top: 20rpx;
  233. box-sizing: border-box;
  234. .cl_item{
  235. padding: 0 26rpx;
  236. height: 56rpx;
  237. background: #FFFFFF;
  238. border-radius: 10rpx;
  239. font-family: PingFangSC, PingFang SC;
  240. font-weight: 400;
  241. font-size: 26rpx;
  242. color: #252525;
  243. line-height: 56rpx;
  244. text-align: center;
  245. &.active{
  246. background: #B7F358;
  247. }
  248. }
  249. }
  250. .list{
  251. padding: 0 24rpx;
  252. flex: 1;
  253. overflow-y: auto;
  254. margin-top: 4rpx;
  255. .ysl-box{
  256. margin-top: 20rpx;
  257. padding: 36rpx 24rpx;
  258. position: relative;
  259. background: linear-gradient(45deg, #FFFFFF 80%, #F2FFE8 100%);
  260. &-title{
  261. font-family: PingFang-SC, PingFang-SC;
  262. font-weight: bold;
  263. font-size: 32rpx;
  264. color: #151B29;
  265. line-height: 40rpx;
  266. }
  267. &-tip{
  268. font-family: PingFangSC, PingFang SC;
  269. font-weight: 400;
  270. font-size: 24rpx;
  271. color: #676775;
  272. line-height: 24rpx;
  273. margin-top: 30rpx;
  274. }
  275. &-btn{
  276. width: 118rpx;
  277. height: 64rpx;
  278. background: #B7F358;
  279. border-radius: 45rpx;
  280. font-family: PingFang-SC, PingFang-SC;
  281. font-weight: bold;
  282. font-size: 26rpx;
  283. color: #151B29;
  284. line-height: 64rpx;
  285. text-align: center;
  286. letter-spacing: 2rpx;
  287. position: absolute;
  288. right: 24rpx;
  289. bottom: 40rpx;
  290. }
  291. }
  292. }
  293. .btn{
  294. width: calc(100% - 210rpx);
  295. height: 90rpx;
  296. background: #B7F358;
  297. border-radius: 45rpx;
  298. font-family: PingFang-SC, PingFang-SC;
  299. font-weight: bold;
  300. font-size: 32rpx;
  301. color: #151B29;
  302. line-height: 90rpx;
  303. text-align: center;
  304. letter-spacing: 2rpx;
  305. position: fixed;
  306. left: 105rpx;
  307. bottom: 64rpx;
  308. }
  309. }
  310. </style>