inquiry.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <template>
  2. <view class="">
  3. <view class="navBox">
  4. <view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
  5. <view class="nav">
  6. <view class="navLeft" >
  7. <!-- <image src="../static/img/nav_icon_back.png" mode="aspectFit" class="backImg" @click="goback"></image> -->
  8. </view>
  9. <view class="title">询价信息</view>
  10. <view class="goVin" @click="vinScanFn">车架号查询</view>
  11. </view>
  12. </view>
  13. <view class="status_bar" :style="{height: iStatusBarHeight + 'px'}"></view>
  14. <view style="height: 44px;"></view>
  15. <scroll-view class="conversations" scroll-y="true">
  16. <!-- <view @click="setClipboardData">token:{{token}}</view> -->
  17. <view>
  18. <!-- <video src="https://66-goesay.oss-accelerate.aliyuncs.com/goeasy-im-dmsIMTest/3369051043664274_uni-video.mp4" id="videoPlayer"
  19. ></video> -->
  20. </view>
  21. <view v-if="conversations.length > 0">
  22. <view class="scroll-item" v-for="(conversation, key) in conversations" :key="key">
  23. <view class="item-head">
  24. <!-- <image :src="conversation.data.avatar" class="head-icon"></image> -->
  25. <image src="/static/img/pic_def_ava@2x.png" class="head-icon"></image>
  26. <view class="item-head_unread" v-if="conversation.unread">{{ conversation.unread }}</view>
  27. </view>
  28. <view class="scroll-item_info" @click="chat(conversation)">
  29. <view class="item-info-top">
  30. <text class="item-info-top_name">{{ conversation.data.name }}</text>
  31. <view class="item-info-top_time">{{ formatDate(conversation.lastMessage.timestamp) }}</view>
  32. </view>
  33. <view class="item-info-bottom">
  34. <view class="item-info-bottom-item">
  35. <view class="item-info-top_content" v-if="!conversation.lastMessage.recalled">
  36. <text class="unread-text">
  37. {{ conversation.lastMessage.read === false && conversation.lastMessage.senderId === currentUser.id ? '[未读]' : '' }}
  38. </text>
  39. <text v-if="conversation.lastMessage.senderId === currentUser.id">我: </text>
  40. <text v-else>{{ conversation.type === 'group' ? conversation.lastMessage.senderData.name : conversation.data.name }}: </text>
  41. <text v-if="conversation.lastMessage.type === 'text'">{{ conversation.lastMessage.payload.text }}</text>
  42. <text v-else-if="conversation.lastMessage.type === 'video'">[视频消息]</text>
  43. <text v-else-if="conversation.lastMessage.type === 'audio'">[语音消息]</text>
  44. <text v-else-if="conversation.lastMessage.type === 'image'">[图片消息]</text>
  45. <text v-else-if="conversation.lastMessage.type === 'file'">[文件消息]</text>
  46. <text v-else-if="conversation.lastMessage.type === 'order'">[自定义消息:订单]</text>
  47. <text v-else-if="conversation.lastMessage.type === 'pic'">[图片消息]</text>
  48. <text v-else-if="conversation.lastMessage.type === 'car'">[车辆信息]</text>
  49. <text v-else>[[未识别内容]]</text>
  50. </view>
  51. <view class="item-info-top_content" v-else>
  52. <text>
  53. {{conversation.lastMessage.recaller.id === currentUser.id ? '你' : conversation.lastMessage.recaller.data.name}}撤回了一条消息
  54. </text>
  55. </view>
  56. <view class="item-info-bottom_action" @click.stop="showAction(conversation)"></view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. <view class="no-conversation" v-else>当前没有会话</view>
  63. <view class="action-container" v-if="actionPopup.visible">
  64. <view class="layer" @click="actionPopup.visible = false"></view>
  65. <view class="action-box">
  66. <view class="action-item" @click="topConversation">
  67. {{ actionPopup.conversation.top ? '取消置顶' : '置顶聊天' }}
  68. </view>
  69. <view class="action-item" @click="deleteConversation">删除聊天</view>
  70. </view>
  71. </view>
  72. </scroll-view>
  73. </view>
  74. </template>
  75. <script>
  76. import {formatDate} from '../lib/utils';
  77. import restApi from '../lib/restapi';
  78. const GoEasy = uni.$GoEasy;
  79. const GRTC = uni.$GRTC;
  80. export default {
  81. name: 'conversation',
  82. data() {
  83. return {
  84. conversations: [],
  85. actionPopup: {
  86. conversation: null,
  87. visible: false
  88. },
  89. currentUser: null,
  90. iStatusBarHeight:'',
  91. token:'',
  92. }
  93. },
  94. onLoad(opt) {
  95. this.token=opt.token
  96. uni.setStorageSync('token', this.token);
  97. this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  98. this.imLoginUrl()
  99. },
  100. onShow() {
  101. if(this.token){
  102. this.imLoginUrl()
  103. }
  104. /* uni.$currentUser = uni.getStorageSync('currentUser');
  105. this.currentUser = uni.$currentUser;
  106. console.log(this.currentUser)
  107. if (!this.currentUser) {
  108. uni.navigateTo({ url: './login' });
  109. return;
  110. }
  111. if (GoEasy.getConnectionStatus() === 'disconnected') {
  112. this.connectGoEasy(); //连接goeasy
  113. this.subscribeGroup(); //建立连接后,就应该订阅群聊消息,避免漏掉
  114. }
  115. this.loadConversations(); //加载会话列表
  116. this.initGoEasyListeners(); */
  117. },
  118. onHide() {
  119. if (GoEasy.getConnectionStatus() === 'disconnected') {
  120. return
  121. }
  122. GoEasy.im.off(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, this.renderConversations);
  123. },
  124. methods: {
  125. formatDate,
  126. connectGoEasy() {
  127. uni.showLoading();
  128. GoEasy.connect({
  129. id: this.currentUser.id,
  130. data: {
  131. name: this.currentUser.name,
  132. avatar: this.currentUser.avatar
  133. },
  134. onSuccess: () => {
  135. console.log('GoEasy connect successfully.')
  136. },
  137. onFailed: (error) => {
  138. uni.hideLoading();
  139. this.imLoginUrl()
  140. console.log('Failed to connect GoEasy, code:' + error.code + ',error:' + error.content);
  141. },
  142. onProgress: (attempts) => {
  143. uni.hideLoading();
  144. console.log('GoEasy is connecting', attempts);
  145. }
  146. });
  147. },
  148. setClipboardData(){
  149. uni.setClipboardData({
  150. data: this.token,
  151. success: () => {
  152. uni.showToast({
  153. title: '复制成功'
  154. });
  155. }
  156. });
  157. },
  158. chooseImage(){
  159. uni.chooseImage({
  160. count: 6, //默认9
  161. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  162. sourceType: ['album'], //从相册选择
  163. success: function (res) {
  164. console.log(JSON.stringify(res.tempFilePaths));
  165. },
  166. fail(err) {
  167. }
  168. });
  169. },
  170. imLoginUrl(){
  171. this.$http('imSys/imLoginUrl', {
  172. token:this.token,
  173. },'POST').then(res => {
  174. //console.log(res)
  175. if(res.code!=0){
  176. uni.showModal({
  177. title: '提示',
  178. content: res.msg,
  179. showCancel:false,
  180. success: function (res) {
  181. if (res.confirm) {
  182. console.log('用户点击确定');
  183. } else if (res.cancel) {
  184. console.log('用户点击取消');
  185. }
  186. }
  187. });
  188. return false
  189. }
  190. var users={
  191. userId:res.data.userId,
  192. name:res.data.users.name,
  193. avatar:'',
  194. id:res.data.userId,
  195. }
  196. this.currentUser=users
  197. // this.connectGoEasy()
  198. uni.setStorageSync('users', users);
  199. uni.setStorageSync('currentUser', users);
  200. console.log(this.currentUser)
  201. if (!this.currentUser) {
  202. uni.navigateTo({ url: './login' });
  203. return;
  204. }
  205. if (GoEasy.getConnectionStatus() === 'disconnected') {
  206. this.connectGoEasy(); //连接goeasy
  207. this.subscribeGroup(); //建立连接后,就应该订阅群聊消息,避免漏掉
  208. }
  209. this.loadConversations(); //加载会话列表
  210. this.initGoEasyListeners();
  211. })
  212. },
  213. goBack(){
  214. //app交互
  215. var standalone = window.navigator.standalone
  216. var userAgent = window.navigator.userAgent.toLowerCase()
  217. var safari = /safari/.test(userAgent)
  218. var ios = /iphone|ipod|ipad|mac/.test(userAgent)
  219. var android = /android/.test(userAgent)
  220. if (ios) {
  221. if ( true) {//!standalone&& !safari
  222. window.webkit.messageHandlers.goMyNav.postMessage(null)
  223. }
  224. } else if (android) {
  225. window.android.postMessage()
  226. }
  227. },
  228. vinScanFn(){
  229. //app交互
  230. var standalone = window.navigator.standalone
  231. var userAgent = window.navigator.userAgent.toLowerCase()
  232. var safari = /safari/.test(userAgent)
  233. var ios = /iphone|ipod|ipad|mac/.test(userAgent)
  234. var android = /android/.test(userAgent)
  235. if (ios) {
  236. if ( true) {//!standalone&& !safari
  237. window.webkit.messageHandlers.vinScan.postMessage(null)
  238. }
  239. } else if (android) {
  240. window.android.vinScan()
  241. }
  242. },
  243. initGoEasyListeners() {
  244. GoEasy.im.on(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, this.renderConversations); //监听会话列表变化
  245. GoEasy.im.off(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, this.setUnreadAmount); // 移除之前的设置角标回调,防止重复回调
  246. GoEasy.im.on(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, this.setUnreadAmount); // 设置角标
  247. // #ifdef APP-PLUS || H5
  248. GRTC.off(GRTC.EVENT.RING, this.onRing); //移除之前的监听来电事件,防止重复回调
  249. GRTC.on(GRTC.EVENT.RING, this.onRing); //监听来电事件
  250. // #endif
  251. },
  252. onRing() {
  253. const currentCall = GRTC.currentCall();
  254. if (currentCall.groupId) {
  255. uni.navigateTo({
  256. url: `./rtc/group/ring`,
  257. })
  258. } else {
  259. uni.navigateTo({
  260. url: `./rtc/private/ring`,
  261. })
  262. }
  263. },
  264. // 加载最新的会话列表
  265. loadConversations() {
  266. GoEasy.im.latestConversations({
  267. onSuccess: (result) => {
  268. uni.hideLoading();
  269. let content = result.content;
  270. this.renderConversations(content);
  271. this.setUnreadAmount(content);
  272. },
  273. onFailed: (error) => {
  274. uni.hideLoading();
  275. console.log('获取最新会话列表失败, error:', error);
  276. }
  277. });
  278. },
  279. renderConversations(content) {
  280. this.conversations = content.conversations;
  281. console.log("消息列表")
  282. console.log(this.conversations)
  283. },
  284. setUnreadAmount(content) {
  285. const unreadTotal = content.unreadTotal;
  286. if(unreadTotal > 0) {
  287. uni.setTabBarBadge({
  288. index: 0,
  289. text: unreadTotal.toString()
  290. });
  291. }else{
  292. uni.removeTabBarBadge({index: 0});
  293. }
  294. // #ifdef APP-PLUS
  295. GoEasy.setBadge({
  296. badge: unreadTotal,
  297. onSuccess: function () {
  298. console.log("setBadge successfully.")
  299. },
  300. onFailed: function (error) {
  301. console.log("Failed to setBadge,error:" + error);
  302. }
  303. });
  304. // #endif
  305. },
  306. subscribeGroup() {
  307. let groups = restApi.findGroups(this.currentUser);
  308. let groupIds = groups.map(item => item.id);
  309. GoEasy.im.subscribeGroup({
  310. groupIds: groupIds,
  311. onSuccess: function () {
  312. console.log('订阅群消息成功');
  313. },
  314. onFailed: function (error) {
  315. console.log('订阅群消息失败:', error);
  316. }
  317. });
  318. },
  319. topConversation() { //会话置顶
  320. this.actionPopup.visible = false;
  321. let conversation = this.actionPopup.conversation;
  322. let description = conversation.top ? '取消置顶' : '置顶';
  323. GoEasy.im.topConversation({
  324. conversation: conversation,
  325. top: !conversation.top,
  326. onSuccess: function () {
  327. uni.showToast({
  328. title: description + '成功',
  329. icon: 'none'
  330. });
  331. },
  332. onFailed: function (error) {
  333. console.log(description, '失败:', error);
  334. }
  335. });
  336. },
  337. deleteConversation() {
  338. uni.showModal({
  339. content: '确认删除这条会话吗?',
  340. success: (res) => {
  341. if (res.confirm) {
  342. let conversation = this.actionPopup.conversation;
  343. this.actionPopup.visible = false;
  344. GoEasy.im.removeConversation({
  345. conversation: conversation,
  346. onSuccess: function () {
  347. console.log('删除会话成功');
  348. },
  349. onFailed: function (error) {
  350. console.log(error);
  351. },
  352. });
  353. } else {
  354. this.actionPopup.visible = false;
  355. }
  356. },
  357. })
  358. },
  359. chat(conversation) {
  360. console.log(conversation)
  361. var url='http://goeasytest.66km.com.cn/#/pages/privateChatWeb?to=' + conversation.userId+"&token="+this.token+'&supplierName='+conversation.data.name
  362. var standalone = window.navigator.standalone
  363. var userAgent = window.navigator.userAgent.toLowerCase()
  364. var safari = /safari/.test(userAgent)
  365. var ios = /iphone|ipod|ipad|mac/.test(userAgent)
  366. var android = /android/.test(userAgent)
  367. if (ios) {
  368. if ( true) {//!standalone&& !safari
  369. window.webkit.messageHandlers.privateChatWeb.postMessage(url)
  370. }
  371. } else if (android) {
  372. window.android.privateChatWeb(url)
  373. }
  374. return false
  375. let path = conversation.type === GoEasy.IM_SCENE.PRIVATE ?
  376. './privateChatWeb?to=' + conversation.userId+'&supplierName='+conversation.data.name+"&token="+this.token:
  377. './groupChat?to=' + conversation.groupId;
  378. var friend={
  379. id:conversation.userId,
  380. supplierName:conversation.data.name,
  381. avatar:conversation.data.avatar,
  382. }
  383. uni.setStorage({
  384. key: 'friend',
  385. data: friend,
  386. success: function () {
  387. /* uni.navigateTo({
  388. url: './privateChat?to=' + friend.ID
  389. }); */
  390. uni.navigateTo({ url: path });
  391. }
  392. });
  393. },
  394. showAction(conversation) {
  395. this.actionPopup.conversation = conversation;
  396. this.actionPopup.visible = true;
  397. }
  398. }
  399. }
  400. </script>
  401. <style>
  402. page {
  403. height: 100%;
  404. }
  405. .conversations {
  406. width: 750rpx;
  407. overflow-x: hidden;
  408. display: flex;
  409. flex-direction: column;
  410. height: 100%;
  411. }
  412. .conversations .scroll-item {
  413. height: 152rpx;
  414. display: flex;
  415. align-items: center;
  416. padding-left: 32rpx;
  417. }
  418. .conversations .scroll-item .head-icon {
  419. width: 100rpx;
  420. height: 100rpx;
  421. margin-right: 28rpx;
  422. }
  423. .conversations .scroll-item_info {
  424. height: 151rpx;
  425. width: 590rpx;
  426. padding-right: 32rpx;
  427. border-bottom: 1px solid #EFEFEF;
  428. }
  429. .conversations .scroll-item_info .item-info-top {
  430. padding-top: 20rpx;
  431. height: 60rpx;
  432. line-height: 60rpx;
  433. display: flex;
  434. align-items: center;
  435. justify-content: space-between;
  436. }
  437. .conversations .item-info-top_name {
  438. font-size: 30rpx;
  439. color: #262628;
  440. white-space: nowrap;
  441. overflow: hidden;
  442. text-overflow: ellipsis;
  443. width: 370rpx;
  444. }
  445. .conversations .item-info-top_time {
  446. font-size: 34rpx;
  447. color: rgba(179, 179, 179, 0.8);
  448. }
  449. .conversations .item-info-bottom {
  450. height: 40rpx;
  451. line-height: 40rpx;
  452. overflow: hidden;
  453. }
  454. .conversations .item-info-bottom-item {
  455. display: flex;
  456. justify-content: space-between;
  457. }
  458. .item-info-bottom .item-info-top_content {
  459. font-size: 34rpx;
  460. color: #b3b3b3;
  461. overflow: hidden;
  462. text-overflow: ellipsis;
  463. white-space: nowrap;
  464. }
  465. .item-info-bottom .item-info-bottom_action {
  466. width: 50rpx;
  467. height: 50rpx;
  468. font-size: 34rpx;
  469. background: url("../static/images/action.png") no-repeat center;
  470. background-size: 28rpx 30rpx;
  471. }
  472. .no-conversation {
  473. width: 100%;
  474. text-align: center;
  475. height: 80rpx;
  476. line-height: 80rpx;
  477. font-size: 34rpx;
  478. color: #9D9D9D;
  479. }
  480. .item-head {
  481. position: relative;
  482. }
  483. .item-head .item-head_unread {
  484. padding: 6rpx;
  485. background-color: #EE593C;
  486. color: #FFFFFF;
  487. font-size: 34rpx;
  488. line-height: 28rpx;
  489. border-radius: 24rpx;
  490. min-width: 24rpx;
  491. min-height: 24rpx;
  492. text-align: center;
  493. position: absolute;
  494. top: 0;
  495. right: 15rpx;
  496. }
  497. .action-container {
  498. width: 100%;
  499. height: 100%;
  500. position: fixed;
  501. top: 0;
  502. left: 0;
  503. display: flex;
  504. justify-content: center;
  505. align-items: center;
  506. }
  507. .action-container .layer {
  508. position: absolute;
  509. top: 0;
  510. left: 0;
  511. background: rgba(51, 51, 51, 0.5);
  512. width: 100%;
  513. height: 100%;
  514. z-index: 99;
  515. }
  516. .action-box {
  517. width: 400rpx;
  518. height: 240rpx;
  519. background: #ffffff;
  520. position: relative;
  521. z-index: 100;
  522. border-radius: 20rpx;
  523. overflow: hidden;
  524. }
  525. .action-item {
  526. text-align: center;
  527. line-height: 120rpx;
  528. font-size: 34rpx;
  529. color: #262628;
  530. border-bottom: 1px solid #EFEFEF;
  531. }
  532. .unread-text {
  533. color: #d02129;
  534. }
  535. .backImg{
  536. width: 44rpx;
  537. height: 44rpx;
  538. /* margin-left: 10rpx; */
  539. /* margin-right: 20rpx; */
  540. }
  541. .nav{
  542. height: 44px;
  543. display: flex;
  544. justify-content: space-between;
  545. align-items: center;
  546. border-bottom: 1px solid #eaeaea;
  547. }
  548. .goVin{
  549. width: 200rpx;
  550. color: #3F90F7;
  551. text-align: right;
  552. padding-right: 20rpx;
  553. }
  554. .navLeft{
  555. width: 200rpx;
  556. padding-left: 20rpx;
  557. }
  558. .navBox{
  559. position: fixed;
  560. left: 0;
  561. top: 0;
  562. z-index: 11;
  563. width: 100vw;
  564. }
  565. </style>