practice.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 } from 'vue'
  54. import { onShow } from '@dcloudio/uni-app'
  55. const { proxy } = getCurrentInstance()
  56. const pb = ref(184)
  57. const tidx = ref(1)
  58. const midx = ref(0)
  59. const scrollLeft = ref(0)
  60. const queryParams = ref({
  61. page:1,
  62. limit:10,
  63. userId:'',
  64. memberId:''
  65. })
  66. const isOver = ref(false)
  67. const memberList = ref([])
  68. const list = ref([])
  69. const yslList = ref([])
  70. const changeTab = index => {
  71. tidx.value = index;
  72. pb.value = index===1?184:40;
  73. getDataByTab()
  74. }
  75. const changeMember = (item,index) => {
  76. midx.value = index;
  77. queryParams.value.memberId = item.id;
  78. getDataByTab()
  79. }
  80. const getDataByTab = () => {
  81. queryParams.value.page = 1;
  82. isOver.value = false;
  83. list.value = [];
  84. yslList.value = [];
  85. if(!queryParams.value.memberId) queryParams.value.memberId = memberList.value[0]?.id;
  86. if(tidx.value===1){
  87. getKslList()
  88. }else if(tidx.value===2){
  89. getYslList()
  90. }
  91. }
  92. const handleDetail = item => {
  93. uni.navigateTo({
  94. url:'/pagesMy/practiceRecord?id='+item.id
  95. })
  96. }
  97. const scrolltolower = () => {
  98. if(isOver.value) return
  99. getDataByTab()
  100. }
  101. const getKslList = () => {
  102. proxy.$api.get('/core/social/practice/record/claimPage',queryParams.value).then(({data:res})=>{
  103. if(res.code!==0) return proxy.$showToast(res.msg)
  104. list.value = [...list.value,...res.data.list]
  105. list.value.forEach(l=>{
  106. l.activityStartTime = l.activityStartTime?new Date(l.activityStartTime).Format('yyyy.MM.dd'):'';
  107. l.activityEndTime = l.activityEndTime?new Date(l.activityEndTime).Format('yyyy.MM.dd'):'';
  108. l.check = false;
  109. l.age = getAge(l.idCard);
  110. })
  111. queryParams.value.page++;
  112. if(res.data.list.length===0) isOver.value = true
  113. })
  114. }
  115. const getYslList = () => {
  116. proxy.$api.get('/core/social/practice/record/claimedPage',queryParams.value).then(({data:res})=>{
  117. if(res.code!==0) return proxy.$showToast(res.msg)
  118. yslList.value = [...yslList.value,...res.data.list]
  119. yslList.value.forEach(l=>{
  120. l.createDate = new Date(l.createDate).Format('yyyy.MM.dd hh:mm:ss');
  121. })
  122. queryParams.value.page++;
  123. if(res.data.list.length===0) isOver.value = true
  124. })
  125. }
  126. const getMemberList = () => {
  127. proxy.$api.get('/core/family/member/page',queryParams.value).then(({data:res})=>{
  128. if(res.code!==0) return proxy.$showToast(res.msg)
  129. memberList.value = res.data.list;
  130. getDataByTab()
  131. })
  132. }
  133. const isValid = (idCard) => {
  134. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  135. 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]$/;
  136. return typeof idCard === 'string' && regex.test(idCard);
  137. }
  138. const getAge = (idCard) => {
  139. if (!isValid(idCard)) return 0
  140. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  141. const birthDateStr = idCard.substring(6, 14);
  142. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  143. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  144. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  145. const today = new Date();
  146. const currentYear = today.getFullYear();
  147. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  148. const currentDay = today.getDate();
  149. // 计算周岁
  150. let age = currentYear - birthYear;
  151. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  152. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  153. age--;
  154. }
  155. return age < 0 ? 0 : age;
  156. }
  157. const handleCheck = (item) => {
  158. item.check = !item.check;
  159. }
  160. const handleApply = () => {
  161. let activityIds = list.value.filter(l=>l.check).map(l=>l.activityId);
  162. if(activityIds.length===0) return proxy.$showToast('请至少选择一条记录')
  163. proxy.$api.post('/core/social/practice/record',{
  164. activityIds,
  165. memberId:queryParams.value.memberId
  166. }).then(({data:res})=>{
  167. if(res.code!==0) return proxy.$showToast(res.msg)
  168. tidx.value = 2;
  169. getDataByTab()
  170. proxy.$showToast('申领成功')
  171. })
  172. }
  173. onShow(()=>{
  174. try{
  175. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  176. getMemberList();
  177. }catch(e){
  178. //TODO handle the exception
  179. }
  180. })
  181. </script>
  182. <style scoped lang="scss">
  183. .scroll-view_H {
  184. white-space: nowrap;
  185. width: 100%;
  186. }
  187. .scroll-view-item_H {
  188. display: inline-block;
  189. height: 100%;
  190. margin-left: 30rpx;
  191. &:first-child{
  192. margin-left: 0;
  193. }
  194. }
  195. .common_page{
  196. padding: 0;
  197. box-sizing: border-box;
  198. .tab{
  199. width: 100%;
  200. height: 102rpx;
  201. background: #FFFFFF;
  202. &-pre{
  203. width: 50%;
  204. height: 102rpx;
  205. position: relative;
  206. font-family: PingFangSC, PingFang SC;
  207. font-weight: 400;
  208. font-size: 32rpx;
  209. color: #676775;
  210. line-height: 48rpx;
  211. &.active{
  212. font-weight: bold;
  213. font-size: 36rpx;
  214. color: #252525;
  215. &::after{
  216. content: '';
  217. width: 42rpx;
  218. height: 6rpx;
  219. background: #B7F358;
  220. border-radius: 3rpx;
  221. position: absolute;
  222. left: 50%;
  223. margin-left: -21rpx;
  224. bottom: 6rpx;
  225. }
  226. }
  227. }
  228. }
  229. .member{
  230. width: 100%;
  231. height: 56rpx;
  232. padding: 0 30rpx;
  233. margin-top: 20rpx;
  234. box-sizing: border-box;
  235. .cl_item{
  236. padding: 0 26rpx;
  237. height: 56rpx;
  238. background: #FFFFFF;
  239. border-radius: 10rpx;
  240. font-family: PingFangSC, PingFang SC;
  241. font-weight: 400;
  242. font-size: 26rpx;
  243. color: #252525;
  244. line-height: 56rpx;
  245. text-align: center;
  246. &.active{
  247. background: #B7F358;
  248. }
  249. }
  250. }
  251. .list{
  252. padding: 0 24rpx;
  253. flex: 1;
  254. overflow-y: auto;
  255. margin-top: 4rpx;
  256. .ysl-box{
  257. margin-top: 20rpx;
  258. padding: 36rpx 24rpx;
  259. position: relative;
  260. background: linear-gradient(45deg, #FFFFFF 80%, #F2FFE8 100%);
  261. &-title{
  262. font-family: PingFang-SC, PingFang-SC;
  263. font-weight: bold;
  264. font-size: 32rpx;
  265. color: #151B29;
  266. line-height: 40rpx;
  267. }
  268. &-tip{
  269. font-family: PingFangSC, PingFang SC;
  270. font-weight: 400;
  271. font-size: 24rpx;
  272. color: #676775;
  273. line-height: 24rpx;
  274. margin-top: 30rpx;
  275. }
  276. &-btn{
  277. width: 118rpx;
  278. height: 64rpx;
  279. background: #B7F358;
  280. border-radius: 45rpx;
  281. font-family: PingFang-SC, PingFang-SC;
  282. font-weight: bold;
  283. font-size: 26rpx;
  284. color: #151B29;
  285. line-height: 64rpx;
  286. text-align: center;
  287. letter-spacing: 2rpx;
  288. position: absolute;
  289. right: 24rpx;
  290. bottom: 40rpx;
  291. }
  292. }
  293. }
  294. .btn{
  295. width: calc(100% - 210rpx);
  296. height: 90rpx;
  297. background: #B7F358;
  298. border-radius: 45rpx;
  299. font-family: PingFang-SC, PingFang-SC;
  300. font-weight: bold;
  301. font-size: 32rpx;
  302. color: #151B29;
  303. line-height: 90rpx;
  304. text-align: center;
  305. letter-spacing: 2rpx;
  306. position: fixed;
  307. left: 105rpx;
  308. bottom: 64rpx;
  309. }
  310. }
  311. </style>