| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- <template>
- <view>
- <u-navbar
- title="选择朋友"
- :safeAreaInsetTop="true"
- :placeholder="true"
- :fixed="true"
- leftIcon="close"
- :autoBack="true"
- >
- </u-navbar>
- <!-- 好友列表 -->
- <view>
- <u-list @scrolltolower="scrolltolower">
- <u-list-item v-for="(friendItem, index) in friendList" :key="index">
- <!-- 展示的cell不能为当前聊天中的好友 -->
- <u-cell
- v-if="chattingId !== friendItem.userId"
- @click="openWaitSendModal(friendItem.userId)"
- >
- <u-avatar
- slot="icon"
- shape="square"
- size="40"
- :src="showFriendAvatar(friendItem)"
- customStyle="margin: -3px 5px -3px 0"
- ></u-avatar>
- <view slot="title">
- <u--text
- :lines="1"
- :text="showFriendNickname(friendItem)"
- iconStyle="margin-left: 2px;"
- ></u--text>
- </view>
- </u-cell>
- </u-list-item>
- </u-list>
- </view>
- <!-- 待发送modal -->
- <u-modal
- :show="isShowWaitSendModal"
- :zoom="true"
- title="发送名片"
- async-close
- show-cancel-button
- confirm-text="发送"
- cancel-text="取消"
- @confirm="sendUserCardMessage"
- @cancel="closeWaitSendModal"
- >
- <view class="content_box">
- <text class="send_target_title">发送给:</text>
- <view class="send_target_user_info">
- <image
- class="send_target_avatar"
- :src="showFriendAvatar(chattingId)"
- ></image>
- <text class="send_target_nickname">{{
- showFriendNickname({ userId: chattingId })
- }}</text>
- </view>
- <text class="wait_send_user_nickname"
- >[个人名片] {{ waitSendUserNickname || waitSendUserId || '' }}</text
- >
- <u-input
- class="leave_message_input"
- v-model="leaveMessageInput"
- placeholder="给朋友留言"
- type="text"
- maxlength="100"
- />
- </view>
- </u-modal>
- </view>
- </template>
- <script>
- import { emMessages } from '@/EaseIM/emApis';
- import { MESSAGE_TYPE } from '@/EaseIM/constant';
- const { sendDisplayMessages } = emMessages();
- export default {
- data() {
- return {
- sendTargetInfo: {
- userId: '',
- chatType: '',
- },
- isShowWaitSendModal: false,
- waitSendUserId: '',
- waitSendUserNickname: '',
- leaveMessageInput: '',
- defaultAvatar: '/static/images/new_ui/defaultAvatar.png',
- };
- },
- computed: {
- chattingId() {
- return this.$store.getters.chattingId;
- },
- chattingChatType() {
- return this.$store.getters.chattingChatType;
- },
- //好友列表
- friendList() {
- return this.$store.state.ContactsStore.friendList;
- },
- friendUserInfoCollection() {
- return this.$store.getters.friendUserInfoCollection;
- },
- //好友头像展示
- showFriendAvatar() {
- return (hxId) => {
- if (
- this.friendUserInfoCollection[hxId] &&
- this.friendUserInfoCollection[hxId]?.avatarurl
- ) {
- return this.friendUserInfoCollection[hxId].avatarurl;
- } else {
- return this.defaultAvatar;
- }
- };
- },
- //好友昵称展示
- showFriendNickname() {
- return (userItem) => {
- const { userId, remark } = userItem;
- if (remark) {
- return remark;
- }
- if (
- this.friendUserInfoCollection[userId] &&
- this.friendUserInfoCollection[userId]?.nickname
- ) {
- return this.friendUserInfoCollection[userId].nickname;
- } else {
- return userId;
- }
- };
- },
- },
- methods: {
- scrolltolower() {},
- loginUserAvactar() {
- return (
- this.$store.state.LoginStore.loginUserProfiles?.avatarurl ||
- this.defaultAvatar
- );
- },
- openWaitSendModal(userId) {
- console.log('>>>>>>>111', userId);
- this.isShowWaitSendModal = true;
- this.$nextTick(() => {
- this.waitSendUserId = userId;
- this.getWaitSendUserInfo(userId);
- });
- },
- getWaitSendUserInfo(userId) {
- if (this.friendUserInfoCollection[userId]) {
- this.waitSendUserNickname =
- this.friendUserInfoCollection[userId].nickname;
- return this.friendUserInfoCollection[userId];
- }
- },
- closeWaitSendModal() {
- this.isShowWaitSendModal = false;
- this.waitSendUserId = '';
- this.waitSendUserNickname = '';
- },
- async sendUserCardMessage() {
- const customEvent = 'userCard';
- if (!this.chattingId) return;
- const friendInfo = this.getWaitSendUserInfo(this.waitSendUserId);
- const customExtParams = {
- uid: this.waitSendUserId,
- ...friendInfo,
- };
- const params = {
- type: MESSAGE_TYPE.CUSTOM,
- // 消息接收方:单聊为对方用户 ID,群聊和聊天室分别为群组 ID 和聊天室 ID。
- to: this.chattingId,
- // 会话类型:单聊、群聊和聊天室分别为 `singleChat`、`groupChat` 和 `chatRoom`。
- chatType: this.chattingChatType,
- customEvent,
- customExts: { ...customExtParams },
- };
- try {
- await sendDisplayMessages({ ...params });
- if (this.leaveMessageInput) {
- this.sendLeaveTextMessage();
- }
- } catch (error) {
- uni.showToast({
- title: '消息发送失败',
- icon: 'none',
- });
- } finally {
- this.isShowWaitSendModal = false;
- uni.navigateBack();
- }
- },
- async sendLeaveTextMessage() {
- const params = {
- // 消息类型。
- type: 'txt',
- // 消息内容。
- msg: this.leaveMessageInput,
- // 消息接收方:单聊为对方用户 ID,群聊和聊天室分别为群组 ID 和聊天室 ID。
- to: this.chattingId,
- // 会话类型:单聊、群聊和聊天室分别为 `singleChat`、`groupChat` 和 `chatRoom`。
- chatType: this.chattingChatType,
- };
- try {
- const res = await sendDisplayMessages({ ...params });
- console.log('>>>>>留言消息发送成功', res);
- } catch (error) {
- console.log('>>>>>留言消息发送失败', error);
- uni.showToast({
- title: '消息发送失败',
- icon: 'none',
- });
- } finally {
- this.leaveMessageInput = '';
- uni.hideKeyboard && uni.hideKeyboard();
- }
- },
- },
- };
- </script>
- <style scoped>
- .content_box {
- width: 100%;
- display: flex;
- flex-direction: column;
- }
- .send_target_user_info {
- display: flex;
- justify-content: flex-start;
- align-items: center;
- border-bottom: 1rpx solid #eee;
- }
- .send_target_title {
- font-size: 33rpx;
- color: #333;
- font-weight: 600;
- }
- .send_target_avatar {
- width: 60rpx;
- height: 60rpx;
- border-radius: 50%;
- margin-right: 20rpx;
- }
- .send_target_nickname {
- font-size: 35rpx;
- color: #333;
- font-weight: 500;
- }
- .wait_send_user_nickname {
- font-size: 22rpx;
- color: rgba(51, 51, 51, 0.6);
- font-weight: 500;
- overflow: hidden;
- margin-top: 20rpx;
- }
- .leave_message_input {
- margin-top: 10rpx;
- background-color: #f7f7f7;
- border-radius: 5rpx;
- }
- </style>
|