merChantSideIndex.vue 5.8 KB

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