ConversationItem.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <u-swipe-action-item
  3. :index="source.conversationID"
  4. @click="clickConversationMenu($event, source)"
  5. :name="source.conversationID"
  6. :disabled="true"
  7. :options="getSwipeActions || []"
  8. @touchmove.stop>
  9. <view @tap.prevent="clickConversationItem" class="conversation_item">
  10. <view class="pinned" v-if="source.isPinned"></view>
  11. <view class="left_info">
  12. <my-avatar :isGroup="isGroup" :isNotify="isNotify" :src="source.faceURL" :desc="source.showName" size="48" >
  13. <image v-if="getRole()==1" class="taoj" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/doctor.svg"></image>
  14. <image v-if="getRole()==2" class="taoj" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/guanjia.svg"></image>
  15. </my-avatar>
  16. <view class="details">
  17. <text class="conversation_name">{{ source.showName }}</text>
  18. <view class="lastest_msg_wrap">
  19. <text v-if="messagePrefix" class="lastest_msg_prefix" :class="{ lastest_msg_prefix_active: needActivePerfix }">{{ messagePrefix }}</text>
  20. <text class="lastest_msg_content">{{ latestMessage }}</text>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="right_desc">
  25. <text class="send_time">{{ latestMessageTime }}</text>
  26. <image style="width: 16px; height: 16px" v-if="notAccept" src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/conversation_not_accept.png" />
  27. <u-badge v-else max="99" :value="source.unreadCount"></u-badge>
  28. </view>
  29. </view>
  30. </u-swipe-action-item>
  31. </template>
  32. <script>
  33. import IMSDK, { GroupAtType, MessageReceiveOptType, SessionType } from 'openim-uniapp-polyfill';
  34. import MyAvatar from './MyAvatar/index.vue';
  35. // import UParse from '@/pages_im/components/gaoyia-parse/parse.vue';
  36. import { getConversationContent, formatConversionTime, prepareConversationState, parseAt } from '@/pages_im/util/imCommon';
  37. import { formatInputHtml,isDoctorAction } from '@/pages_im/util/common';
  38. export default {
  39. components: {
  40. MyAvatar,
  41. // UParse
  42. },
  43. props: {
  44. source: {
  45. type: Object,
  46. default: () => {}
  47. }
  48. },
  49. computed: {
  50. messagePrefix() {
  51. let prefix = '';
  52. if (this.source?.recvMsgOpt !== MessageReceiveOptType.Nomal && this.source.unreadCount > 0) {
  53. prefix = `[${this.source.unreadCount}条] `;
  54. }
  55. if (this.source.groupAtType !== GroupAtType.AtNormal) {
  56. switch (this.source.groupAtType) {
  57. case GroupAtType.AtAll:
  58. prefix = '[所有人]';
  59. break;
  60. case GroupAtType.AtMe:
  61. prefix = '[有人@你]';
  62. break;
  63. case GroupAtType.AtAllAtMe:
  64. prefix = '[有人@你]';
  65. break;
  66. case GroupAtType.AtGroupNotice:
  67. prefix = '[群公告]';
  68. break;
  69. }
  70. return prefix;
  71. }
  72. if (this.source.draftText !== '') {
  73. return '[草稿]';
  74. }
  75. return prefix;
  76. },
  77. latestMessage() {
  78. if (this.source.latestMsg === '') return '';
  79. if (this.source.draftText && this.source.groupAtType === GroupAtType.AtNormal) {
  80. return parseAt(formatInputHtml(this.source.draftText), true);
  81. }
  82. let parsedMessage;
  83. try {
  84. parsedMessage = JSON.parse(this.source.latestMsg);
  85. } catch (e) {}
  86. if (!parsedMessage) return '';
  87. return getConversationContent(parsedMessage);
  88. },
  89. needActivePerfix() {
  90. return this.source.groupAtType !== GroupAtType.AtNormal || this.source.draftText;
  91. },
  92. latestMessageTime() {
  93. return this.source.latestMsgSendTime ? formatConversionTime(this.source.latestMsgSendTime) : '';
  94. },
  95. notAccept() {
  96. return this.source.recvMsgOpt !== MessageReceiveOptType.Nomal;
  97. },
  98. isGroup() {
  99. return this.source.conversationType === SessionType.WorkingGroup;
  100. },
  101. isNotify() {
  102. return this.source.conversationType === SessionType.Notification;
  103. },
  104. getSwipeActions() {
  105. let actions = [
  106. {
  107. text: `${this.source.isPinned ? '取消' : ''}置顶`,
  108. style: {
  109. backgroundColor: '#3c9cff'
  110. }
  111. },
  112. {
  113. text: '移除',
  114. style: {
  115. backgroundColor: '#FF381F'
  116. }
  117. }
  118. ];
  119. if (this.source.unreadCount > 0) {
  120. actions = [
  121. {
  122. text: '标为已读',
  123. style: {
  124. backgroundColor: '#8E9AB0'
  125. }
  126. },
  127. ...actions
  128. ];
  129. }
  130. return actions;
  131. }
  132. },
  133. data() {
  134. return {
  135. isCustom:false,
  136. };
  137. },
  138. methods: {
  139. clickConversationItem() {
  140. console.log("qxj clickConversationItem:::");
  141. console.log(this.source);
  142. let userId=this.source.userID;
  143. let isDoctor=isDoctorAction(userId);
  144. if(!isDoctor){
  145. this.$store.commit("timStore/setImType",1);
  146. }
  147. else{
  148. //this.$store.commit("timStore/setImType",1);
  149. let ex=this.source.ex;
  150. if(this.source.latestMsg!=null && this.source.latestMsg!=''){
  151. let latestMsg=JSON.parse(this.source.latestMsg);
  152. if(!!latestMsg.ex && latestMsg.ex!=''){
  153. ex=latestMsg.ex;
  154. }
  155. }
  156. if(ex!=null || ex!=''){
  157. try{
  158. var json=JSON.parse(ex);
  159. this.$store.commit("timStore/setImType", json.imType);
  160. this.$store.commit("timStore/setOrderType", json.orderType);
  161. this.$store.commit("timStore/setOrderId", json.orderId);
  162. this.$store.commit("timStore/setFollowId", json.followId);
  163. this.$store.commit("timStore/setType", json.type);
  164. }
  165. catch(e){
  166. }
  167. }
  168. }
  169. this.$store.commit("timStore/setConversationID", this.source.conversationID);
  170. prepareConversationState(this.source);
  171. },
  172. clickConversationMenu({ name, index }, item) {
  173. console.log('clickConversationMenu');
  174. const noUnRead = this.getSwipeActions.length === 2;
  175. if (index === 0 && !noUnRead) {
  176. IMSDK.asyncApi(IMSDK.IMMethods.MarkConversationMessageAsRead, IMSDK.uuid(), item.conversationID).catch(() => uni.$u.toast('操作失败'));
  177. }
  178. if ((index === 0 && noUnRead) || (index === 1 && !noUnRead)) {
  179. IMSDK.asyncApi(IMSDK.IMMethods.PinConversation, IMSDK.uuid(), {
  180. conversationID: item.conversationID,
  181. isPinned: !item.isPinned
  182. }).catch(() => uni.$u.toast('置顶失败'));
  183. }
  184. if (index === 2 || (noUnRead && index === 1)) {
  185. console.log("qxj conversationID:"+item.conversationID);
  186. let that=this;
  187. IMSDK.asyncApi(IMSDK.IMMethods.DeleteConversationAndDeleteAllMsg,IMSDK.uuid(),item.conversationID)
  188. .then(() => {
  189. console.log("移除成功!!!");
  190. that.$store.dispatch('conversation/delConversationByCID', item.conversationID)
  191. }).catch(({ errCode, errMsg }) => { // 调用失败
  192. console.log("errMsg:",errCode);
  193. uni.$u.toast('移除失败');
  194. });
  195. }
  196. //this.$emit('closeAllSwipe');
  197. },
  198. getRole(){
  199. let userType=0;
  200. let userId=this.source.userID;
  201. if(userId!=undefined && (userId!="" || userId.length>0)){
  202. if(userId.indexOf('U')!==-1){
  203. userType=0;
  204. }
  205. if(userId.indexOf('D')!==-1){
  206. userType=1;
  207. }
  208. if(userId.indexOf('C')!==-1){
  209. userType=2;
  210. }
  211. }
  212. return userType;
  213. }
  214. }
  215. };
  216. </script>
  217. <style lang="scss" scoped>
  218. .conversation_item {
  219. @include btwBox();
  220. flex-direction: row;
  221. margin:0rpx 24rpx 0;
  222. padding: 20rpx 24rpx 22rpx;
  223. position: relative;
  224. border-radius: 16rpx;
  225. background: #fff;
  226. &::after {
  227. content: "";
  228. position: absolute;
  229. bottom: 0;
  230. left: 0;
  231. border-bottom: 1px solid #ECECEC;
  232. width: 100%;
  233. transform: scaleY(0.5);
  234. border-top-color: #ECECEC;
  235. border-right-color: #ECECEC;
  236. border-left-color: #ECECEC;
  237. }
  238. &_active {
  239. background-color: #f3f3f3;
  240. }
  241. .left_info {
  242. @include btwBox();
  243. .details {
  244. @include colBox(false);
  245. margin-left: 24rpx;
  246. height: 64px;
  247. color: $uni-text-color;
  248. justify-content: space-around;
  249. .conversation_name {
  250. @include nomalEllipsis();
  251. max-width: 40vw;
  252. font-size: 36rpx;
  253. }
  254. .lastest_msg_wrap {
  255. display: flex;
  256. font-size: 30rpx;
  257. margin-top: 10rpx;
  258. color: #666;
  259. .lastest_msg_prefix {
  260. margin-right: 6rpx;
  261. &_active {
  262. color: $u-primary;
  263. }
  264. }
  265. .lastest_msg_content {
  266. flex: 1;
  267. max-width: 75vw;
  268. // margin-right: 160rpx;
  269. // /deep/uni-view {
  270. @include ellipsisWithLine(1);
  271. // }
  272. }
  273. }
  274. }
  275. }
  276. .right_desc {
  277. @include colBox(true);
  278. align-items: flex-end;
  279. width: max-content;
  280. justify-content: space-between;
  281. height: 46px;
  282. .send_time {
  283. width: max-content;
  284. font-size: 28rpx;
  285. color: #999;
  286. }
  287. .u-badge {
  288. width: fit-content;
  289. }
  290. }
  291. .pinned {
  292. position: absolute;
  293. top: 0;
  294. right: 24rpx;
  295. width: 17rpx;
  296. height: 17rpx;
  297. background-image: linear-gradient(to bottom left, #314ffe 50%, white 50%);
  298. }
  299. .taoj{
  300. position: absolute;
  301. left: -1px;
  302. top: -1px;
  303. width: 50px;
  304. height: 50px;
  305. }
  306. }
  307. </style>