演示
This commit is contained in:
@@ -1,134 +1,214 @@
|
||||
<template>
|
||||
<view class="select-user-mask" v-if="visible">
|
||||
<view class="select-user-container">
|
||||
<!-- 标题栏 -->
|
||||
<view class="header">
|
||||
<text>{{ title }}</text>
|
||||
<text class="close" @click="close">×</text>
|
||||
</view>
|
||||
<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="姓名、工号" />
|
||||
</view>
|
||||
|
||||
|
||||
<!-- 列表 -->
|
||||
<scroll-view class="user-list" scroll-y>
|
||||
<view v-for="item in filteredList" :key="item.id" class="user-item" @click="selectUser(item)">
|
||||
<view class="radio" :class="{ checked: isSelected(item) }"></view>
|
||||
<text>{{ item.name }}({{ item.department }})</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 搜索框 -->
|
||||
<view class="search-box">
|
||||
<input v-model="keyword" placeholder="姓名、工号" @input="onSearch" />
|
||||
</view>
|
||||
|
||||
<!-- 列表 -->
|
||||
<scroll-view class="user-list" scroll-y>
|
||||
<view v-for="item in filteredList" :key="item.id" class="user-item" @click="selectUser(item)">
|
||||
<view class="radio" :class="{ checked: isSelected(item) }"></view>
|
||||
<text>{{ item.name }}({{ item.department }})</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 底部按钮 -->
|
||||
<view class="footer">
|
||||
<button @click="confirm">{{ confirmText }}</button>
|
||||
</view>
|
||||
</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: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
filteredList() {
|
||||
if (!this.keyword) return this.list;
|
||||
return this.list.filter(item => item.name.includes(this.keyword) || item.id.includes(this.keyword));
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
close() {
|
||||
this.$emit('update:visible', false);
|
||||
},
|
||||
selectUser(item) {
|
||||
if (this.multiple) {
|
||||
if (this.isSelected(item)) {
|
||||
this.selected = this.selected.filter(i => i.id !== item.id);
|
||||
} else {
|
||||
this.selected.push(item);
|
||||
}
|
||||
} else {
|
||||
this.selected = [item];
|
||||
}
|
||||
},
|
||||
isSelected(item) {
|
||||
return this.selected.some(i => i.id === item.id);
|
||||
},
|
||||
confirm() {
|
||||
this.$emit('confirm', this.selected);
|
||||
this.close();
|
||||
},
|
||||
onSearch() {
|
||||
// 可以加节流优化
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.select-user-mask {
|
||||
position: fixed;
|
||||
top: 0; left: 0;
|
||||
width: 100%; height: 100%;
|
||||
background: rgba(0,0,0,0.3);
|
||||
display: flex; justify-content: center; align-items: center;
|
||||
}
|
||||
.select-user-container {
|
||||
width: 80%;
|
||||
max-height: 70%;
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
display: flex; flex-direction: column;
|
||||
}
|
||||
.header {
|
||||
padding: 15px;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
display: flex; justify-content: space-between;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.close {
|
||||
font-size: 22px; color: #999;
|
||||
}
|
||||
.search-box {
|
||||
padding: 10px;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.search-box input {
|
||||
width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 6px;
|
||||
}
|
||||
.user-list {
|
||||
flex: 1; overflow-y: auto;
|
||||
}
|
||||
.user-item {
|
||||
padding: 12px 15px; display: flex; align-items: center; border-bottom: 1px solid #eee;
|
||||
}
|
||||
.radio {
|
||||
width: 18px; height: 18px; border: 1px solid #ccc; border-radius: 50%; margin-right: 10px;
|
||||
}
|
||||
.radio.checked {
|
||||
background: #2d8cf0;
|
||||
border-color: #2d8cf0;
|
||||
}
|
||||
.footer {
|
||||
padding: 12px; border-top: 1px solid #eee;
|
||||
}
|
||||
.footer button {
|
||||
width: 100%; height: 40px; background: #2d8cf0; color: #fff; border-radius: 6px; border: none;
|
||||
}
|
||||
</style>
|
||||
<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: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
filteredList() {
|
||||
if (!this.keyword) return this.list;
|
||||
return this.list.filter(item => item.name.includes(this.keyword) || item.id.includes(this.keyword));
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
close() {
|
||||
this.$emit('update:visible', false);
|
||||
},
|
||||
selectUser(item) {
|
||||
if (this.multiple) {
|
||||
if (this.isSelected(item)) {
|
||||
this.selected = this.selected.filter(i => i.id !== item.id);
|
||||
} else {
|
||||
this.selected.push(item);
|
||||
}
|
||||
} else {
|
||||
this.selected = [item];
|
||||
}
|
||||
},
|
||||
isSelected(item) {
|
||||
return this.selected.some(i => i.id === item.id);
|
||||
},
|
||||
confirm() {
|
||||
this.$emit('confirm', this.selected);
|
||||
this.close();
|
||||
},
|
||||
onSearch() {}
|
||||
}
|
||||
}
|
||||
</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;
|
||||
}
|
||||
|
||||
.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>
|
Reference in New Issue
Block a user