diff --git a/project.private.config.json b/project.private.config.json index d933e7a..c11fcf9 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -11,7 +11,14 @@ { "name": "聊天室", "pathName": "module1/pages/chatRoom/index", - "query": "id=2", + "query": "id=4", + "launchMode": "default", + "scene": null + }, + { + "name": "module1/pages/setChatDoctor/index", + "pathName": "module1/pages/setChatDoctor/index", + "query": "cid=39&create=1", "launchMode": "default", "scene": null }, diff --git a/src/module1/pages/casesDetail/index.ts b/src/module1/pages/casesDetail/index.ts index dc43c9f..4e1804c 100644 --- a/src/module1/pages/casesDetail/index.ts +++ b/src/module1/pages/casesDetail/index.ts @@ -517,6 +517,33 @@ Page({ }, }); }, + + handleCreateRoomShow() { + this.setData({ + show6: true, + }); + }, + handleRoom() { + wx.navigateTo({ + url: `/module1/pages/chatRoom/index?id=${this.data.id}`, + }); + }, + handleCreateRoomInvite() { + wx.navigateTo({ + url: `/module1/pages/setChatDoctor/index?cid=${this.data.id}&create=1`, + }); + }, + handleCreateRoom() { + wx.ajax({ + method: "POST", + url: "?r=takeda/chat/create-room", + data: { caseId: this.data.id }, + }).then((res) => { + wx.navigateTo({ + url: `/module1/pages/chatRoom/index?id=${res.roomId}`, + }); + }); + }, }); export {}; diff --git a/src/module1/pages/casesDetail/index.wxml b/src/module1/pages/casesDetail/index.wxml index dedfa91..6045096 100644 --- a/src/module1/pages/casesDetail/index.wxml +++ b/src/module1/pages/casesDetail/index.wxml @@ -244,11 +244,11 @@ 更多操作 - + 创建聊天室 - + 进入聊天室 @@ -305,11 +305,11 @@ 驳回原因 - + 创建聊天室 - + 进入聊天室 @@ -452,11 +452,11 @@ 确认创建聊天室 - + 邀约并创建 您可邀约一位您的合作医生讨论病历 - 直接创建 + 直接创建 取消 diff --git a/src/module1/pages/chatRoom/index.scss b/src/module1/pages/chatRoom/index.scss index 621eba4..9732796 100644 --- a/src/module1/pages/chatRoom/index.scss +++ b/src/module1/pages/chatRoom/index.scss @@ -109,6 +109,12 @@ page { color: rgba(173, 179, 180, 1); text-align: center; } + .create { + padding-top: 20rpx; + font-size: 28rpx; + color: rgba(173, 179, 180, 1); + text-align: center; + } .doctor { padding: 15rpx 30rpx; display: flex; @@ -208,6 +214,12 @@ page { display: flex; flex-direction: column; align-items: flex-end; + .user { + padding: 12rpx 0; + font-size: 28rpx; + color: rgba(153, 153, 153, 1); + line-height: 32rpx; + } .message { margin-bottom: 32rpx; padding: 26rpx 32rpx; diff --git a/src/module1/pages/chatRoom/index.ts b/src/module1/pages/chatRoom/index.ts index b168a00..dfb84a1 100644 --- a/src/module1/pages/chatRoom/index.ts +++ b/src/module1/pages/chatRoom/index.ts @@ -8,15 +8,14 @@ interface IMessageItem { content: any; fromDoctorId: string; doctorImg: string; - msgVisitTime: string; - createTime: ""; + createTime: string; + createTimeName?: string; isSelf: 1 | 2; isRead: 1 | 2; -} - -interface Item { - questionId: string; - question: string; + doctorName: string; + hospitalName: string; + showTime?: boolean; + isPlay?: boolean; } Page({ @@ -30,104 +29,21 @@ Page({ scrollIntoView: "", doctorDetail: {} as any, - questionActive: 0, - questionList: [] as any, - questionActiveList: [] as Item[], - roomDoctors: [], newRoomDoctors: [], case: {} as any, - chatGroupInfo: {}, - chatDoctor: {}, + chatGroupInfo: {} as any, + chatDoctor: {} as any, isLoad: false, isFinish: false, - messageList: [ - { - msgId: "686", - contentType: "2", - msgContent: "重症肌无力患者复查的频率取决于多种因素", - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "2", - msgCreateTime: "2024-10-10 09:37:40", - }, - { - msgId: "686", - contentType: "3", - msgContent: "重症肌无力患者复查的频率取决于多种因素", - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "2", - msgCreateTime: "2024-10-10 09:37:40", - }, - { - msgId: "686", - contentType: "2", - msgContent: "重症肌无力患者复查的频率取决于多种因素", - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "1", - msgCreateTime: "2024-10-10 09:37:40", - }, - { - msgId: "686", - contentType: "3", - msgContent: "重症肌无力患者复查的频率取决于多种因素", - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "1", - msgCreateTime: "2024-10-10 09:37:40", - }, - { - msgId: "681", - contentType: "1", - msgContent: "重症肌无力是否有遗传性?", - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "1", - msgCreateTime: "2024-10-10 09:37:17", - }, - { - msgId: "681", - contentType: "1", - msgContent: "重症肌无力是否有遗传性?", - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "1", - msgCreateTime: "2024-10-10 09:37:17", - }, - { - msgId: "483", - contentType: "4", - msgContent: - '[{"duration":8,"url":"https://circlehbsaas.oss-cn-beijing.aliyuncs.com/audio/20240907757_tmp_acf4f18c59553a8d2d9f74e173a16328.m4a.mp3"}]', - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "2", - msgCreateTime: "2024-10-08 15:24:19", - }, - { - msgId: "483", - contentType: "4", - msgContent: - '[{"duration":8,"url":"https://circlehbsaas.oss-cn-beijing.aliyuncs.com/audio/20240907757_tmp_acf4f18c59553a8d2d9f74e173a16328.m4a.mp3"}]', - welcomeMsg: "", - msgVisitTime: "", - msgFromType: "1", - msgCreateTime: "2024-10-08 15:24:19", - }, - ], + messageList: [] as IMessageItem[], lastMsgId: "", unReadCount: 0, - firstNotReadMsgId: 0, - isVisitAdl: 2, - adlMsgId: 0, - week: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"], - timeDay: { 1: "上午", 2: "下午" }, + userInfo: {} as any, - userInfo: {}, + sendMessage: [], }, innerAudioContext: null as WechatMiniprogram.InnerAudioContext | null, videoContext: null as WechatMiniprogram.VideoContext | null, @@ -141,9 +57,12 @@ Page({ this.getMessageList(); this.getDetail(); + this.listenMessage(); + app.getUserInfo(this); }); }, onUnload() { + wx.WebIM.conn.close(); if (this.innerAudioContext) { this.innerAudioContext.stop(); } @@ -190,6 +109,7 @@ Page({ chatGroupInfo: res.chatGroupInfo, chatDoctor: res.chatDoctor, }); + this.WebIMLogin(); }); }, handleRoomDetail() { @@ -203,29 +123,14 @@ Page({ scrollIntoView: index > -1 ? `view${index}` : `place`, }); }, - getDoctorDetail() { - wx.ajax({ - method: "GET", - url: "?r=zd/message-interact/get-bind-doctor-info", - data: {}, - }).then((res) => { - this.setData({ - doctorDetail: { - ...res, - }, - }); - }); - }, - getQuestionList() { - wx.ajax({ - method: "GET", - url: "?r=zd/message-interact/get-question-list", - data: {}, - }).then((res) => { - this.setData({ - questionList: res, - questionActiveList: res[0].questionList, - }); + listenMessage() { + wx.WebIM.conn.addEventHandler("room", { + onConnected: (message) => { + console.log("message: ", message); + }, + onTextMessage: (meessage) => { + console.log("meessage1: ", meessage); + }, }); }, getMessageList() { @@ -242,23 +147,23 @@ Page({ roomId: this.data.id, }, }).then((res) => { + if (res.length === 0) { + this.setData({ + isFinite: true, + }); + return; + } res.map((item) => { //消息内容类型,1-文本,2-语音,3-图片,4-视频,5-提示信息 if (["2", "3", "4"].includes(item.contentType)) { item.msgContent = JSON.parse(item.msgContent); } - return item; }); this.setData({ - messageList: [...res.messageList.reverse(), ...this.data.messageList], - lastMsgId: res.lastMsgId, - unReadCount: res.unReadCount, - firstNotReadMsgId: res.firstNotReadMsgId, - isVisitAdl: res.isVisitAdl, - adlMsgId: res.adlMsgId, + messageList: [...res.reverse(), ...this.data.messageList], + lastMsgId: res[0].msgId, isLoad: false, - isFinish: lastMsgId === res.lastMsgId, }); this.filterCreateTime(); if (!lastMsgId) { @@ -267,9 +172,80 @@ Page({ }); }, scrolltoupper(e) { - // if (e.detail.direction === 'top') { - // this.getMessageList() - // } + if (e.detail.direction === "top") { + this.getMessageList(); + } + }, + WebIMLogin() { + const { chatDoctor } = this.data; + wx.WebIM.conn.open({ + user: chatDoctor.chatUserId, + pwd: chatDoctor.chatUserPwd, + }); + }, + handleSendMessage() { + const { sendMessage, userInfo } = this.data; + if (!sendMessage) { + wx.showToast({ + icon: "none", + title: "请输入内容", + }); + return; + } + const message: IMessageItem = { + msgId: "", + contentType: "1", + content: sendMessage, + fromDoctorId: userInfo.DoctorId, + createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), + isSelf: 1, + isRead: 1, + doctorImg: userInfo.Img, + doctorName: userInfo.Name, + hospitalName: userInfo.HospitalName, + }; + this.WebIMSendMessage(message); + }, + WebIMSendMessage(message: IMessageItem) { + const { chatGroupInfo } = this.data; + const option = { + type: "txt", + msg: message.content, + to: chatGroupInfo.ChatGroupId, + chatType: "groupChat", + ext: { + ...message, + }, + }; + const msg = wx.WebIM.message.create(option); + wx.WebIM.conn + .send(msg) + .then((res) => { + this.sendMessage({ ...message, uniqueCode: res.serverMsgId }); + this.setData({ + messageList: [...this.data.messageList, message], + }); + }) + .catch(() => { + wx.showToast({ + icon: "none", + title: "发送失败", + }); + }); + }, + sendMessage({ uniqueCode, ...message }) { + wx.ajax({ + method: "POST", + url: "?r=takeda/chat/send-message", + data: { + roomId: this.data.id, + message: { + contentType: message.contentType, + content: message.content, + uniqueCode, + }, + }, + }); }, handleHot(e) { const { index, mindex } = e.currentTarget.dataset; @@ -285,69 +261,25 @@ Page({ msgContent: hot?.question, msgVisitTime: "", msgFromType: "1", - msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), + createTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), }, ], }); this.handleView(); this.sendQuestion(hot?.questionId); }, - handleQuestion(e) { - const { index } = e.currentTarget.dataset; - const { questionActiveList, messageList } = this.data; - const question = questionActiveList[index]; - this.setData({ - messageList: [ - ...messageList, - { - msgId: "", - contentType: "1", - msgContent: question.question, - msgVisitTime: "", - msgFromType: "1", - msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), - }, - ], - }); - this.sendQuestion(question.questionId); - }, - sendQuestion(questionId) { - wx.ajax({ - method: "POST", - url: "?r=zd/message-interact/send-question-message", - data: { - questionId, - }, - }).then((res) => { - this.setData({ - messageList: [ - ...this.data.messageList, - { - msgId: "", - contentType: "1", - msgContent: res, - msgVisitTime: "", - msgFromType: "2", - msgCreateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"), - }, - ], - }); - this.filterCreateTime(); - this.handleView(); - }); - }, formatTime(date: string) { - let msgCreateTimeName = ""; + let createTimeName = ""; if (dayjs().format("YYYY-MM-DD") === dayjs(date).format("YYYY-MM-DD")) { - msgCreateTimeName = dayjs(date).format("HH:mm"); + createTimeName = dayjs(date).format("HH:mm"); } else if (dayjs().format("YYYY-MM-DD") === dayjs(date).add(1, "day").format("YYYY-MM-DD")) { - msgCreateTimeName = `昨天 ${dayjs(date).format("HH:mm")}`; + createTimeName = `昨天 ${dayjs(date).format("HH:mm")}`; } else if (dayjs().diff(date, "day") < 7) { - msgCreateTimeName = dayjs(date).format(`dddd HH:mm`); + createTimeName = dayjs(date).format(`dddd HH:mm`); } else { - msgCreateTimeName = dayjs(date).format("YYYY-MM-DD HH:mm"); + createTimeName = dayjs(date).format("YYYY-MM-DD HH:mm"); } - return msgCreateTimeName; + return createTimeName; }, filterCreateTime() { const gapTime = 5 * 60 * 1000; @@ -357,14 +289,14 @@ Page({ messageList.forEach((item, index) => { if (index === 0) { item.showTime = true; - preTime = dayjs(item.msgCreateTime).valueOf(); - item.msgCreateTimeName = this.formatTime(item.msgCreateTime); + preTime = dayjs(item.createTime).valueOf(); + item.createTimeName = this.formatTime(item.createTime); } else { - const curTime = dayjs(item.msgCreateTime).valueOf(); + const curTime = dayjs(item.createTime).valueOf(); if (curTime - preTime > gapTime) { item.showTime = true; - item.msgCreateTimeName = this.formatTime(item.msgCreateTime); - preTime = dayjs(item.msgCreateTime).valueOf(); + item.createTimeName = this.formatTime(item.createTime); + preTime = dayjs(item.createTime).valueOf(); } } }); @@ -372,27 +304,6 @@ Page({ messageList, }); }, - handleQuestionTab(e) { - const { index } = e.currentTarget.dataset; - this.setData({ - questionActive: index, - questionActiveList: this.data.questionList[index].questionList, - }); - }, - handleDoctorDetail() { - const { doctorId } = this.data.doctorDetail; - wx.navigateTo({ - url: `/pages/doctorDetail/index?id=${doctorId}`, - }); - }, - handleRead() { - const { firstNotReadMsgId, messageList } = this.data; - const index = messageList.findIndex((item) => `${item.msgId}` === `${firstNotReadMsgId}`); - this.handleView(index); - this.setData({ - unReadCount: 0, - }); - }, handleFooter() { this.setData({ fold: !this.data.fold, @@ -403,16 +314,11 @@ Page({ }, 300); } }, - handleAdl() { - wx.navigateTo({ - url: "/pages/adl/index", - }); - }, handleAudio(e) { const { index } = e.currentTarget.dataset; const { messageList } = this.data; const messageItem = messageList[index]; - const { url } = messageItem.msgContent[0]; + const { url } = messageItem.content[0]; if (this.innerAudioContext) { if (messageItem.isPlay) { this.innerAudioContext.stop(); diff --git a/src/module1/pages/chatRoom/index.wxml b/src/module1/pages/chatRoom/index.wxml index 5464b62..b0e00fd 100644 --- a/src/module1/pages/chatRoom/index.wxml +++ b/src/module1/pages/chatRoom/index.wxml @@ -18,7 +18,7 @@ | {{case.hospitalName}} - {{case.cityName}}{{case.countyName?'/':''}}{{case.countyName}} + {{case.cityName}}{{case.countyName ? '/' : ''}}{{case.countyName}} @@ -35,8 +35,9 @@ > - {{message.msgCreateTimeName}} - + {{message.createTimeName}} + {{message.content}} + 李倩 中南大学湘雅医院李倩 - {{message.msgContent}} - + {{message.content}} + + + + {{message.msgContent[0].duration}}'' + + - + - - - - {{message.msgContent[0].duration}}'' - - + - {{message.msgContent}} - + {{message.doctorName}} {{message.hospitalName}} + {{message.content}} + {{message.msgContent[0].duration}}'' - + - + - + @@ -140,7 +128,15 @@ - + + - - 用户须知 diff --git a/src/module1/pages/setChatDoctor/index.ts b/src/module1/pages/setChatDoctor/index.ts index 753845a..fa871b1 100644 --- a/src/module1/pages/setChatDoctor/index.ts +++ b/src/module1/pages/setChatDoctor/index.ts @@ -37,23 +37,26 @@ Page({ }, list: [], - DoctorId: "", - - params: {}, + DoctorId: [] as any, caseId: "", - detailInvite: false, - feedBackInvite: false, + roomId: "", + create: false, + + userInfo: {} as any, }, onLoad(options) { this.setData({ + roomId: options.rid, caseId: options.cid, + create: options.create === "1", }); app.waitLogin().then(() => { this.getList(); this.getDoctorDict(); this.getHostipalDict(); this.getArea(); + app.getUserInfo(this); }); }, getDoctorDict() { @@ -227,59 +230,40 @@ Page({ handleRadio(e) { const { index } = e.currentTarget.dataset; - const { list } = this.data; - this.setData({ - DoctorId: (list as any)[index].doctorId, - }); + const { list, DoctorId, userInfo } = this.data; + const id: any = (list as any)[index].doctorId; + if (userInfo.DoctorLevel > 3) { + this.setData({ + DoctorId: DoctorId.includes(id) ? DoctorId.filter((item: any) => item !== id) : [...DoctorId, id], + }); + } else { + this.setData({ + DoctorId: DoctorId.includes(id) ? [] : [id], + }); + } }, handleSubmit() { - const { feedBackInvite, caseId, DoctorId, params, detailInvite } = this.data; - if (!DoctorId) { + const { caseId, roomId, DoctorId, create } = this.data; + if (DoctorId.length === 0) { wx.showToast({ - title: "请选择指派医生", + title: "请选择医生", icon: "none", }); - } - if (feedBackInvite) { - wx.ajax({ - method: "POST", - url: "?r=takeda/case/add-feedback", - data: { - caseId, - dealDoctorId: DoctorId, - ...params, - }, - }).then(() => { - wx.redirectTo({ - url: `/module1/pages/casesDetail/index?id=${caseId}`, - }); - }); return; } - if (detailInvite) { - wx.ajax({ method: "POST", url: "?r=takeda/case/invite-doctor", data: { caseId, dealDoctorId: DoctorId } }).then( - (res) => { - wx.navigateTo({ - url: `/module1/pages/entryCasesResult/index?isf=${res.isSubscribe}&wxi=${encodeURIComponent(res.wxImg)}&cid=${res.caseId}`, - }); - }, - ); - return; - } - const url = caseId ? "?r=takeda/case/save-case" : "?r=takeda/case/create-case"; + const url = create ? "?r=takeda/chat/create-room" : "?r=takeda/chat/invite-doctor"; wx.ajax({ method: "POST", url, data: { - ...params, caseId, - isSubmit: 1, - dealDoctorId: DoctorId, + roomId, + inviteDoctorId: DoctorId, }, }).then((res) => { wx.reLaunch({ - url: `/module1/pages/entryCasesResult/index?isf=${res.isSubscribe}&wxi=${encodeURIComponent(res.wxImg)}&cid=${res.caseId || caseId}`, + url: `/module1/pages/chatRoom/index?id=${res.roomId || roomId}`, }); }); }, diff --git a/src/module1/pages/setChatDoctor/index.wxml b/src/module1/pages/setChatDoctor/index.wxml index dc3ecfe..868d6b7 100644 --- a/src/module1/pages/setChatDoctor/index.wxml +++ b/src/module1/pages/setChatDoctor/index.wxml @@ -1,6 +1,7 @@ + - 邀请医生进行病历反馈,提交后医生将收到消息提醒 + 邀请合作医生加入聊天室讨论病历 @@ -38,40 +39,43 @@ - - - - - - - - - {{item.doctorName}} - {{item.doctorTitleName || item.doctorOtherTitle}} - - - {{depart.DepartmentName}} - - - - {{item.hospitalName}} - {{item.hospitalClassificationName}}{{item.hospitalLevelName}} - - {{item.cityName}}{{item.countyName?'/':''}}{{item.countyName}} - + + + + + + + + {{item.doctorName}} + {{item.doctorTitleName || item.doctorOtherTitle}} + + + {{depart.DepartmentName}} + + + + {{item.hospitalName}} + {{item.hospitalClassificationName}}{{item.hospitalLevelName}} + + {{item.cityName}}{{item.countyName?'/':''}}{{item.countyName}} - - - - {{spec.SpecialtyName}} - + + + + + {{spec.SpecialtyName}} - - + + 返回 diff --git a/src/pages/chatRoomList/index.wxml b/src/pages/chatRoomList/index.wxml index 160c0e4..962f0ab 100644 --- a/src/pages/chatRoomList/index.wxml +++ b/src/pages/chatRoomList/index.wxml @@ -153,6 +153,7 @@ +