user-list.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="hc-all-user-list">
  3. <view class="hc-user-bar" v-for="item in dataList" :key="item.id" @click="checkChange(item.id)">
  4. <view class="check-box">
  5. <text class="i-material-symbols-check-box-rounded icon" v-if="modelData.indexOf(item.id) > -1"/>
  6. <text class="i-material-symbols-check-box-outline-blank icon check" v-else/>
  7. </view>
  8. <view class="content-bar">
  9. <view class="avatar">{{item.avatarName}}</view>
  10. <view class="content">
  11. <view class="name">{{item.createUserName}}</view>
  12. <view class="text">{{item.recordTime}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script setup>
  19. import { ref, watch } from "vue";
  20. //参数
  21. const props = defineProps({
  22. modelValue: {
  23. type: Array,
  24. default: () => ([]),
  25. },
  26. data: {
  27. type: Array,
  28. default: () => ([]),
  29. },
  30. })
  31. //基础变量
  32. const modelData = ref(props.modelValue)
  33. const dataList = ref(props.data)
  34. //监听选中项
  35. watch(() => [
  36. props.modelValue
  37. ], ([val]) => {
  38. modelData.value = val
  39. }, {deep: true})
  40. //监听列表数据
  41. watch(() => [
  42. props.data
  43. ], ([val]) => {
  44. dataList.value = val
  45. }, {deep: true})
  46. //事件
  47. const emit = defineEmits(['update:modelValue', 'change'])
  48. //选择数据改变
  49. const checkChange = (id) => {
  50. const data = modelData.value, index = data.indexOf(id);
  51. if (index > -1) {
  52. modelData.value.splice(index, 1)
  53. } else {
  54. modelData.value.push(id)
  55. }
  56. emit('update:modelValue', modelData.value)
  57. emit('change', modelData.value)
  58. }
  59. //获取选中的数据
  60. const getCheckData = () => {
  61. return modelData.value
  62. }
  63. //导出
  64. defineExpose({
  65. getCheckData
  66. })
  67. </script>
  68. <style lang="scss" scoped>
  69. .hc-all-user-list {
  70. position: relative;
  71. margin-top: 8rpx;
  72. margin-bottom: 10rpx;
  73. .hc-user-bar {
  74. position: relative;
  75. background: white;
  76. display: flex;
  77. align-items: center;
  78. padding: 9rpx 0;
  79. .check-box {
  80. width: 40rpx;
  81. height: 40rpx;
  82. display: flex;
  83. align-items: center;
  84. justify-content: center;
  85. margin-left: 25rpx;
  86. .icon {
  87. width: 38rpx;
  88. height: 38rpx;
  89. color: #007aff;
  90. }
  91. .icon.check {
  92. color: #c8c9cc;
  93. }
  94. }
  95. .content-bar {
  96. position: relative;
  97. display: flex;
  98. align-items: center;
  99. margin-left: 18rpx;
  100. flex: 1;
  101. .avatar {
  102. position: relative;
  103. margin-right: 24rpx;
  104. height: 66rpx;
  105. width: 66rpx;
  106. background: #2b8cf5;
  107. border-radius: 8rpx;
  108. color: white;
  109. display: flex;
  110. justify-content: center;
  111. align-items: center;
  112. font-size: 26rpx;
  113. }
  114. .content {
  115. position: relative;
  116. padding-right: 18rpx;
  117. flex: 1;
  118. .text {
  119. font-size: 25rpx;
  120. color: #7A7B7C;
  121. margin-top: 3rpx;
  122. }
  123. }
  124. }
  125. }
  126. .hc-user-bar + .hc-user-bar {
  127. .content-bar::before{
  128. content: "";
  129. position: absolute;
  130. top: -10rpx;
  131. height: 2rpx;
  132. width: 100%;
  133. background: #eee;
  134. }
  135. }
  136. }
  137. </style>