Files
im/pages/common/contactChoose/index.vue
T

312 lines
7.6 KiB
Vue
Raw Normal View History

2025-11-07 09:56:20 +08:00
<template>
2025-11-25 05:36:02 +08:00
<view class="contact_choose_container">
2026-02-15 19:40:36 +08:00
<uni-nav-bar
left-icon="back"
@clickLeft="uni.$u.route({type:'back'})"
statusBar
title="联系人">
</uni-nav-bar>
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
<view class="search_bar_wrap">
<u-search shape="square" placeholder="搜索" :showAction="false" v-model="keyword" />
</view>
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
<view class="tab_container">
<template v-if="activeTab === 0">
2026-02-15 19:40:36 +08:00
<div @click="tabChange(tabs[0].idx)" style="display: flex; align-items: center;justify-content: space-between;padding: 20rpx 40rpx;">
{{ tabs[0].title }}
<u-icon name="arrow-right" />
</div>
2025-12-05 16:10:52 +08:00
<view class="tab_pane">
<user-item
@updateCheck="updateCheckedUser"
:checked="checkedUserIDList.includes(cell.userID)"
:disabled="disabledUserIDList.includes(cell.userID)"
:checkVisible="true"
2026-02-15 19:40:36 +08:00
v-for="cell in conversationList" :item="cell" :key="cell.userID" />
2025-12-05 16:10:52 +08:00
</view>
2025-11-25 05:36:02 +08:00
</template>
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
<template v-else>
<view class="tab_pane" v-show="activeTab === 1">
<choose-index-list @updateCheck="updateCheckedUser" :indexList="getChooseData.indexList"
:itemArr="getChooseData.dataList" :checkedIDList="checkedUserIDList"
:disabledIDList="disabledUserIDList" :showCheck="true" />
</view>
</template>
</view>
2025-12-05 16:10:52 +08:00
<choose-index-footer v-show="limit != 1" :comfirmLoading="comfirmLoading" @removeItem="updateCheckedUserOrGroup" @confirm="confirm"
2025-11-25 05:36:02 +08:00
:choosedData="getCheckedInfo" />
</view>
2025-11-07 09:56:20 +08:00
</template>
<script>
2026-02-15 19:40:36 +08:00
import { mapGetters } from "vuex";
2025-11-25 05:36:02 +08:00
import {ContactChooseTypes} from "@/constant";
import {formatChooseData,toastWithCallback} from "@/util/common";
2026-02-15 19:40:36 +08:00
import IMSDK from "openim-uniapp-polyfill"
2025-11-25 05:36:02 +08:00
import UserItem from "@/components/UserItem/index.vue";
import ChooseIndexList from "@/components/ChooseIndexList/index.vue";
import ChooseIndexFooter from "@/components/ChooseIndexFooter/index.vue";
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
export default {
components: {
UserItem,
ChooseIndexList,
2026-02-15 19:40:36 +08:00
ChooseIndexFooter
2025-11-25 05:36:02 +08:00
},
data() {
return {
keyword: "",
type: ContactChooseTypes.Card,
activeTab: 0,
groupID: "",
checkedUserIDList: [],
disabledUserIDList: [],
comfirmLoading: false,
tabs: [
{
idx: 1,
title: "我的好友",
},
],
2025-12-05 16:10:52 +08:00
limit:0,
2025-11-25 05:36:02 +08:00
};
},
computed: {
2026-02-15 19:40:36 +08:00
...mapGetters(["storeFriendList","storeConversationList",'storeCurrentConversation',"storeCurrentUserID"]),
conversationList(){
const _this = this;
let list = [...this.storeConversationList];
list = list.filter((item)=>{
return !item.userID.startsWith('system') && !item.userID.startsWith('official_team') && item.userID !== this.storeCurrentUserID
});
if(!this.allowGroup){
list = list.filter((item)=>{
return !item.groupID
});
}
if(this.keyword){
list = list.filter((item)=>{
return item.showName.indexOf(_this.kw)>-1 || item.userID.indexOf(_this.kw)>-1 || item.groupID.indexOf(_this.kw)>-1
})
}
return list;
},
2025-11-25 05:36:02 +08:00
getChooseData() {
2026-02-15 19:40:36 +08:00
const _this = this;
let list = [...this.storeFriendList];
list = list.filter((item)=>{
return !item.userID.startsWith('system') && !item.userID.startsWith('official_team') && item.userID !== this.storeCurrentUserID
});
if(!this.allowGroup){
list = list.filter((item)=>{
return !item.groupID
});
}
2025-11-25 05:36:02 +08:00
if (this.keyword) {
return {
indexList: ["#"],
dataList: [
2026-02-15 19:40:36 +08:00
list.filter(
2025-11-25 05:36:02 +08:00
(friend) =>
friend.nickname.includes(this.keyword) ||
friend.remark.includes(this.keyword)
),
],
};
}
2026-02-15 19:40:36 +08:00
return formatChooseData(list);
2025-11-25 05:36:02 +08:00
},
getCheckedInfo() {
const tmpUserIDList = [...this.checkedUserIDList];
const checkedFriends = this.storeFriendList.filter((friend) => {
const idx = tmpUserIDList.findIndex(
(userID) => userID === friend.userID
);
if (idx > -1) {
tmpUserIDList.splice(idx, 1);
}
return idx > -1;
});
return [...checkedFriends];
},
},
onLoad(options) {
2026-02-15 19:40:36 +08:00
//cardInfo
const {groupID,type,checkedUserIDList,muitple,allowType,limit} = options;
2025-11-25 05:36:02 +08:00
this.type = type;
2026-02-15 19:40:36 +08:00
if(allowType){
this.allowGroup = allowType === 'All';
}
2025-11-25 05:36:02 +08:00
this.groupID = groupID;
2026-02-15 19:40:36 +08:00
if(muitple){
this.muitple = muitple;
}
2025-12-05 16:10:52 +08:00
this.checkedUserIDList = checkedUserIDList ? JSON.parse(checkedUserIDList) : [];
2025-11-25 05:36:02 +08:00
if (this.type === ContactChooseTypes.Invite) {
this.checkDisabledUser();
}
2025-12-05 16:10:52 +08:00
if(limit){
this.limit = limit;
}
2025-11-25 05:36:02 +08:00
},
methods: {
checkDisabledUser() {
const friendIDList = this.storeFriendList.map((friend) => friend.userID);
IMSDK.asyncApi("getUsersInGroup", IMSDK.uuid(), {
groupID: this.groupID,
userIDList: friendIDList,
}).then(({
data
}) => {
this.disabledUserIDList = data;
});
},
tabChange(idx) {
this.keyword = "";
this.activeTab = idx;
},
updateCheckedUserOrGroup(item) {
if (item.userID) {
this.updateCheckedUser(item);
}
},
2025-12-05 16:10:52 +08:00
updateCheckedUser({userID}) {
if(this.limit == 1){
this.checkedUserIDList = [userID];
this.confirm();
}else{
if (this.checkedUserIDList.includes(userID)) {
const idx = this.checkedUserIDList.findIndex((item) => item === userID);
const tmpArr = [...this.checkedUserIDList];
tmpArr.splice(idx, 1);
this.checkedUserIDList = [...tmpArr];
} else {
this.checkedUserIDList = [...this.checkedUserIDList, userID];
}
2025-11-25 05:36:02 +08:00
}
},
confirm() {
if (this.activeTab) {
this.activeTab = 0;
return;
}
this.comfirmLoading = true;
if (this.type === ContactChooseTypes.GetList) {
let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.$vm.getCheckedUsers(this.getCheckedInfo);
this.comfirmLoading = false;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
uni.navigateBack({
delta: 1,
});
return;
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
if (this.type === ContactChooseTypes.Invite) {
IMSDK.asyncApi(IMSDK.IMMethods.InviteUserToGroup, IMSDK.uuid(), {
groupID: this.groupID,
reason: "",
userIDList: this.getCheckedInfo.map((user) => user.userID),
})
.then(() => {
toastWithCallback("操作成功", () => uni.navigateBack());
this.comfirmLoading = false;
})
.catch(() => toastWithCallback("操作失败"));
return;
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
this.comfirmLoading = false;
},
},
onBackPress() {
if (this.activeTab) {
this.activeTab = 0;
return true;
}
return false;
},
};
2025-11-07 09:56:20 +08:00
</script>
<style lang="scss" scoped>
2025-11-25 05:36:02 +08:00
::v-deep.u-popup {
flex: none;
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.contact_choose_container {
height: 100vh;
display: flex;
flex-direction: column;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.search_bar_wrap {
height: 34px;
padding: 12px 22px;
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.tab_container {
@include colBox(false);
flex: 1;
overflow: hidden;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.setting_item {
padding: 32rpx 36rpx;
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.title {
height: 60rpx;
display: flex;
2025-12-05 16:10:52 +08:00
justify-content: flex-start;
2025-11-25 05:36:02 +08:00
align-items: center;
// padding: 16rpx 8rpx;
background: #f8f9fa;
color: #8e9ab0;
font-size: 24rpx;
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.tabs_bar {
@include vCenterBox();
justify-content: space-evenly;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.tab_item {
@include colBox(false);
align-items: center;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
image {
width: 50px;
height: 50px;
}
}
}
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.tab_pane {
display: flex;
flex-direction: column;
flex: 1;
overflow: hidden;
2025-11-07 09:56:20 +08:00
2025-11-25 05:36:02 +08:00
.member_list {
flex: 1;
height: 80% !important;
::v-deepuni-scroll-view {
max-height: 100% !important;
}
}
.user_list {
height: 100% !important;
}
.member_anchor {
background-color: #f8f8f8 !important;
border: none !important;
}
}
}
}
</style>