practice.vue 9.4 KB

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