doctorOrderIM.vue 6.9 KB

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