<template>
  <view class="conversation_container">
   <u-navbar :placeholder="true">
	  <view  slot="left">
		  <u-icon name="arrow-left" color="#000" size="28" @click="gotoPage('/pages/index/index')"></u-icon>
	  </view>
      <view slot="center">
		消息
      </view>
    </u-navbar>
    <template v-if="pinConversationList.length || conversationList.length">
      <!-- 搜索会话列表相关 -->
      <view>
        <view class="search_container" v-if="isShowDefaultSearch">
          <view class="search_icon_box" @tap="openSearch">
            <icon type="search" size="22"></icon>
            <text class="search_text">搜索</text>
          </view>
        </view>
      </view>
      <view class="searching_container" v-if="!isShowDefaultSearch">
        <u-search
          class="searching_input"
          height="36"
          v-model.trim="searchInputKeywords"
          shape="square"
          placeholder="搜索"
          :actionText="'取消'"
          :actionStyle="{
            color: '#0873de',
          }"
          :clearabled="true"
          :focus="true"
          @search="actionSearch"
          @input="actionSearch"
          @custom="cancelSearch"
        ></u-search>
      </view>
      <!-- 展示搜索会话结果List -->
      <template v-if="!isShowDefaultSearch">
        <u-list
          v-if="searchResConversationList.length > 0"
          :height="conversationListHeight"
        >
          <u-list-item
            v-for="conversationItem in searchResConversationList"
            :key="conversationItem.conversationId"
          >
            <u-cell @click="entryChatPage(conversationItem)">
              <!-- 头像 -->
              <u-avatar
                slot="icon"
                shape="square"
                size="50"
                :src="showConversationAvatar(conversationItem)"
                customStyle="margin: -3px 5px -3px 0"
              ></u-avatar>
              <!-- name -->
              <view class="conversation_item_title" slot="title">
                <u--text
                  class="conversation_item_title_text"
                  :lines="1"
                  :text="showConversationName(conversationItem)"
                  :suffixIcon="
                    conversationItemSilentStatus(
                      conversationItem.conversationId
                    )
                      ? '/static/images/new_ui/no_disturbing.png'
                      : ''
                  "
                  iconStyle="margin-left: 2px;"
                >
                </u--text>
              </view>
              <!-- lastmsg -->
              <u--text
                slot="label"
                :lines="1"
                :text="handleLastMsgContent(conversationItem.lastMessage)"
              ></u--text>
              <!-- time&unReadNum -->
              <view slot="value" class="conversation_item_right">
                <view>
                  <view class="conversation_item_time">{{
                    handleTime(conversationItem)
                  }}</view>
                  <view class="conversation_item_unread">
                    <u-badge
                      class="conversation_item_badge"
                      type="primary"
                      max="99"
                      :isDot="
                        (conversationItemSilentStatus(
                          conversationItem.conversationId
                        ) &&
                          conversationItem.unReadCount > 0) ||
                        conversationItem.isRead === false
                      "
                      :offset="[15, 0]"
                      :absolute="true"
                      :value="conversationItem.unReadCount"
                    ></u-badge>
                  </view>
                </view>
              </view>
            </u-cell>
          </u-list-item>
        </u-list>
        <u-empty v-if="searchResConversationList.length === 0" mode="search">
        </u-empty>
      </template>
      <!-- 会话列表展示相关 -->
      <template v-else>
        <u-list @scrolltolower="scrolltolower" :height="conversationListHeight">
          <!-- 系统通知 -->
          <!-- <u-list-item v-if="lastInformData">
            <u-cell title="系统通知" value="系统通知哈哈哈哈">
              <u-avatar
                slot="icon"
                shape="square"
                size="35"
                src="../../static/images/inform.png"
                customStyle="margin: -3px 5px -3px 0"
              ></u-avatar>
              <text slot="value" class="u-slot-value">{{
                handleTime(lastInformData)
              }}</text>
            </u-cell>
          </u-list-item> -->
          <!-- 置顶会话列表 -->
          <template v-if="pinConversationList.length">
            <u-list-item
              v-for="(conversationItem, index) in pinConversationList"
              :key="conversationItem.conversationId"
            >
              <view
                class="pinconversation_item"
                @longpress="onConversationMoreFunction(conversationItem)"
                @click="entryChatPage(conversationItem)"
              >
                <u-cell>
                  <!-- 头像 -->
                  <u-avatar
                    slot="icon"
                    shape="square"
                    size="50"
                    :src="showConversationAvatar(conversationItem)"
                    customStyle="margin: -3px 5px -3px 0"
                  ></u-avatar>
                  <!-- name -->
                  <view class="conversation_item_title" slot="title">
                    <u--text
                      class="conversation_item_title_text"
                      :lines="1"
                      :text="showConversationName(conversationItem)"
                      :suffixIcon="
                        conversationItemSilentStatus(
                          conversationItem.conversationId
                        )
                          ? '/static/images/new_ui/no_disturbing.png'
                          : ''
                      "
                      iconStyle="margin-left: 2px;"
                    >
                    </u--text>
                  </view>
                  <!-- lastmsg -->
                  <u--text
                    slot="label"
                    :lines="1"
                    :text="handleLastMsgContent(conversationItem.lastMessage)"
                  ></u--text>
                  <!-- time&unReadNum -->
                  <view slot="value" class="conversation_item_right">
                    <view>
                      <view class="conversation_item_time">{{
                        handleTime(conversationItem)
                      }}</view>
                      <view class="conversation_item_unread">
                        <u-badge
                          class="conversation_item_badge"
                          type="primary"
                          max="99"
                          :isDot="
                            (conversationItemSilentStatus(
                              conversationItem.conversationId
                            ) &&
                              conversationItem.unReadCount > 0) ||
                            conversationItem.isRead === false
                          "
                          :offset="[15, 0]"
                          :absolute="true"
                          :value="conversationItem.unReadCount"
                        ></u-badge>
                      </view>
                    </view>
                  </view>
                </u-cell>
              </view>
            </u-list-item>
          </template>

          <!-- 普通会话列表 -->
          <u-list-item
            class="conversation_item"
            v-for="(conversationItem, index) in conversationList"
            :key="conversationItem.conversationId"
          >
            <template>
			  <!-- <swipe-delete @deleteChatItem="handleDelete(conversationItem)">	 -->
              <swipe-delete>
                <view
                  @longpress="onConversationMoreFunction(conversationItem)"
                  @click="entryChatPage(conversationItem)"
                >
                  <u-cell>
                    <!-- 头像 -->
                    <u-avatar
                      slot="icon"
                      shape="square"
                      size="50"
                      :src="showConversationAvatar(conversationItem)"
                      customStyle="margin: -3px 5px -3px 0"
                    ></u-avatar>
                    <!-- name -->
                    <view class="conversation_item_title" slot="title">
                      <u--text
                        class="conversation_item_title_text"
                        :lines="1"
                        :text="showConversationName(conversationItem)"
                        :suffixIcon="
                          conversationItemSilentStatus(
                            conversationItem.conversationId
                          )
                            ? '/static/images/new_ui/no_disturbing.png'
                            : ''
                        "
                        iconStyle="margin-left: 2px;"
                      >
                      </u--text>
                    </view>
                    <!-- lastmsg -->
                    <u--text
                      slot="label"
                      :lines="1"
                      :text="handleLastMsgContent(conversationItem.lastMessage)"
                    ></u--text>
                    <!-- time&unReadNum -->
                    <view slot="value" class="conversation_item_right">
                      <view>
                        <view class="conversation_item_time">{{
                          handleTime(conversationItem)
                        }}</view>
                        <view class="conversation_item_unread">
                          <u-badge
                            class="conversation_item_badge"
                            type="primary"
                            max="99"
                            :isDot="
                              (conversationItemSilentStatus(
                                conversationItem.conversationId
                              ) &&
                                conversationItem.unReadCount > 0) ||
                              conversationItem.isRead === false
                            "
                            :offset="[15, 0]"
                            :absolute="true"
                            :value="conversationItem.unReadCount"
                          ></u-badge>
                        </view>
                      </view>
                    </view>
                  </u-cell>
                </view>
              </swipe-delete>
            </template>
          </u-list-item>
        </u-list>
        <u-action-sheet
          :actions="moreFunctionList"
          :closeOnClickOverlay="true"
          :closeOnClickAction="true"
          :safeAreaInsetBottom="true"
          :show="isShowMoreFunction"
          round="5"
          @select="onSelectClick"
          @close="onConversationMoreFunction"
        ></u-action-sheet>
      </template>
    </template>
    <u-empty v-else mode="history"> </u-empty>
  </view>
