merChantSideIndex.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div>
  3. <div
  4. class="tui-conversation"
  5. @click="handleClickConv"
  6. @touchstart="handleTouchStart"
  7. @touchend="handleTouchEnd"
  8. >
  9. <TUISearch searchType="global" />
  10. <!-- <div class="header" @click="myGourp">我的群聊</div> -->
  11. <div class="header" @click="createGroup">创建粉丝群</div>
  12. <!-- <ConversationHeader
  13. v-if="isShowConversationHeader"
  14. ref="headerRef"
  15. /> -->
  16. <ConversationNetwork />
  17. <ConversationList
  18. ref="conversationListDomRef"
  19. class="tui-conversation-list"
  20. @handleSwitchConversation="handleSwitchConversation"
  21. @handleSwitchConversationObj="handleSwitchConversationObj"
  22. @getPassingRef="getPassingRef"
  23. />
  24. </div>
  25. <merchantTabBar :index="3"></merchantTabBar>
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import * as MesApi from "../../../api/message";
  30. import {
  31. TUIStore,
  32. StoreName,
  33. TUIConversationService,
  34. } from "@tencentcloud/chat-uikit-engine";
  35. import { TUIGlobal } from "@tencentcloud/universal-api";
  36. import { ref } from "../../adapter-vue";
  37. import TUISearch from "../TUISearch/index.vue";
  38. import ConversationList from "./conversation-list/index.vue";
  39. import ConversationHeader from "./conversation-header/index.vue";
  40. import ConversationNetwork from "./conversation-network/index.vue";
  41. import { onHide } from "@dcloudio/uni-app"; // 该方法只能用在父组件内,子组件内不生效
  42. const emits = defineEmits(["handleSwitchConversation"]);
  43. const totalUnreadCount = ref(0);
  44. const headerRef = ref<typeof ConversationHeader>();
  45. const conversationListDomRef = ref<typeof ConversationList>();
  46. const touchX = ref<number>(0);
  47. const touchY = ref<number>(0);
  48. const isShowConversationHeader = ref<boolean>(true);
  49. TUIStore.watch(StoreName.CONV, {
  50. totalUnreadCount: (count: number) => {
  51. totalUnreadCount.value = count;
  52. },
  53. });
  54. TUIStore.watch(StoreName.CUSTOM, {
  55. isShowConversationHeader: (showStatus: boolean) => {
  56. isShowConversationHeader.value = showStatus !== false;
  57. },
  58. });
  59. const handleSwitchConversation = (conversationID: string) => {
  60. TUIGlobal?.navigateTo({
  61. url: "/TUIKit-House/components/TUIChat/index",
  62. });
  63. let companyUserId =
  64. conversationID[3] === "C"
  65. ? conversationID.substring(4)
  66. : conversationID.substring(3);
  67. TUIGlobal?.navigateTo({
  68. url:
  69. "/TUIKit-House/components/TUIChat/index?shopUserId=" +
  70. uni.getStorageSync("userId") +
  71. "&recruitUserId=" +
  72. companyUserId,
  73. });
  74. emits("handleSwitchConversation", conversationID);
  75. };
  76. const closeChildren = () => {
  77. headerRef?.value?.closeChildren();
  78. conversationListDomRef?.value?.closeChildren();
  79. };
  80. const shopInfo = ref({});
  81. const myGourp = () => {
  82. TUIGlobal?.navigateTo({
  83. url: "/TUIKit-House/components/TUIContact/index",
  84. });
  85. };
  86. const createGroup = async () => {
  87. const ownerAccount = uni.getStorageSync('id');
  88. // TUIConversationService.switchConversation(
  89. // "GROUP17527216214421942041809035223041"
  90. // );
  91. let res = await MesApi.default.getInfoByUserId();
  92. if (res.code == 200) {
  93. shopInfo.value = res.data;
  94. let create = await MesApi.default.createGroup({
  95. shopId: res.data.id ,
  96. ownerAccount:ownerAccount,
  97. agentType:uni.getStorageSync('agentType')
  98. });
  99. console.log(create);
  100. if (create.code == 200) {
  101. TUIConversationService.switchConversation(
  102. `GROUP${create.data.groupId}`
  103. );
  104. uni.$u.toast(create.msg);
  105. } else {
  106. uni.$u.toast(create.msg);
  107. }
  108. }
  109. };
  110. const handleClickConv = () => {
  111. closeChildren();
  112. };
  113. onHide(closeChildren);
  114. const handleTouchStart = (e: any) => {
  115. touchX.value = e.changedTouches[0].clientX;
  116. touchY.value = e.changedTouches[0].clientY;
  117. };
  118. const handleTouchEnd = (e: any) => {
  119. const x = e.changedTouches[0].clientX;
  120. const y = e.changedTouches[0].clientY;
  121. let turn = "";
  122. if (x - touchX.value > 50 && Math.abs(y - touchY.value) < 50) {
  123. // 右滑
  124. turn = "right";
  125. } else if (x - touchX.value < -50 && Math.abs(y - touchY.value) < 50) {
  126. // 左滑
  127. turn = "left";
  128. }
  129. if (y - touchY.value > 50 && Math.abs(x - touchX.value) < 50) {
  130. // 下滑
  131. turn = "down";
  132. } else if (y - touchY.value < -50 && Math.abs(x - touchX.value) < 50) {
  133. // 上滑
  134. turn = "up";
  135. }
  136. // 根据方向进行操作
  137. if (turn === "down" || turn === "up") {
  138. closeChildren();
  139. }
  140. };
  141. const getPassingRef = (ref) => {
  142. ref.value = conversationListDomRef.value;
  143. };
  144. </script>
  145. <style lang="scss" scoped>
  146. .header {
  147. height: 25px;
  148. background: white;
  149. display: flex;
  150. flex-direction: row;
  151. align-items: center;
  152. justify-content: flex-end;
  153. padding: 0px 10px 10px 10px;
  154. }
  155. </style>
  156. <style lang="scss" scoped src="./style/index.scss"></style>