familyMember.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="page">
  3. <el-table :data="dataList" border cell-class-name="vertical-top-cell" v-loading="loading" empty-text="暂无家庭成员">
  4. <el-table-column label="序号" width="70">
  5. <template slot-scope="scope">{{ scope.$index + 1 }}</template>
  6. </el-table-column>
  7. <!-- <el-table-column prop="xxx" label="善行少年编号"></el-table-column> -->
  8. <el-table-column prop="name" label="姓名"></el-table-column>
  9. <el-table-column prop="idCard" label="身份证"></el-table-column>
  10. <el-table-column prop="volunteerNo" label="义工号"></el-table-column>
  11. <el-table-column prop="age" label="年龄">
  12. <template slot-scope="scope">{{ scope.row.age||0 }}岁</template>
  13. </el-table-column>
  14. <el-table-column prop="gender" label="性别">
  15. <template slot-scope="scope">{{ genderDict[scope.row.gender] }}</template>
  16. </el-table-column>
  17. <el-table-column prop="currentSchool" label="就读学校"></el-table-column>
  18. <el-table-column label="所属渠道">
  19. <template slot-scope="scope">{{ scope.row.channelNames || '-' }}</template>
  20. </el-table-column>
  21. <el-table-column prop="xxx" label="义工时长">
  22. <template slot-scope="scope">{{ scope.row.volunteerHours||0 }}h</template>
  23. </el-table-column>
  24. <el-table-column prop="welfareCount" label="参与活动次数"></el-table-column>
  25. </el-table>
  26. <el-pagination
  27. :current-page="queryParams.page"
  28. :page-sizes="[10, 20, 50, 100]"
  29. :page-size="queryParams.limit"
  30. :total="total"
  31. layout="total, sizes, prev, pager, next, jumper"
  32. @size-change="pageSizeChangeHandle"
  33. @current-change="pageCurrentChangeHandle">
  34. </el-pagination>
  35. </div>
  36. </template>
  37. <script>
  38. export default {
  39. props: ['userId'],
  40. data () {
  41. return {
  42. queryParams: {
  43. userId: '',
  44. page: 1,
  45. limit: 10
  46. },
  47. dataList: [],
  48. total: 0,
  49. loading: false,
  50. genderDict: {
  51. 0: '男',
  52. 1: '女',
  53. 2: '保密'
  54. }
  55. }
  56. },
  57. mounted () {
  58. this.queryParams.userId = this.userId
  59. this.getList()
  60. },
  61. methods: {
  62. getList () {
  63. this.loading = true
  64. this.$http.get('/core/family/member/page', { params: this.queryParams }).then(({ data: res }) => {
  65. if (res.code === 0) {
  66. this.dataList = res.data.list
  67. this.dataList.forEach(d => {
  68. d.age = this.getAge(d.idCard)
  69. d.idCard = d.idCard && d.idCard.replace(/^(\d{6})\d{8}(\w{4})$/, '$1********$2')
  70. })
  71. this.total = res.data.total
  72. }
  73. this.loading = false
  74. })
  75. },
  76. isValid (idCard) {
  77. 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]$/
  78. return typeof idCard === 'string' && regex.test(idCard)
  79. },
  80. getAge (idCard) {
  81. if (!this.isValid(idCard)) return 0
  82. const birthDateStr = idCard.substring(6, 14)
  83. const birthYear = parseInt(birthDateStr.substring(0, 4), 10)
  84. const birthMonth = parseInt(birthDateStr.substring(4, 6), 10)
  85. const birthDay = parseInt(birthDateStr.substring(6, 8), 10)
  86. const today = new Date()
  87. const currentYear = today.getFullYear()
  88. const currentMonth = today.getMonth() + 1
  89. const currentDay = today.getDate()
  90. // 计算周岁
  91. let age = currentYear - birthYear
  92. // 如果当前月份小于出生月份,或者月份相同但日期小于出生日期,说明今年的生日还没过
  93. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  94. age--
  95. }
  96. return age < 0 ? 0 : age
  97. },
  98. pageSizeChangeHandle (val) {
  99. this.queryParams.limit = val
  100. this.getList()
  101. },
  102. pageCurrentChangeHandle (val) {
  103. this.queryParams.page = val
  104. this.getList()
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped lang="scss">
  110. </style>