</template>

<script>
import { EMClient } from "@/EaseIM";
import {
		selectMerchant,
		selectMerchantOrder,
		payUserList
	} from '@/commit/shop.js'
import {
  MESSAGE_TYPE,
  SESSION_MESSAGE_TYPE,
  CUSTOM_TYPE,
  CHAT_TYPE,
} from '@/EaseIM/constant';
// import swipeDelete from '../../components/swipedelete/swipedelete';
import { emConversation,emConnect } from '@/EaseIM/emApis';
// const { sendChannelAck } = emConversation();
const tabBarHeight = 50;
const navBarHeight = 44;
const searchInputHeight = 45;
const { loginWithPassword } = emConnect();
import { emHandleReconnect } from "@/EaseIM/utils";
export default {
  data() {
    return {
	  nowConversationIntem:{},
	  chatUserList:[],//会话列表用户数组
	  loginEaseIMId:'',//环信的userid
      MESSAGE_TYPE,
      isShowDefaultSearch: true,
      searchResConversationList: [], //开启搜索时的会话列表
      searchInputKeywords: '',
      conversationListHeight: '100vh',
      // defaultAvatar: '/static/images/new_ui/defaultAvatar.png',
      // defaultAvatar: 'https://cdn.bjtdba.com/chuxubao/images/2024-04-24/2bc4c202404241807123503.jpg',
      defaultAvatar: ' https://app.bjtdba.com/uploads/logo.jpg',
      defaultGroupAvatar: '/static/images/new_ui/defaultGroupAvatar.png',
      longPressCheckedConversationItem: {},
      isShowMoreFunction: false,
      moreFunctionList: [
        {
          name: '会话置顶',
          type: 1,
          color: '#009EFF',
          fontSize: '15',
        },
        {
          name: '会话免打扰',
          type: 2,
          color: '#009EFF',
          fontSize: '15',
        },
        {
          name: '标记已读',
          type: 3,
          color: '#009EFF',
          fontSize: '15',
        },
        {
          name: '删除会话',
          type: 0,
          color: '#FF002B',
          fontSize: '15',
        },
      ],
    };
  },
  components: {
    // swipeDelete,
  },
  onShow() {
  	let authorization = uni.getStorageSync('authorization')
  	let userinfo = uni.getStorageSync('userinfo')
  	let selectmerchant = uni.getStorageSync('selectmerchant')
  	let uid = userinfo.uid
  	if (authorization && uid) {
  		if (selectmerchant.merId >= 0 && selectmerchant.status == -1) {
  			uni.redirectTo({
  				url: "/openmerchant/guide/index" //有或者没有商户 没有金额支付and激活码支付
  			});
  			return
  		} else if (selectmerchant.merId > 0 && (selectmerchant.status == 1 || selectmerchant.status == 5)) {
  			// uni.showLoading({
  			// 	title: '加载中',
  			// 	mask: true
  			// });
  			this.selectMerchant()
  			this.selectMerchantOrder()
  			this.payUserList()
  			return
  		} else if (selectmerchant.merId >= 0 && (selectmerchant.status == 3 || selectmerchant.status == 4)) {
  			uni.redirectTo({
  				url: '/openmerchant/shopentry/process?mer_id=' + selectmerchant.merId //已开通商户未填写资料
  			});
  			return
  		} else if (selectmerchant.merId > 0 && selectmerchant.status == 0) {
  			uni.redirectTo({
  				url: '/openmerchant/shopentry/processaudit?submitCode=' + 3 //已开通商户待审核
  			});
  			return
  		} else if (selectmerchant.merId > 0 && selectmerchant.status == 2) {
  			uni.redirectTo({
  				url: '/openmerchant/shopentry/processaudit?submitCode=' + 2 //已开通商户审核拒绝
  			});
  			return
  		}
  
  	} else {
  		uni.redirectTo({
  			url: "/pages/user/login/index"
  		});
  	}
  },
  computed: {
    loginUserProfiles() {
      return this.$store.state.LoginStore.loginUserProfiles;
    },
	//用户头像
    // loginUserAvatar() {
    //   if (this.loginUserProfiles.avatarurl) {
    //     return this.loginUserProfiles?.avatarurl;
    //   } else {
    //     return this.defaultAvatar;
    //   }
    // },
    pinConversationList() {
      return this.$store.getters.sortedPinConversationList;
    },
    conversationList() {
      return this.$store.getters.sortedConversationList;
    },
    friendUserInfoCollection() {
      return this.$store.getters.friendUserInfoCollection;
    },
    //好友列表
    friendList() {
      return this.$store.state.ContactsStore.friendList;
    },
    //会话头像展示
    showConversationAvatar() {
      return (conversationItem) => {
        const { conversationId, conversationType } = conversationItem;
		console.log('conversationItem',conversationItem)
        if (conversationType === CHAT_TYPE.SINGLE_CHAT) {
          // if (
          //   this.friendUserInfoCollection[conversationId] &&
          //   this.friendUserInfoCollection[conversationId]?.avatarurl
          // ) {
          //   return this.friendUserInfoCollection[conversationId].avatarurl;
          // } else {
          //   return this.defaultAvatar;
          // }
		  if (
		    this.chatUserList[conversationId] &&
		    this.chatUserList[conversationId].avatarurl
		  ) {
		    return this.chatUserList[conversationId].avatarurl;
		  } else {
		    return this.defaultAvatar;
		  }
		 
        } else if (conversationType === CHAT_TYPE.GROUP_CHAT) {
          return this.defaultGroupAvatar;
        }
      };
    },
    //会话name展示
    showConversationName() {
      return (conversationItem) => {
        const { conversationId, conversationType } = conversationItem;
        if (conversationType === CHAT_TYPE.SINGLE_CHAT) {
          if (
            this.friendList.some((f) => f.userId === conversationId)?.remark
          ) {
            return this.friendList.some((f) => f.userId === conversationId)
              .remark;
          } else if (
			this.chatUserList[conversationId]
          ) {
            return this.chatUserList[conversationId].nickname;
          } else {
			return this.chatUserList[conversationId].nickname||conversationId;
			// return 'nickname';
          }
        } else if (conversationType === CHAT_TYPE.GROUP_CHAT) {
          return this.getGroupName(conversationId);
        }
      };
    },
    //处理时间显示
    handleTime() {
      return (item) => {
        // return this.$u.timeFormat(item.time, 'mm/dd/hh:MM');
        // const {
        //   lastMessage: { time },
        // } = item;
        // console.log(item.lastMessage.time);
        return this.$u.timeFrom(item?.time || item?.lastMessage?.time);
      };
    },
    //处理预览消息内容
    handleLastMsgContent() {
      return (msgBody) => {
        const { type, msg } = msgBody;
        let resultContent = '';
        //如果消息类型，在预设非展示文本类型中，就返回预设值
        if (SESSION_MESSAGE_TYPE[type]) {
          resultContent = SESSION_MESSAGE_TYPE[type];
		  
        } else if (type === MESSAGE_TYPE.CUSTOM) {
          //如果为自定义类型消息就匹配自定义消息对应的lastmsg文本
     //      if (msgBody.customEvent) {
     //        (CUSTOM_TYPE[msgBody.customEvent] &&
     //          (resultContent = CUSTOM_TYPE[msgBody.customEvent])) ||
     //          '';
			  // console.log(22222222222,msgBody.customEvent（productLink）,CUSTOM_TYPE[msgBody.customEvent] （）);
     //      }
			if (msgBody.customEvent) {
			  (CUSTOM_TYPE[msgBody.customEvent] &&
			    (resultContent = CUSTOM_TYPE[msgBody.customEvent])) ||
			    '';
						  
			}
        } else {
			 
          resultContent = msg;
        }
        return resultContent;
      };
    },
    //系统通知
    lastInformData() {
      return this.$store.getters.getAllInformsList[
        this.$store.getters.getAllInformsList.length - 1
      ];
    },
    unReadNoticeNum() {
      return this.$store.getters.getAllInformsList.filter(
        (inform) => !inform.isHandled
      ).length;
    },
    //会话未读数
    allConversationUnReadNum() {
      return (
        this.unReadNoticeNum +
        this.$store.getters.calcAllUnReadNumFromConversation
      );
    },
    //免打扰状态
    conversationItemSilentStatus() {
      return (conversationId) => {
        const silentStatus =
          this.$store.getters.silentConversationMap[conversationId]?.type ===
          'NONE';
        return silentStatus;
      };
    },
  },
  created() {
    console.log('converstaion created');
    this.$store.dispatch('fetchPinConversationList');
    if (!this.conversationList.length) {
      this.$store.dispatch('fetchConversationList');
    }
    uni.hideHomeButton && uni.hideHomeButton();
    this.setConversationListHeigth();
	
	//得到会话列表用户属性数组
	const uidsarr1= JSON.parse(JSON.stringify(uni.getStorageSync('uIds')));
	EMClient.fetchUserInfoById(uidsarr1).then((resData)=>{
				this.chatUserList=resData.data;
	})
  },
  methods: {
	  // 最新纪录列表
	  payUserList() {
	  	payUserList({
	  		mer_id: this.mer_id,
	  		pageNum: this.page,
	  		pageSize: this.limit,
	  	}).then(res => {
	  		uni.stopPullDownRefresh();
	  		if (res.data.status == 200) {
	  			this.tihsi = res.data.data.pageInfo.list.length
	  			if (res.data.data.pageInfo.list.length > 0) { //分页处理
	  				if (this.page == 1) {
	  					this.List = res.data.data.pageInfo.list
	  				} else {
	  					this.List = this.List.concat(res.data.data.pageInfo.list)
	  				}
	  			} else {
	  				this.is_panudn = false
	  			}
	  			uni.hideLoading();
	  		}
	  	}, fail => {
	  		uni.hideLoading()
	  		console.log(fail)
	  	})
	  },
	  // 今日昨日收益
	  selectMerchantOrder() {
	  	// uni.showLoading({
	  	// 	title: '加载中',
	  	// });
	  	selectMerchantOrder({
	  		start_time: this.start_time,
	  		end_time: this.start_time,
	  		mer_id: this.mer_id
	  	}).then(res => {
	  		if (res.data.status == 200) {
	  			this.dataList = res.data.data
	  			uni.hideLoading();
	  		}
	  	}, fail => {
	  		console.log(fail)
	  		uni.hideLoading();
	  	})
	  },
	  // 店铺信息头
	  selectMerchant() {
	  	selectMerchant({
	  		mer_id: this.mer_id
	  	}).then(res => {
	  		console.log(res)
	  		if (res.data.status == 200) {
	  			this.merchantCashierShow = res.data.data.merchantCashierShow
	  		}
	  	}, fail => {
	  		console.log(fail)
	  	})
	  },
	//登录环信
	async loginWithUserId() {
	 this.loginEaseIMId =uni.getStorageSync('im_userid')
	  try {
	    const res = await loginWithPassword(
	      this.loginEaseIMId,
	      uni.getStorageSync('im_pass')
	    );
	    this.$store.commit('SET_LOGIN_USER_BASE_INFOS', {
	      loginUserId:  this.loginEaseIMId,
	    });
	    this.setEMUserLoginInfosToStorage(
	      this.loginEaseIMId.toLowerCase(),
	      res.accessToken
	    );
	  } catch (error) {
	    console.log('>>>>>>环信登录失败', error);
	    uni.showToast({
	      title: '登录失败',
	      icon: 'none',
	    });
	  } finally {
	    this.loginEaseIMId = '';
	  }
	},
	setEMUserLoginInfosToStorage(userId, token) {
	  const params = {
	    key: `EM_LOGIN_INFOS`,
	    data: { userId: userId, token: token },
	  };
	  uni.setStorage({ ...params });
	},
	gotoPage(url){
		console.log(1111);
		uni.navigateTo({
		  url: url,
		});
	},
    handleDelete(conversationItem){
      uni.showModal({
        title: '确认删除？',
        confirmText: '删除',
        success: async (res) => {
          if (res.confirm) {
            this.$store.dispatch('deleteConversation', {
              ...conversationItem,
            });
          }
        },
        fail: function (err) {
          uni.showToast({
            title: '删除失败',
            icon: 'none',
            duration: 2000,
          });
          console.log('删除失败', err);
        },
      });
    },
    setConversationListHeigth() {
      uni.getSystemInfo({
        success: (res) => {
          //顶部安全区高度
          const statusBarHeight = res.statusBarHeight;
          //底部安全区高度
          const safeAreaBottom = res.safeAreaInsets.bottom;
          console.log('safeAreaBottom', safeAreaBottom);
          this.conversationListHeight =
            res.windowHeight -
            (tabBarHeight +
              navBarHeight +
              searchInputHeight +
              statusBarHeight +
              safeAreaBottom);
        },
      });
    },
    scrolltolower() {
      console.log('>>>>>>list触底');
    },
    //群组名称
    getGroupName(groupid) {
      const joinedGroupList = this.$store.state.GroupStore.joinedGroupList;
      let groupName = '';
      if (joinedGroupList.length) {
        joinedGroupList.forEach((item) => {
          if (item.groupId == groupid) {
            return (groupName = item.groupName);
          }
        });
        return groupName;
      } else {
        return groupid;
      }
    },
    //开启搜索模式
    openSearch() {
      this.isShowDefaultSearch = false;
    },
    //取消搜索模式
    cancelSearch() {
      this.searchInputKeywords = '';
      this.searchResConversationList = [];
      this.isShowDefaultSearch = true;
    },
    //执行搜索并返回搜索结果
    actionSearch(val) {
      const sourceConversationList = [
        ...this.conversationList,
        ...this.pinConversationList,
      ];
      let keyWord = this.searchInputKeywords;
      let resConversationList = [];
      if (keyWord) {
        resConversationList = sourceConversationList.filter(
          (conversatonItem) => {
            const { conversationId, conversationType, lastMessage } =
              conversatonItem;
            if (conversationType === CHAT_TYPE.SINGLE_CHAT) {
              if (
                this.friendUserInfoCollection[conversationId] &&
                this.friendUserInfoCollection[conversationId]?.nickname
              ) {
                return (
                  lastMessage?.msg?.indexOf(keyWord) > -1 ||
                  conversationId?.indexOf(keyWord) > -1 ||
                  this.friendUserInfoCollection[
                    conversationId
                  ].nickname?.indexOf(keyWord) > -1
                );
              } else {
                return (
                  lastMessage?.msg?.indexOf(keyWord) > -1 ||
                  conversationId.indexOf(keyWord) > -1
                );
              }
            }
            if (conversationType === CHAT_TYPE.GROUP_CHAT) {
              console.log('>>>>group chat lastMessage', lastMessage);
              return (
                conversationId.indexOf(keyWord) > -1 ||
                this.getGroupName(conversationId).indexOf(keyWord) > -1 ||
                lastMessage?.msg?.indexOf(keyWord) > -1
              );
            }
          }
        );
      }
      console.log('>>>>>执行搜索', resConversationList);
      this.searchResConversationList = [...resConversationList];
    },
    //长按会话事件
    onConversationMoreFunction(conversationItem) {
      if (conversationItem) {
        const silentStatus =
          this.$store.getters.silentConversationMap[
            conversationItem?.conversationId
          ]?.type === 'NONE';
        this.longPressCheckedConversationItem = { ...conversationItem };
        this.isShowMoreFunction = true;
        //长按时选项文本调整
        this.moreFunctionList.map((item) => {
          switch (item.type) {
            case 1:
              {
                if (conversationItem.isPinned) {
                  item.name = '取消置顶';
                } else {
                  item.name = '置顶';
                }
              }
              break;
            case 2:
              {
                if (silentStatus) {
                  item.name = '取消免打扰';
                } else {
                  item.name = '免打扰';
                }
              }
              break;
            case 3: {
              if (
                conversationItem?.unReadCount > 0 ||
                !conversationItem.isRead
              ) {
                item.name = '标记已读';
              } else {
                item.name = '标记未读';
              }
            }
            default:
              break;
          }
        });
        this.isShowMoreFunction = true;
        return;
      }
      this.isShowMoreFunction = false;
    },
    onSelectClick(item) {
      switch (item.type) {
        case 0:
          this.deleteConversationItem();
          break;
        case 1:
          this.handlePinConversationItem();
          break;
        case 2:
          this.handleConversationSilent();
          break;
        case 3:
          this.handleConversationUnRead();

          break;
        default:
          break;
      }
    },
    //置顶操作
    handlePinConversationItem() {
      const conversationItem = { ...this.longPressCheckedConversationItem };
      conversationItem.isPinned = !conversationItem.isPinned;
      this.$store.dispatch('pinConversationItem', conversationItem);
    },
    //删除会话
    deleteConversationItem: function () {
      uni.showModal({
        title: '确认删除？',
        confirmText: '删除',
        success: async (res) => {
          if (res.confirm) {
            this.$store.dispatch('deleteConversation', {
              ...this.longPressCheckedConversationItem,
            });
          }
        },
        fail: function (err) {
          uni.showToast({
            title: '删除失败',
            icon: 'none',
            duration: 2000,
          });
          console.log('删除失败', err);
        },
      });
    },
    //会话免打扰操作
    handleConversationSilent() {
      const { conversationId, conversationType } =
        this.longPressCheckedConversationItem;
      const silentStatus =
        this.$store.getters.silentConversationMap[conversationId]?.type ===
        'NONE';
      const params = {
        conversationId,
        type: conversationType,
      };
      if (silentStatus) {
        this.$store.dispatch('setConversationSilentMode', {
          ...params,
        });
      } else {
        (params.options = {
          paramType: 0,
          remindType: 'NONE',
        }),
          this.$store.dispatch('setConversationSilentMode', {
            ...params,
          });
      }
    },
    /**
     * 会话已读未读状态变更
     * isRead: true表示已读，false表示未读
     * 实现原理为本地往会话数据中插入isRead字段从而标记实现手动标记会话已读状态
     * !需注意此功能为本地实现，并不记录远端会话列表接口，刷新状态重置。
     */
    handleConversationUnRead() {
      const { unReadCount } = this.longPressCheckedConversationItem;
      if (unReadCount > 0 || !this.longPressCheckedConversationItem?.isRead) {
        this.$store.dispatch('setConversationReadStatus', {
          conversationItem: this.longPressCheckedConversationItem,
          isRead: true,
        });
      } else {
        this.$store.dispatch('setConversationReadStatus', {
          conversationItem: this.longPressCheckedConversationItem,
          isRead: false,
        });
      }
    },
    //进入系统通知页面
    // entryInform() {
    //   uni.navigateTo({
    //     url: '../notification/notification',
    //   });
    // },
    //进入聊天页面
    entryChatPage: async function (conversationItem) {
	  console.log('进入聊天页面',conversationItem);
	  const { conversationId, conversationType } = conversationItem;
	  const uidsarr= JSON.parse(JSON.stringify(uni.getStorageSync('uIds')));
	  EMClient.fetchUserInfoById(uidsarr).then((resData)=>{
	  			this.chatUserList=resData.data;
				for(var key in resData.data){
					if(key==conversationId){
						uni.setStorage({
						  key: 'nowConversationIntem',
						  data: resData.data[conversationId],
						});
					}
				}
	  })
      if (conversationItem.unReadCount > 0) {
        this.$store.dispatch('sendConversatonReadedAck', {
          targetId: conversationId,
          chatType: conversationType,
        });
      }
      uni.navigateTo({
        url: `../../emChat/emChatContainer/index?targetId=${conversationId}&chatType=${conversationType}`,
      });
    },
  },
};
</script>
<style>
.but{
	width:80%;
	height:40px;
	line-height: 40px;
	text-align: center;
	border-radius: 20px;
	background-color:#007aff ;
	color:#fff;
/* 	margin:0 auto;
	margin-top: 100px; */
	position:fixed;
	bottom:100px;
	left:50%;
	margin-left:-40%;
}
.conversation_container {
  /* height: 100vh; */
  background-color: #fff;
  width: 100%;
}
.search_container {
  height: 40px;
  width: 100%;
  box-sizing: border-box;
  padding: 4px;
  background: #fff;
  margin-bottom: 5px;
}
.searching_container {
  height: 40px;
  width: 100%;
  box-sizing: border-box;
  padding: 4px;
  background: #fff;
  margin-bottom: 5px;
}

.search_icon_box {
  width: 100%;
  height: 36px;
  background: #f1f2f3;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}
.search_text {
  /* Input */

  width: 32px;
  height: 22px;

  /* 简体中文/文本/大 */
  font-family: 'PingFang SC';
  font-style: normal;
  font-weight: 400;
  font-size: 16px;
  line-height: 22px;
  /* identical to box height, or 138% */

  /* Neutral/6 */
  color: #919ba1;

  /* Inside auto layout */
  flex: none;
  order: 1;
  flex-grow: 0;
}
.pinconversation_item {
  background: #eaeaea;
}
.conversation_item_title {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
}
.conversation_item_right {
  position: relative;
}
.conversation_item_time {
  font-size: 12px;
  font-weight: 600;
}
.conversation_navbar_center {
  width: 52px;
  height: 22px;
}
</style>
