Files
SmartParks_uniapp/components/SelectUser.vue
2025-09-06 16:37:22 +08:00

241 lines
4.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view>
<!-- 遮罩层 -->
<view class="mask" v-if="visible" @click="close"></view>
<!-- 底部弹窗 -->
<view class="popup" v-if="visible">
<!-- 标题栏 -->
<view class="header">
<text>{{ title }}</text>
<image class="close" @click="close" src="/static/ic_close_01.png" />
</view>
<view class="search-bar">
<image class="search-icon" src="/static/ic_search_gray.png" />
<input class="search-input" placeholder="姓名" v-model="keyword" @confirm="handleSearch" confirm-type="search" />
<view class="search-btn" @click="handleSearch">搜索</view>
</view>
<!-- 列表 -->
<scroll-view class="user-list" scroll-y>
<view v-for="item in filteredList" :key="item.value" class="user-item" @click="selectUser(item)">
<view class="radio" :class="{ checked: isSelected(item) }"></view>
<text>{{ item.name }}{{ item.department }}</text>
</view>
</scroll-view>
<button class="footer" @click="confirm">{{ confirmText }}</button>
</view>
</view>
</template>
<script>
export default {
name: 'SelectUser',
props: {
visible: {
type: Boolean,
default: false
},
list: {
type: Array,
default: () => []
},
title: {
type: String,
default: '选择'
},
multiple: {
type: Boolean,
default: false
},
confirmText: {
type: String,
default: '指派'
}
},
data() {
return {
keyword: '',
selected: [],
allList: [], // 存放所有数据
filteredList: []
}
},
watch: {
list: {
handler(newVal) {
this.allList = [...newVal];
this.filteredList = [...newVal];
},
immediate: true
}
},
methods: {
close() {
this.$emit('update:visible', false);
},
selectUser(item) {
if (this.multiple) {
if (this.isSelected(item)) {
this.selected = this.selected.filter(i => i.value !== item.value);
} else {
this.selected.push(item);
}
} else {
this.selected = [item];
}
},
isSelected(item) {
return this.selected.some(i => i.value === item.value);
},
confirm() {
this.$emit('confirm', this.selected);
this.close();
},
// 搜索方法
handleSearch() {
if (!this.keyword) {
this.filteredList = [...this.allList];
return;
}
this.filteredList = this.allList.filter(item =>
item.name.includes(this.keyword) ||
(item.department && item.department.includes(this.keyword))
);
}
}
}
</script>
<style scoped>
.mask {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.3);
z-index: 998;
}
.popup {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
max-height: 80%;
background: #fff;
border-radius: 24rpx 24rpx 0 0;
overflow: hidden;
display: flex;
flex-direction: column;
z-index: 999;
animation: slideUp 0.3s ease;
}
@keyframes slideUp {
from {
transform: translateY(100%);
}
to {
transform: translateY(0);
}
}
.header {
padding-top: 45rpx;
font-size: 36rpx;
display: flex;
align-items: center;
padding: 45rpx 30rpx 20rpx 30rpx;
position: relative;
justify-content: center;
}
.close {
width: 22rpx;
height: 21rpx;
position: absolute;
right: 30rpx;
}
.search-bar {
display: flex;
align-items: center;
background: #F7F7F7;
border-radius: 29rpx;
height: 58rpx;
padding-left: 20rpx;
margin-left: 34rpx;
margin-right: 34rpx;
margin-top: 26rpx;
}
.search-icon {
width: 27rpx;
height: 27rpx;
margin-right: 8rpx;
}
.search-input {
border: none;
font-size: 26rpx;
flex: 1;
color: #000;
background: transparent;
}
.search-btn {
font-size: 26rpx;
color: #0090FF;
padding: 0 20rpx;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.user-list {
flex: 1;
overflow-y: auto;
margin-top: 20rpx;
padding-left: 52rpx;
padding-right: 52rpx;
}
.user-item {
height: 88rpx;
display: flex;
align-items: center;
border-bottom: 1rpx solid #F7F7F7;
font-size: 28rpx;
}
.radio {
width: 36rpx;
height: 36rpx;
border: 1rpx solid #ccc;
border-radius: 50%;
margin-right: 20rpx;
}
.radio.checked {
background: #2d8cf0;
border-color: #2d8cf0;
}
.footer{
width: 80vw;
height: 88rpx;
background: #0090FF;
color: #fff;
border-radius: 44rpx;
font-size: 36rpx;
margin-top: 50rpx;
margin-bottom: 50rpx;
}
</style>