familyMember.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title="家庭成员" bgColor="#FFFFFF"></cus-header>
  4. <view class="add">
  5. <view class="btn adfacjc" @click="handleAdd">
  6. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/10/09/af9133fd-e15e-454d-9152-e4629fd0ce28.png"></image>
  7. <text>添加</text>
  8. </view>
  9. </view>
  10. <template v-if="list.length">
  11. <view class="list">
  12. <up-list @scrolltolower="scrolltolower" style="height: 100%;">
  13. <up-list-item v-for="(item, index) in list" :key="index">
  14. <view class="box adfacjb">
  15. <view class="box-left adfac" @click="handleEdit(item,index)">
  16. <view class="box-left-edit">
  17. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/10/09/7799f9f2-1dca-4af3-980b-7f6def10e22f.png"></image>
  18. </view>
  19. <view class="box-left-info">
  20. <view class="box-left-info-top adfac">
  21. <view class="name">{{item.name||''}}</view>
  22. <image class="sex" v-if="item.gender==1" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/12/b6d1fcb3-55ba-4104-b8cd-756b963a4da8.png"></image>
  23. <image class="sex" v-else-if="item.gender==0" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/12/a1899fd0-c468-48d9-b554-2f17b75a4157.png"></image>
  24. <view class="age" :class="{'women':item.gender==1,'man':item.gender==0}">{{item.age}}岁</view>
  25. </view>
  26. <view class="box-left-info-bottom">
  27. 身份证 {{item.idCardCopy}}
  28. </view>
  29. </view>
  30. </view>
  31. <view class="box-right" @click="handleDelete(item,index)">
  32. <image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/09/23/ebdf1327-3eeb-4797-8840-cb1ec4840d9a.png"></image>
  33. </view>
  34. </view>
  35. </up-list-item>
  36. </up-list>
  37. </view>
  38. </template>
  39. <view class="dataEmpty" v-else>
  40. <page-empty text="暂无家庭成员,请添加"></page-empty>
  41. </view>
  42. </view>
  43. </template>
  44. <script setup name="">
  45. import CusHeader from '@/components/CusHeader/index.vue'
  46. import PageEmpty from '@/components/pageEmpty/index.vue'
  47. import { ref, onMounted, getCurrentInstance } from 'vue'
  48. const { proxy } = getCurrentInstance()
  49. const queryParams = ref({
  50. page:1,
  51. limit:10,
  52. userId:''
  53. })
  54. const isOver = ref(false)
  55. const list = ref([])
  56. const scrolltolower = () => {
  57. if(isOver.value) return
  58. getMemberList()
  59. }
  60. const getMemberList = () => {
  61. proxy.$api.get('/core/family/member/page',queryParams.value).then(({data:res})=>{
  62. if(res.code!==0) return proxy.$showToast(res.msg)
  63. list.value = [...list.value,...res.data.list]
  64. list.value.forEach(l=>{
  65. l.age = getAge(l.idCard)
  66. l.idCardCopy = l.idCard.replace(/^(\d{6})(\d{8})(\d{3}[\dX])$/i,'$1********$3')
  67. })
  68. queryParams.value.page++;
  69. if(res.data.list.length===0) isOver.value = true
  70. })
  71. }
  72. const isValid = (idCard) => {
  73. // 正则表达式校验18位身份证号码(最后一位可以是数字或X/x)
  74. 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]$/;
  75. return typeof idCard === 'string' && regex.test(idCard);
  76. }
  77. const getAge = (idCard) => {
  78. if (!isValid(idCard)) return 0
  79. // 从身份证的第7位开始,截取8位作为出生日期字符串 (YYYYMMDD)
  80. const birthDateStr = idCard.substring(6, 14);
  81. const birthYear = parseInt(birthDateStr.substring(0, 4), 10);
  82. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10);
  83. const birthDay = parseInt(birthDateStr.substring(6, 8), 10);
  84. const today = new Date();
  85. const currentYear = today.getFullYear();
  86. const currentMonth = today.getMonth() + 1; // getMonth() 返回 0-11
  87. const currentDay = today.getDate();
  88. // 计算周岁
  89. let age = currentYear - birthYear;
  90. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  91. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  92. age--;
  93. }
  94. return age < 0 ? 0 : age;
  95. }
  96. const handleAdd = () => {
  97. uni.navigateTo({
  98. url:'/pagesMy/familyMemberVindicate'
  99. })
  100. }
  101. const handleEdit = (item,index) => {
  102. uni.navigateTo({
  103. url:'/pagesMy/familyMemberVindicate?id='+item.id
  104. })
  105. }
  106. const handleDelete = (item,index) => {
  107. uni.showModal({
  108. title:'温馨提示',
  109. content:`是否确认删除家庭成员【${item.name}】?`,
  110. success: (res) => {
  111. if(res.confirm){
  112. proxy.$api.del('/core/family/member',[item.id]).then(({data:res})=>{
  113. if(res.code!==0) return proxy.$showToast(res.msg)
  114. proxy.$showToast('删除成功')
  115. queryParams.value.page = 1;
  116. isOver.value = false;
  117. list.value = [];
  118. getMemberList()
  119. })
  120. }
  121. }
  122. })
  123. }
  124. onMounted(()=>{
  125. try{
  126. queryParams.value.userId = JSON.parse(uni.getStorageSync('userInfo')).id;
  127. getMemberList()
  128. }catch(e){
  129. //TODO handle the exception
  130. }
  131. })
  132. </script>
  133. <style scoped lang="scss">
  134. .common_page{
  135. padding-bottom: 60rpx;
  136. .add{
  137. margin-top: 20rpx;
  138. background: #FFFFFF;
  139. border-radius: 20rpx 20rpx 0 0;
  140. padding: 30rpx 24rpx 20rpx;
  141. .btn{
  142. width: 100%;
  143. background: rgba(112,207,82,0.08);
  144. border-radius: 24rpx;
  145. border: 1rpx dotted #70CF52;
  146. padding: 21rpx 0;
  147. image{
  148. width: 36rpx;
  149. height: 36rpx;
  150. }
  151. text{
  152. font-family: PingFang-SC, PingFang-SC;
  153. font-weight: bold;
  154. font-size: 28rpx;
  155. color: #70CF52;
  156. line-height: 40rpx;
  157. margin-left: 18rpx;
  158. letter-spacing: 2rpx;
  159. }
  160. }
  161. }
  162. .list{
  163. flex: 1;
  164. overflow: auto;
  165. background: #FFFFFF;
  166. border-radius: 0 0 20rpx 20rpx;
  167. padding: 0 24rpx;
  168. .box{
  169. padding: 37rpx 0;
  170. box-shadow: inset 0rpx -1rpx 0rpx 0rpx #F2F2F2;
  171. &-left{
  172. width: calc(100% - 76rpx);
  173. &-edit{
  174. width: 36rpx;
  175. height: 36rpx;
  176. image{
  177. width: 100%;
  178. height: 100%;
  179. }
  180. }
  181. &-info{
  182. width: calc(100% - 36rpx);
  183. padding-left: 20rpx;
  184. box-sizing: border-box;
  185. &-top{
  186. .name{
  187. font-family: PingFang-SC, PingFang-SC;
  188. font-weight: bold;
  189. font-size: 32rpx;
  190. color: #151B29;
  191. line-height: 32rpx;
  192. }
  193. .sex{
  194. width: 44rpx;
  195. height: 32rpx;
  196. margin-left: 16rpx;
  197. }
  198. .age{
  199. border-radius: 13rpx;
  200. font-family: PingFangSC, PingFang SC;
  201. font-weight: 400;
  202. font-size: 20rpx;
  203. line-height: 24rpx;
  204. padding: 4rpx 10rpx;
  205. margin-left: 13rpx;
  206. &.women{
  207. background: rgba(244,101,122,0.14);
  208. color: #F4657A;
  209. }
  210. &.man{
  211. background: rgba(5,169,254,0.12);
  212. color: #05A9FE;
  213. }
  214. }
  215. }
  216. &-bottom{
  217. font-family: PingFangSC, PingFang SC;
  218. font-weight: 400;
  219. font-size: 24rpx;
  220. color: #989998;
  221. line-height: 24rpx;
  222. margin-top: 23rpx;
  223. }
  224. }
  225. }
  226. &-right{
  227. width: 36rpx;
  228. height: 36rpx;
  229. image{
  230. width: 100%;
  231. height: 100%;
  232. }
  233. }
  234. }
  235. }
  236. .empty{
  237. margin-top: 300rpx;
  238. text-align: center;
  239. font-size: 32rpx;
  240. color: #666666;
  241. }
  242. }
  243. </style>