doctorOrderIM.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="container">
  3. <view class="message-list" @tap="triggerClose"><TUI-message-list id="message-list" @finish="finish" ref="messageList" :conversation="conversation" /></view>
  4. <view v-if="videoPlay" class="container-box" @tap.stop="stopVideoHander">
  5. <video
  6. v-if="videoPlay"
  7. class="video-message"
  8. :src="videoMessage.payload.videoUrl"
  9. :poster="videoMessage.payload.thumbUrl"
  10. object-fit="cover"
  11. error="videoError"
  12. autoplay="true"
  13. direction="0"
  14. />
  15. </view>
  16. <view v-if="showChat" class="message-input">
  17. <TUI-message-input id="message-input" ref="messageInput" :toUser="toUser" :conversation="conversation" @sendMessage="sendMessage" />
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {getTlsSig} from '@/api/common.js'
  23. import {getUserInfo} from '@/api/user'
  24. import {getImOrderDetail,pingOrder} from '@/api/doctorOrder.js'
  25. import TUIMessageList from '../../components/im/tui-chat/message-list/index';
  26. import TUIMessageInput from '../../components/im/tui-chat/message-input/index';
  27. export default {
  28. components: {
  29. TUIMessageList,
  30. TUIMessageInput,
  31. },
  32. data() {
  33. return {
  34. toUser:"",
  35. conversationName: '',
  36. conversation: {},
  37. messageList: [],
  38. showChat: true,
  39. conversationID: null,
  40. videoPlay: false,
  41. videoMessage: {},
  42. order:null,
  43. doctor:null,
  44. user:null,
  45. doctorId:null,
  46. orderId:null,
  47. }
  48. },
  49. created() {
  50. uni.$on('videoPlayerHandler', value => {
  51. this.videoPlay = value.isPlay;
  52. this.videoMessage = value.message;
  53. });
  54. },
  55. onLoad(option) {
  56. console.log(option.orderId)
  57. this.orderId=option.orderId;
  58. this.getImOrderDetail();
  59. },
  60. onShow() {
  61. uni.setStorageSync('orderId',this.orderId);
  62. },
  63. methods: {
  64. finish(){
  65. this.showChat=false
  66. uni.$emit('refreshDoctorOrder');
  67. },
  68. stopVideoHander() {
  69. this.videoPlay = false;
  70. },
  71. triggerClose() {
  72. if (this.showChat) {
  73. this.$refs.messageInput.handleClose();
  74. }
  75. },
  76. sendMessage(event) {
  77. // 将自己发送的消息写进消息列表里面
  78. this.$refs.messageList.updateMessageList(event.detail.message);
  79. console.log(event.detail.message);
  80. if(event.detail.message.type=="TIMCustomElem"){
  81. if(event.detail.message.payload.data=="evaluation"){
  82. //提交评价extension {"score":3,"comment":"q2"}
  83. var jsonObj=JSON.parse(event.detail.message.payload.extension)
  84. var data={orderId:this.order.orderId,pingStar:jsonObj.score,pingContent:jsonObj.comment}
  85. pingOrder(data).then(
  86. res => {
  87. if(res.code==200){
  88. uni.showToast({
  89. icon:'success',
  90. title: "评价成功",
  91. });
  92. }else{
  93. uni.showToast({
  94. icon:'none',
  95. title: res.msg,
  96. });
  97. }
  98. },
  99. rej => {}
  100. );
  101. }
  102. }
  103. },
  104. getUserInfo(){
  105. var that=this;
  106. getUserInfo().then(
  107. res => {
  108. if(res.code==200){
  109. if(res.user!=null){
  110. this.user=res.user;
  111. this.getTlsSig()
  112. }
  113. }else{
  114. uni.showToast({
  115. icon:'none',
  116. title: "请求失败",
  117. });
  118. }
  119. },
  120. rej => {}
  121. );
  122. },
  123. getTlsSig(){
  124. var that=this;
  125. var data={userId:'user'+this.user.userId}
  126. getTlsSig(data).then(
  127. res => {
  128. if(res.code==200){
  129. that.loginIm(res.data);
  130. }else{
  131. uni.showToast({
  132. icon:'none',
  133. title: "请求失败",
  134. });
  135. }
  136. },
  137. rej => {}
  138. );
  139. },
  140. loginIm(sign){
  141. var that=this;
  142. uni.$TUIKit.login({
  143. userID: 'user'+that.user.userId,
  144. userSig: sign
  145. }).then((res) => {
  146. console.log("IM登录成功")
  147. setTimeout(function(){
  148. let promise = uni.$TUIKit.updateMyProfile({
  149. nick: that.user.nickname,
  150. avatar: that.user.avatar,
  151. gender: uni.$TUIKitTIM.TYPES.GENDER_MALE,
  152. selfSignature: '我的个性签名',
  153. allowType: uni.$TUIKitTIM.TYPES.ALLOW_TYPE_ALLOW_ANY
  154. });
  155. promise.then(function(imResponse) {
  156. console.log(imResponse.data); // 更新资料成功
  157. that.setRead()
  158. var conversation={conversationID:that.conversationID,type:uni.$TUIKitTIM.TYPES.CONV_C2C}
  159. that.conversation = conversation;
  160. that.$refs.messageList.getMessageList(conversation);
  161. }).catch(function(imError) {
  162. console.warn('updateMyProfile error:', imError); // 更新资料失败的相关信息
  163. });
  164. },1000);
  165. }).catch((error) => {
  166. });
  167. },
  168. setRead(){
  169. var that=this;
  170. uni.$TUIKit.setMessageRead({
  171. conversationID:that.conversationID
  172. })
  173. .then(() => {
  174. });
  175. // uni.$TUIKit.getConversationProfile(that.conversationID).then(res => {
  176. // const { conversation } = res.data;
  177. // that.conversation = conversation;
  178. // console.log(that.conversation)
  179. // that.setData({
  180. // conversationName: this.getConversationName(conversation),
  181. // isShow: conversation.type === 'GROUP'
  182. // });
  183. // });
  184. },
  185. getImOrderDetail(){
  186. let data = {orderId:this.orderId};
  187. var that=this;
  188. getImOrderDetail(data).then(
  189. res => {
  190. if(res.code==200){
  191. this.doctor=res.doctor;
  192. this.order=res.order;
  193. this.toUser="doctor"+this.doctor.doctorId;
  194. this.conversationID='C2Cdoctor'+this.doctor.doctorId
  195. uni.setNavigationBarTitle({
  196. title:'与'+this.doctor.doctorName+'医生聊天中'
  197. })
  198. this.getUserInfo();
  199. }else{
  200. uni.showToast({
  201. icon:'none',
  202. title: "请求失败",
  203. });
  204. }
  205. },
  206. rej => {}
  207. );
  208. },
  209. }
  210. }
  211. </script>
  212. <style lang="scss">
  213. .container {
  214. width: 100vw;
  215. height: 100vh;
  216. position: fixed;
  217. top: 0;
  218. left: 0;
  219. right: 0;
  220. bottom: 0;
  221. display: flex;
  222. flex-direction: column;
  223. }
  224. .tui-chatroom-navigatorbar {
  225. position: relative;
  226. /*top: 0;*/
  227. flex-shrink: 0;
  228. width: 750rpx;
  229. height: 176rpx;
  230. background-color: #006EFF;
  231. }
  232. .tui-chatroom-navigatorbar-back {
  233. position: absolute;
  234. width: 48rpx;
  235. height: 48rpx;
  236. left: 24rpx;
  237. bottom: 20rpx;
  238. }
  239. .conversation-title {
  240. position: absolute;
  241. width: 350rpx;
  242. height: 88rpx;
  243. line-height: 56rpx;
  244. font-size: 36rpx;
  245. color: #FFFFFF;
  246. z-index: 100;
  247. bottom: 0;
  248. left: 200rpx;
  249. display: flex;
  250. justify-content: center;
  251. align-items: center;
  252. }
  253. .message-list {
  254. flex: 1;
  255. width: 100vw;
  256. overflow-y: scroll;
  257. }
  258. .message-input {
  259. flex-shrink: 0;
  260. width: 100%;
  261. }
  262. .calling {
  263. position: fixed;
  264. z-index: 199;
  265. top: 0;
  266. /* #ifdef H5 */
  267. top: calc(88rpx + constant(safe-area-inset-top));
  268. top: calc(88rpx + env(safe-area-inset-top));
  269. /* #endif */
  270. bottom: 0;
  271. right: 0;
  272. }
  273. .group-profile {
  274. top: 176rpx;
  275. left: 0;
  276. z-index: 1111
  277. }
  278. .container-box {
  279. position: fixed;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. left: 0;
  284. right: 0;
  285. bottom: 0;
  286. top: 0;
  287. background-color: rgba(0, 0, 0, 0.5);
  288. }
  289. .video-message {
  290. width: 90vw;
  291. height: 300px;
  292. }
  293. </style>