<template>
|
<div class="voiceCallContainer" :style="{ paddingTop: topMargin + 'px' }">
|
<!-- 顶部搜索栏 -->
|
<div class="searchBar">
|
<up-search placeholder="请输入关键字搜索" v-model="defaultParam.nickName" :animation="true" :show-action="false" @confirm="onSearch" @search="onSearch" @clear="handleClear"></up-search>
|
</div>
|
|
<!-- 联系人列表 -->
|
<div class="contactList" @scrolltolower="onScrollToLower">
|
<div
|
class="contactItem"
|
v-for="(contact, index) in contacts"
|
:key="index"
|
>
|
<div class="itemBox">
|
<!-- 头像 -->
|
<div class="contactAvatar">
|
<image :src="contact.avatar || defaultAvatar" :class="{ 'avatar-disabled': contact.online === 0}" />
|
</div>
|
|
<!-- 联系人信息 -->
|
<div class="contactInfo">
|
<div class="contactName">{{ contact.nickName || '未知联系人' }}</div>
|
<div class="contactDept">{{ contact.deptName || '未知部门' }}</div>
|
</div>
|
|
<!-- 电话按钮 -->
|
<div class="callButton" :class="{ 'call-button-disabled': contact.online === 0 }" @click="makeCall(contact)">
|
<image src="@/static/images/voiceVal/phoneVal.svg" />
|
</div>
|
</div>
|
|
</div>
|
|
<!-- 加载提示 -->
|
<div class="loadingMore">
|
<text v-if="loading">加载中...</text>
|
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import { getStatusBarHeight } from '@/utils/common';
|
import { useUserStore, useAppStore } from "@/store/index.js"
|
const topMargin = getStatusBarHeight()
|
import { getPhoneBookListApi } from '@/api/voiceCall/index.js'
|
import { onShow } from '@dcloudio/uni-app'
|
import defaultAvatar from '/static/images/defaultAvatar.svg'
|
const userStore = useUserStore()
|
const appStore = useAppStore()
|
const userId = userStore.userInfo.new_userInfo.userId
|
// 联系人数据
|
const contacts = ref([])
|
const defaultParam = ref({
|
current: 1,
|
size: 10,
|
nickName: ''
|
})
|
|
// 加载状态
|
const loading = ref(false)
|
const hasMore = ref(true)
|
|
// 获取通讯录
|
const getPhoneBookList = () => {
|
if (loading.value || !hasMore.value) return
|
loading.value = true
|
// 添加分页参数
|
const params = {
|
current: defaultParam.value.current,
|
size: defaultParam.value.size,
|
nickName: defaultParam.value.nickName
|
}
|
|
getPhoneBookListApi(params).then(res => {
|
const response = res.data.data
|
// 过滤掉与当前登录用户userId一致的联系人
|
const filteredRecords = response.records.filter(contact => {
|
return contact.userId && String(contact.userId) !== String(userId)
|
})
|
if (defaultParam.value.current === 1) {
|
contacts.value = filteredRecords
|
// 更新通讯录到全局状态管理
|
appStore.updateContactList(filteredRecords)
|
} else {
|
contacts.value = [...contacts.value, ...filteredRecords]
|
// 更新通讯录到全局状态管理
|
appStore.updateContactList(contacts.value)
|
}
|
|
// 判断是否还有更多数据
|
if (filteredRecords.length < defaultParam.value.size || response.current >= response.pages) {
|
hasMore.value = false
|
} else {
|
hasMore.value = true
|
}
|
|
}).catch(err => {
|
console.error('获取通讯录失败:', err)
|
const errorMsg = err.msg || err.message || '获取通讯录失败'
|
uni.showToast({
|
title: errorMsg,
|
icon: 'none',
|
duration: 3000
|
})
|
}).finally(() => {
|
loading.value = false
|
})
|
}
|
|
// 加载更多
|
const loadMore = () => {
|
if (loading.value || !hasMore.value) return
|
|
defaultParam.value.current++
|
getPhoneBookList()
|
}
|
const onSearch = () => {
|
defaultParam.value.current = 1
|
hasMore.value = true
|
getPhoneBookList()
|
|
}
|
const handleClear = () => {
|
defaultParam.value.nickName = ''
|
defaultParam.value.current = 1
|
hasMore.value = true
|
getPhoneBookList()
|
}
|
// 拨打电话方法
|
const makeCall = (contact) => {
|
if (contact.online === 0) {
|
return
|
}
|
console.log('拨打电话', contact)
|
// 将contact对象转换为JSON字符串并URL编码
|
const contactStr = encodeURIComponent(JSON.stringify(contact))
|
uni.navigateTo({
|
url: `/subPackages/voiceCallDetail/index?contact=${contactStr}`,
|
})
|
}
|
|
onShow(() => {
|
// 重置分页参数
|
defaultParam.value.current = 1
|
hasMore.value = true
|
getPhoneBookList()
|
});
|
|
// 监听滚动到底部
|
const onScrollToLower = () => {
|
loadMore()
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.voiceCallContainer {
|
width: 100%;
|
height: 100%;
|
display: flex;
|
flex-direction: column;
|
box-sizing: border-box;
|
}
|
|
.searchBar {
|
padding: 20rpx 20rpx 0 20rpx;
|
display: flex;
|
align-items: center;
|
height: 108rpx;
|
:deep(){
|
.u-search__content{
|
background: #fff !important;
|
}
|
.u-search__content__input{
|
background: #fff !important;
|
}
|
}
|
}
|
|
.contactList {
|
margin: 0 20rpx 20rpx 20rpx;
|
background: #fff;
|
border-radius: 12rpx;
|
overflow-y: auto;
|
height: 0;
|
flex-grow: 1;
|
align-content: flex-start;
|
}
|
|
.contactItem {
|
display: flex;
|
align-items: center;
|
padding: 0 20rpx;
|
|
}
|
|
.itemBox {
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
width: 100%;
|
height: 98rpx;
|
border-bottom: 1rpx solid #EBEBEB;
|
}
|
|
.contactAvatar {
|
width: 80rpx;
|
height: 80rpx;
|
margin-right: 26rpx;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
}
|
|
.contactAvatar image {
|
width: 60rpx;
|
height: 60rpx;
|
}
|
|
.contactInfo {
|
flex: 1;
|
display: flex;
|
justify-content: space-around;
|
align-items: center;
|
}
|
|
.contactName {
|
font-family: Source Han Sans CN, Source Han Sans CN;
|
font-weight: 500;
|
font-size: 30rpx;
|
color: #222324;
|
margin-bottom: 8rpx;
|
}
|
|
.contactDept {
|
font-family: Source Han Sans CN, Source Han Sans CN;
|
font-weight: 400;
|
font-size: 30rpx;
|
color: #222324;
|
}
|
|
.callButton {
|
width: 80rpx;
|
height: 80rpx;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
}
|
|
.callButton image {
|
width: 60rpx;
|
height: 60rpx;
|
|
}
|
|
/* 禁用状态样式 */
|
.avatar-disabled {
|
filter: grayscale(100%);
|
opacity: 0.6;
|
}
|
|
.call-button-disabled {
|
opacity: 0.6;
|
pointer-events: none;
|
}
|
|
.call-button-disabled image {
|
filter: grayscale(100%);
|
}
|
|
.loadingMore {
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
height: 80rpx;
|
font-size: 28rpx;
|
color: #999;
|
}
|
</style>
|