contacts.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <view class="contacts_container">
  3. <!-- navbar -->
  4. <!-- #ifdef H5 || APP-PLUS -->
  5. <u-navbar title="联系人" :placeholder="true">
  6. <u-avatar size="32" slot="left" shape="square" :src="loginUserAvatar">
  7. </u-avatar>
  8. <view slot="center">
  9. <image class="contacts_navbar_center" src="/static/images/new_ui/contacts_log.png" />
  10. </view>
  11. <u-icon slot="right" size="24" name="/static/images/new_ui/contacts/add_contacts.png"
  12. @click="entryAddContactsPage"></u-icon>
  13. </u-navbar>
  14. <!-- #endif -->
  15. <!-- #ifndef H5 || APP-PLUS-->
  16. <u-navbar title="联系人" :placeholder="true">
  17. <view class="u-nav-slot" slot="left">
  18. <u-avatar size="32" shape="square" :src="loginUserAvatar"> </u-avatar>
  19. <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
  20. <u-icon size="24" name="/static/images/new_ui/contacts/add_contacts.png"
  21. @click="entryAddContactsPage"></u-icon>
  22. </view>
  23. <view slot="center">
  24. <image class="contacts_navbar_center" src="/static/images/new_ui/contacts_log.png" />
  25. </view>
  26. </u-navbar>
  27. <!-- #endif -->
  28. <!-- search -->
  29. <!-- 搜索好友列表相关 -->
  30. <view>
  31. <view class="search_container" v-if="isShowDefaultSearch">
  32. <view class="search_icon_box" @click="openSearch">
  33. <u-icon size="22" name="/static/images/new_ui/search_icon.png"></u-icon>
  34. <text class="search_text">搜索</text>
  35. </view>
  36. </view>
  37. <!-- 好友搜索结果展示 -->
  38. <view class="searching_container" v-if="!isShowDefaultSearch">
  39. <u-search v-model.trim="searchInputKeywords" shape="square" placeholder="搜索联系人" :actionText="'取消'"
  40. :actionStyle="{
  41. color: '#0873de',
  42. }" :clearabled="true" :focus="true" @search="onSearchContacts" @input="onSearchContacts"
  43. @custom="cancelSearch"></u-search>
  44. </view>
  45. </view>
  46. <!-- 搜索结果list -->
  47. <template v-if="!isShowDefaultSearch">
  48. <u-index-list class="index_list_container" :index-list="indexList" @select="onSelectIndex"
  49. activeColor="#009EFF" customNavHeight="90">
  50. <template v-for="(item, index) in searchFriendResultList">
  51. <u-index-item>
  52. <u-index-anchor :text="indexList[index]" bgColor="#FFF" color="#75828A"
  53. height="32px"></u-index-anchor>
  54. <u-cell class="contacts_item_cell" v-for="(cell, index1) in item"
  55. :key="cell.initial + cell.userId" :border="false">
  56. <!-- 头像 -->
  57. <u-avatar slot="icon" shape="square" size="40" :src="showFriendAvatar(cell.userId)"
  58. customStyle="margin: -3px 5px -3px 0"></u-avatar>
  59. <!-- name -->
  60. <view class="conversation_item_title" slot="title">
  61. <u--text class="conversation_item_title_text" :lines="1"
  62. :text="showFriendNickname(cell)" iconStyle="margin-left: 2px;">
  63. </u--text>
  64. </view>
  65. </u-cell>
  66. </u-index-item>
  67. </template>
  68. </u-index-list>
  69. </template>
  70. <!-- 默认好友列表list -->
  71. <template v-else>
  72. <u-index-list :index-list="indexList" @select="onSelectIndex" activeColor="#009EFF" customNavHeight="90">
  73. <!-- Contacts -->
  74. <view slot="header" class="contacts_header_container">
  75. <u-cell-group :border="false">
  76. <u-cell :clickable="true" :isLink="true" @click="entryNewInvitePage">
  77. <text slot="title" class="header_title">新邀请</text>
  78. <u-badge slot="value" type="primary" max="99" :value="newInviteMsgNum"></u-badge>
  79. </u-cell>
  80. <u-cell :clickable="true" :isLink="true" @click="entryGroupListPage">
  81. <text slot="title" class="header_title">群聊</text>
  82. <text slot="value">{{ joinedGroupTotal }}</text>
  83. </u-cell>
  84. <u-cell :clickable="true" :isLink="true" @click="entryBlockMembersPage">
  85. <text slot="title" class="header_title">黑名单</text>
  86. <text slot="value">{{ blockUserList.length }}</text>
  87. </u-cell>
  88. </u-cell-group>
  89. </view>
  90. <template>
  91. <u-index-item v-for="(item, index) in sortedContactsList" :key="index">
  92. <u-index-anchor :text="indexList[index]" bgColor="#FFF" color="#75828A"
  93. height="32px"></u-index-anchor>
  94. <u-cell class="contacts_item_cell" v-for="(cell, index1) in item" :key="cell.userId"
  95. :border="false" @click="entryContactsDetailPage(cell.userId)">
  96. <!-- 头像 -->
  97. <u-avatar slot="icon" shape="square" size="40" :src="showFriendAvatar(cell.userId)"
  98. customStyle="margin: -3px 5px -3px 0"></u-avatar>
  99. <!-- name -->
  100. <view class="conversation_item_title" slot="title">
  101. <u--text class="conversation_item_title_text" :lines="1"
  102. :text="showFriendNickname(cell)" iconStyle="margin-left: 2px;">
  103. </u--text>
  104. </view>
  105. </u-cell>
  106. </u-index-item>
  107. </template>
  108. <view slot="footer" class="u-safe-area-inset--bottom">
  109. <text class="list__footer"></text>
  110. <u-divider :text="`${friendList.length}个联系人`" :hairline="true"></u-divider>
  111. </view>
  112. </u-index-list>
  113. </template>
  114. <view class="but" @click="gotoPage('/pages/storemanagement/index')">
  115. 查看会话列表
  116. </view>
  117. </view>
  118. </template>
  119. <script>
  120. import { CHAT_TYPE } from "@/EaseIM/constant";
  121. const indexList = () => {
  122. const indexList = [];
  123. const charCodeOfA = "A".charCodeAt(0);
  124. for (let i = 0; i < 26; i++) {
  125. indexList.push(String.fromCharCode(charCodeOfA + i));
  126. }
  127. indexList.push("#");
  128. return indexList;
  129. };
  130. export default {
  131. data() {
  132. return {
  133. isShowDefaultSearch: true,
  134. searchInputKeywords: "",
  135. searchFriendResultList: [],
  136. defaultAvatar: "/static/images/new_ui/defaultAvatar.png",
  137. indexList: [],
  138. // indexList: indexList(),
  139. sortedContactsList: [],
  140. };
  141. },
  142. mounted() {
  143. uni.hideHomeButton && uni.hideHomeButton();
  144. this.getBrandsList(this.friendList);
  145. },
  146. computed: {
  147. loginUserProfiles() {
  148. return this.$store.state.LoginStore.loginUserProfiles;
  149. },
  150. loginUserAvatar() {
  151. if (this.loginUserProfiles.avatarurl) {
  152. return this.loginUserProfiles?.avatarurl;
  153. } else {
  154. return this.defaultAvatar;
  155. }
  156. },
  157. //好友列表
  158. friendList() {
  159. return this.$store.state.ContactsStore.friendList;
  160. },
  161. friendUserInfoCollection() {
  162. return this.$store.getters.friendUserInfoCollection;
  163. },
  164. blockUserList() {
  165. return this.$store.state.ContactsStore.blockUserList;
  166. },
  167. newInviteMsgNum() {
  168. return (
  169. this.$store.getters.getReceiveInviteList?.length &&
  170. this.$store.getters.getReceiveInviteList.filter(
  171. (inform) => !inform.isHandled
  172. ).length
  173. );
  174. },
  175. //群组总数
  176. joinedGroupTotal() {
  177. return this.$store.getters.joinedGroupTotal;
  178. },
  179. //好友头像展示
  180. showFriendAvatar() {
  181. return (hxId) => {
  182. if (
  183. this.friendUserInfoCollection[hxId] &&
  184. this.friendUserInfoCollection[hxId]?.avatarurl
  185. ) {
  186. return this.friendUserInfoCollection[hxId].avatarurl;
  187. } else {
  188. return this.defaultAvatar;
  189. }
  190. };
  191. },
  192. //好友昵称展示
  193. showFriendNickname() {
  194. return (userItem) => {
  195. const { userId, remark } = userItem;
  196. if (remark) {
  197. return remark;
  198. }
  199. if (
  200. this.friendUserInfoCollection[userId] &&
  201. this.friendUserInfoCollection[userId]?.nickname
  202. ) {
  203. return this.friendUserInfoCollection[userId].nickname;
  204. } else {
  205. return userId;
  206. }
  207. };
  208. },
  209. },
  210. watch: {
  211. friendList() {
  212. this.getBrandsList(this.friendList);
  213. },
  214. },
  215. methods: {
  216. gotoPage(url){
  217. // uni.navigateTo({
  218. // url: url,
  219. // });
  220. uni.switchTab({
  221. url:url
  222. })
  223. },
  224. //开启搜索模式
  225. openSearch() {
  226. this.isShowDefaultSearch = false;
  227. },
  228. cancelSearch() {
  229. this.isShowDefaultSearch = true;
  230. this.searchInputKeywords = "";
  231. this.searchFriendResultList = [];
  232. this.getBrandsList(this.friendList);
  233. },
  234. onSearchContacts() {
  235. let searchValue = this.searchInputKeywords;
  236. let member = this.friendList;
  237. let serchList = [];
  238. member.forEach((friendItem) => {
  239. if (String(friendItem.userId).indexOf(searchValue) > -1) {
  240. serchList.push(friendItem);
  241. } else if (
  242. this.friendUserInfoCollection[friendItem.userId] &&
  243. this.friendUserInfoCollection[friendItem.userId]?.nickname
  244. ) {
  245. if (
  246. this.friendUserInfoCollection[friendItem.userId].nickname.indexOf(
  247. searchValue
  248. ) > -1
  249. ) {
  250. serchList.push(friendItem);
  251. }
  252. }
  253. });
  254. this.getBrandsList(serchList, "search");
  255. },
  256. //删除好友
  257. //二次确认&执行删除
  258. async deleteFriend(event) {
  259. console.log(">>>>执行删除好友", event);
  260. const { name: delFriendId } = event;
  261. const res = await uni.showModal({
  262. title: "确认删除?+ delFriendId",
  263. confirmText: "删除",
  264. });
  265. if (res.confirm) {
  266. removeContactFromServer(delFriendId);
  267. updateFriendList();
  268. }
  269. },
  270. //前往系统通知页面
  271. entryTabNnotificationPage: function () {
  272. uni.navigateTo({
  273. url: "../notification/notification",
  274. });
  275. },
  276. //前往群组页面
  277. entryGroupsPage: function () {
  278. uni.navigateTo({
  279. url: "../groups/groups?myName=" + this.myName,
  280. });
  281. },
  282. //前往单聊页面
  283. entryemChat: function (params) {
  284. const chatType = CHAT_TYPE.SINGLE_CHAT;
  285. uni.navigateTo({
  286. url: `../emChatContainer/index?targetId=${params.name}&chatType=${chatType}`,
  287. });
  288. },
  289. //前往添加好友页面
  290. entryAddNewFreiend: function (event) {
  291. uni.navigateTo({
  292. url: "../addNewFriend/addNewFriend",
  293. });
  294. },
  295. //构建indexList
  296. //type为构建indexList init search
  297. getBrandsList(friendsList, type) {
  298. const reg = /[a-z]/i;
  299. let contactsObj = {};
  300. let indexList = [];
  301. friendsList.length &&
  302. friendsList.forEach((friendItem) => {
  303. const { userId, remark } = friendItem;
  304. const params = {};
  305. params.userId = userId;
  306. params.remark = remark;
  307. console.log("friendItem", friendItem);
  308. if (reg.test(userId.substring(0, 1))) {
  309. const initial = userId.substring(0, 1).toUpperCase();
  310. if (!contactsObj[initial]) {
  311. contactsObj[initial] = [];
  312. }
  313. params.initial = initial;
  314. contactsObj[initial].push(params);
  315. indexList.push(userId.substring(0, 1).toUpperCase());
  316. } else {
  317. const initial = "#";
  318. params.initial = initial;
  319. if (!contactsObj[initial]) {
  320. contactsObj[initial] = [];
  321. }
  322. contactsObj[initial].push({ ...params });
  323. indexList.push("#");
  324. }
  325. });
  326. if (type === "search") {
  327. this.searchFriendResultList = Object.values(contactsObj);
  328. } else {
  329. this.sortedContactsList = Object.values(contactsObj);
  330. }
  331. this.indexList = [...new Set(indexList)];
  332. console.log("contactsList", Object.values(contactsObj));
  333. },
  334. onSelectIndex(value) {
  335. console.log(">>>>>>>", value);
  336. },
  337. //前往添加联系人页面
  338. entryAddContactsPage() {
  339. uni.navigateTo({
  340. url: "../addContacts/index",
  341. });
  342. },
  343. //前往新邀请页面
  344. entryNewInvitePage() {
  345. uni.navigateTo({
  346. url: "../newInvite/index",
  347. });
  348. },
  349. //前往群组列表页面
  350. entryGroupListPage() {
  351. uni.navigateTo({
  352. url: "../groupList/index",
  353. });
  354. },
  355. //前往黑名单列表页面
  356. entryBlockMembersPage() {
  357. uni.navigateTo({
  358. url: "../blockMembers/index",
  359. });
  360. },
  361. //前往联系人详情页面
  362. entryContactsDetailPage(userId) {
  363. uni.navigateTo({
  364. url: `../contactsDetail/index?userId=${userId}`,
  365. });
  366. },
  367. },
  368. };
  369. </script>
  370. <style>
  371. @import "./contacts.css";
  372. </style>