inquiry.vue 20 KB

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