<template>
|
<view class="contact-select">
|
<!-- 顶部标题栏 -->
|
<view class="header">
|
<up-icon name="arrow-left" size="20" color="#333" @click="goBack" />
|
<text class="title">选择联系人</text>
|
<text class="confirm-btn" @click="confirmSelect">确定</text>
|
</view>
|
|
<!-- 搜索框 -->
|
<!-- <view class="search-section">-->
|
<!-- <van-search-->
|
<!-- v-model="searchValue"-->
|
<!-- placeholder="搜索联系人"-->
|
<!-- @search="onSearch"-->
|
<!-- @input="onSearch"-->
|
<!-- />-->
|
<!-- </view>-->
|
|
<!-- 已选择的联系人 -->
|
<view class="selected-section" v-if="selectedContact">
|
<view class="selected-header">
|
<text class="selected-title">已选择</text>
|
<text class="clear-btn" @click="clearSelected">清空</text>
|
</view>
|
<view class="selected-item">
|
<view class="contact-avatar">
|
<text class="avatar-text">{{ selectedContact.nickName.charAt(0) }}</text>
|
</view>
|
<view class="contact-details">
|
<text class="contact-name">{{ selectedContact.nickName }}</text>
|
</view>
|
<van-icon name="cross" size="16" color="#999" @click="clearSelected" />
|
</view>
|
</view>
|
|
<!-- 联系人列表 -->
|
<view class="contact-list">
|
<view class="list-header">
|
<text class="list-title">全部联系人</text>
|
</view>
|
|
<van-list
|
v-model:loading="loading"
|
:finished="finished"
|
finished-text="没有更多了"
|
@load="onLoad"
|
>
|
<view
|
v-for="contact in userList"
|
:key="contact.userId"
|
class="contact-item"
|
:class="{ 'selected': isSelected(contact) }"
|
@click="selectContact(contact)"
|
>
|
<view class="contact-info">
|
<view class="contact-avatar">
|
<text class="avatar-text">{{ contact.nickName.charAt(0) }}</text>
|
</view>
|
<view class="contact-details">
|
<text class="contact-name">{{ contact.nickName }}</text>
|
<!-- <text class="contact-dept">{{ contact.department }}</text>-->
|
</view>
|
</view>
|
</view>
|
</van-list>
|
</view>
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, onMounted } from 'vue'
|
import { userListNoPageByTenantId } from "@/api/system/user"
|
|
const loading = ref(false)
|
const finished = ref(false)
|
const selectedContact = ref(null)
|
const userList = ref([])
|
|
// 接收传递的参数
|
const stepIndex = ref(0)
|
|
onMounted(() => {
|
// 获取页面参数
|
const pages = getCurrentPages()
|
const currentPage = pages[pages.length - 1]
|
if (currentPage.options.stepIndex !== undefined) {
|
stepIndex.value = parseInt(currentPage.options.stepIndex)
|
}
|
|
// 初始化联系人数据
|
initContacts()
|
})
|
|
const initContacts = () => {
|
userListNoPageByTenantId().then((res) => {
|
userList.value = res.data
|
})
|
finished.value = true
|
}
|
|
const onLoad = () => {
|
// 模拟加载更多数据
|
setTimeout(() => {
|
loading.value = false
|
finished.value = true
|
}, 1000)
|
}
|
|
const isSelected = (contact) => {
|
return selectedContact.value && selectedContact.value.userId === contact.userId
|
}
|
|
const selectContact = (contact) => {
|
// 单选模式,直接替换选中的联系人
|
selectedContact.value = contact
|
}
|
|
const clearSelected = () => {
|
selectedContact.value = null
|
}
|
|
const goBack = () => {
|
uni.navigateBack()
|
}
|
|
const confirmSelect = () => {
|
if (!selectedContact.value) {
|
uni.showToast({
|
title: '请选择一个联系人',
|
icon: 'none'
|
})
|
return
|
}
|
// 使用 uni.$emit 发送数据
|
uni.$emit('selectContact', {
|
stepIndex: stepIndex.value,
|
contact: selectedContact.value
|
})
|
uni.navigateBack()
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.contact-select {
|
min-height: 100vh;
|
background: #f8f9fa;
|
}
|
|
.header {
|
background: #ffffff;
|
padding: 16px 20px;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
border-bottom: 1px solid #f0f0f0;
|
position: sticky;
|
/* 兼容 iOS 刘海/灵动岛安全区 */
|
padding-top: calc(env(safe-area-inset-top));
|
top: 0;
|
z-index: 100;
|
position: relative;
|
}
|
|
.title {
|
font-size: 18px;
|
font-weight: 600;
|
color: #333;
|
}
|
|
.confirm-btn {
|
color: #006cfb;
|
font-size: 16px;
|
font-weight: 500;
|
}
|
|
.search-section {
|
background: #fff;
|
padding: 12px 16px;
|
border-bottom: 1px solid #f0f0f0;
|
}
|
|
.selected-section {
|
background: #fff;
|
margin-top: 8px;
|
padding: 16px;
|
}
|
|
.selected-header {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
margin-bottom: 12px;
|
}
|
|
.selected-title {
|
font-size: 14px;
|
color: #333;
|
font-weight: 500;
|
}
|
|
.clear-btn {
|
color: #006cfb;
|
font-size: 14px;
|
}
|
|
.selected-item {
|
display: flex;
|
align-items: center;
|
background: #f0f8ff;
|
border: 1px solid #006cfb;
|
border-radius: 12px;
|
padding: 12px;
|
gap: 12px;
|
position: relative;
|
|
&::before {
|
content: '';
|
position: absolute;
|
top: -2px;
|
right: -2px;
|
width: 16px;
|
height: 16px;
|
background: #52c41a;
|
border-radius: 50%;
|
border: 2px solid #fff;
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
}
|
|
&::after {
|
content: '✓';
|
position: absolute;
|
top: -1px;
|
right: -1px;
|
width: 16px;
|
height: 16px;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
font-size: 10px;
|
color: #fff;
|
font-weight: bold;
|
}
|
}
|
|
.contact-list {
|
background: #fff;
|
margin-top: 8px;
|
}
|
|
.list-header {
|
padding: 16px;
|
border-bottom: 1px solid #f0f0f0;
|
}
|
|
.list-title {
|
font-size: 14px;
|
color: #666;
|
}
|
|
.contact-item {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
padding: 12px 16px;
|
border-bottom: 1px solid #f8f9fa;
|
transition: all 0.2s;
|
position: relative;
|
|
&.selected {
|
background-color: #f0f8ff;
|
|
&::before {
|
content: '';
|
position: absolute;
|
left: 8px;
|
top: 50%;
|
transform: translateY(-50%);
|
width: 4px;
|
height: 4px;
|
background: #006cfb;
|
border-radius: 50%;
|
box-shadow: 0 0 0 4px rgba(0, 108, 251, 0.2);
|
}
|
}
|
|
&:active {
|
background-color: #f5f5f5;
|
}
|
}
|
|
.contact-info {
|
display: flex;
|
align-items: center;
|
flex: 1;
|
padding-left: 16px;
|
}
|
|
.contact-avatar {
|
width: 40px;
|
height: 40px;
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
border-radius: 50%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
margin-right: 12px;
|
position: relative;
|
}
|
|
.avatar-text {
|
color: #fff;
|
font-size: 16px;
|
font-weight: 500;
|
}
|
|
.contact-details {
|
flex: 1;
|
}
|
|
.contact-name {
|
display: block;
|
font-size: 16px;
|
color: #333;
|
}
|
|
.contact-dept {
|
font-size: 12px;
|
color: #999;
|
}
|
|
// 自定义单选按钮样式
|
:deep(.van-radio) {
|
.van-radio__icon {
|
width: 20px;
|
height: 20px;
|
border: 2px solid #ddd;
|
border-radius: 50%;
|
background: #fff;
|
position: relative;
|
transition: all 0.2s;
|
|
&::before {
|
content: '';
|
position: absolute;
|
top: 50%;
|
left: 50%;
|
transform: translate(-50%, -50%) scale(0);
|
width: 8px;
|
height: 8px;
|
background: #006cfb;
|
border-radius: 50%;
|
transition: transform 0.2s;
|
}
|
}
|
|
&.van-radio--checked {
|
.van-radio__icon {
|
border-color: #006cfb;
|
background: #fff;
|
|
&::before {
|
transform: translate(-50%, -50%) scale(1);
|
}
|
|
&::after {
|
content: '';
|
position: absolute;
|
top: -2px;
|
left: -2px;
|
right: -2px;
|
bottom: -2px;
|
border: 2px solid rgba(0, 108, 251, 0.2);
|
border-radius: 50%;
|
animation: ripple 0.6s ease-out;
|
}
|
}
|
}
|
}
|
|
@keyframes ripple {
|
0% {
|
transform: scale(0.8);
|
opacity: 1;
|
}
|
100% {
|
transform: scale(1.2);
|
opacity: 0;
|
}
|
}
|
</style>
|