123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <template>
- <view class="hc-all-user-list">
- <view class="hc-user-bar" v-for="item in dataList" :key="item.id" @click="checkChange(item.id)">
- <view class="check-box">
- <text class="i-material-symbols-check-box-rounded icon" v-if="modelData.indexOf(item.id) > -1"/>
- <text class="i-material-symbols-check-box-outline-blank icon check" v-else/>
- </view>
- <view class="content-bar">
- <view class="avatar">{{item.avatarName}}</view>
- <view class="content">
- <view class="name">{{item.createUserName}}</view>
- <view class="text">{{item.recordTime}}</view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import { ref, watch } from "vue";
- //参数
- const props = defineProps({
- modelValue: {
- type: Array,
- default: () => ([]),
- },
- data: {
- type: Array,
- default: () => ([]),
- },
- })
- //基础变量
- const modelData = ref(props.modelValue)
- const dataList = ref(props.data)
- //监听选中项
- watch(() => [
- props.modelValue
- ], ([val]) => {
- modelData.value = val
- }, {deep: true})
- //监听列表数据
- watch(() => [
- props.data
- ], ([val]) => {
- dataList.value = val
- }, {deep: true})
- //事件
- const emit = defineEmits(['update:modelValue', 'change'])
- //选择数据改变
- const checkChange = (id) => {
- const data = modelData.value, index = data.indexOf(id);
- if (index > -1) {
- modelData.value.splice(index, 1)
- } else {
- modelData.value.push(id)
- }
- emit('update:modelValue', modelData.value)
- emit('change', modelData.value)
- }
- //获取选中的数据
- const getCheckData = () => {
- return modelData.value
- }
- //导出
- defineExpose({
- getCheckData
- })
- </script>
- <style lang="scss" scoped>
- .hc-all-user-list {
- position: relative;
- margin-top: 8rpx;
- margin-bottom: 10rpx;
- .hc-user-bar {
- position: relative;
- background: white;
- display: flex;
- align-items: center;
- padding: 9rpx 0;
- .check-box {
- width: 40rpx;
- height: 40rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- margin-left: 25rpx;
- .icon {
- width: 38rpx;
- height: 38rpx;
- color: #007aff;
- }
- .icon.check {
- color: #c8c9cc;
- }
- }
- .content-bar {
- position: relative;
- display: flex;
- align-items: center;
- margin-left: 18rpx;
- flex: 1;
- .avatar {
- position: relative;
- margin-right: 24rpx;
- height: 66rpx;
- width: 66rpx;
- background: #2b8cf5;
- border-radius: 8rpx;
- color: white;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 26rpx;
- }
- .content {
- position: relative;
- padding-right: 18rpx;
- flex: 1;
- .text {
- font-size: 25rpx;
- color: #7A7B7C;
- margin-top: 3rpx;
- }
- }
- }
- }
- .hc-user-bar + .hc-user-bar {
- .content-bar::before{
- content: "";
- position: absolute;
- top: -10rpx;
- height: 2rpx;
- width: 100%;
- background: #eee;
- }
- }
- }
- </style>
|